Skip to content

Commit c350152

Browse files
🔧 Update entrypoint.sh to allow multiline arg commands
1 parent 1e55962 commit c350152

File tree

1 file changed

+82
-59
lines changed

1 file changed

+82
-59
lines changed

entrypoint.sh

Lines changed: 82 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -127,80 +127,103 @@ log_success "Successfully connected to Kubernetes cluster"
127127
# Check for Helm registry credentials if any helm registry login commands are present
128128
log_info "Checking for Helm registry credentials..."
129129
helm_login_required=false
130-
for cmd in "$@"; do
131-
if echo "$cmd" | grep -q "helm registry login"; then
132-
helm_login_required=true
133-
break
134-
fi
135-
done
130+
commands_string="$*"
131+
132+
if echo "$commands_string" | grep -q "helm registry login"; then
133+
helm_login_required=true
134+
fi
136135

137136
if [ "$helm_login_required" = true ]; then
138137
log_info "Helm registry login detected in commands"
139138

140-
# Extract registry from the command to provide better error messages
141-
for cmd in "$@"; do
142-
if echo "$cmd" | grep -q "helm registry login"; then
143-
registry=$(echo "$cmd" | grep -o "helm registry login [^ ]*" | cut -d' ' -f4)
144-
log_info "Will attempt to login to registry: $registry"
145-
146-
# Check if credentials are available (this is a basic check)
147-
if echo "$cmd" | grep -q "\$.*USERNAME" && echo "$cmd" | grep -q "\$.*PASSWORD"; then
148-
log_info "Registry credentials will be read from environment variables"
149-
# Note: We can't validate the actual values here as they're in variables
150-
else
151-
log_error "Helm registry login command found but credentials format is unclear"
152-
log_error "Expected format: helm registry login <registry> --username \$USERNAME --password \$PASSWORD"
153-
fi
154-
fi
155-
done
139+
# Extract registry from the commands to provide better error messages
140+
registry=$(echo "$commands_string" | grep -o "helm registry login [^ ]*" | head -1 | cut -d' ' -f4)
141+
if [ -n "$registry" ]; then
142+
log_info "Will attempt to login to registry: $registry"
143+
fi
144+
145+
# Check if credentials are available (this is a basic check)
146+
if echo "$commands_string" | grep -q "\$.*USERNAME" && echo "$commands_string" | grep -q "\$.*PASSWORD"; then
147+
log_info "Registry credentials will be read from environment variables"
148+
# Note: We can't validate the actual values here as they're in variables
149+
else
150+
log_error "Helm registry login command found but credentials format is unclear"
151+
log_error "Expected format: helm registry login <registry> --username \$USERNAME --password \$PASSWORD"
152+
fi
156153
fi
157154

158155
echo "--- Executing Commands ---"
159156

160-
# Execute each argument as a separate command
161-
# This allows passing multiple commands line by line
157+
# Join all arguments into a single string and process line by line
158+
# This handles multi-line commands properly
159+
commands="$*"
162160
command_count=0
163-
for cmd in "$@"; do
164-
command_count=$((command_count + 1))
165-
log_info "Executing command $command_count: $cmd"
161+
162+
# Process commands line by line, handling line continuations
163+
current_command=""
164+
while IFS= read -r line || [ -n "$line" ]; do
165+
# Skip empty lines
166+
if [ -z "$(echo "$line" | xargs)" ]; then
167+
continue
168+
fi
166169

167-
# Execute the command and capture both stdout and stderr
168-
if eval "$cmd"; then
169-
log_success "Command $command_count completed successfully"
170+
# Check if line ends with backslash (continuation)
171+
if [[ "$line" =~ \\[[:space:]]*$ ]]; then
172+
# Remove trailing backslash and whitespace, add to current command
173+
current_command="$current_command$(echo "$line" | sed 's/\\[[:space:]]*$//')"
174+
current_command="$current_command "
175+
continue
170176
else
171-
exit_code=$?
172-
log_error "Command $command_count failed with exit code $exit_code"
173-
log_error "Failed command: $cmd"
177+
# Complete the command
178+
current_command="$current_command$line"
179+
fi
180+
181+
# Execute the complete command
182+
if [ -n "$current_command" ]; then
183+
command_count=$((command_count + 1))
184+
log_info "Executing command $command_count: $current_command"
174185

175-
# Provide specific error guidance based on command type
176-
if echo "$cmd" | grep -q "helm registry login"; then
177-
log_error "Helm registry login failed. Please check:"
178-
log_error " - Registry URL is correct and accessible"
179-
log_error " - Username and password environment variables are set correctly"
180-
log_error " - Network connectivity to the registry"
181-
elif echo "$cmd" | grep -q "helm install"; then
182-
log_error "Helm install failed. Please check:"
183-
log_error " - Chart name and version are correct"
184-
log_error " - Namespace exists or --create-namespace is used"
185-
log_error " - Sufficient permissions in the cluster"
186-
log_error " - Chart repository is accessible"
187-
elif echo "$cmd" | grep -q "helm uninstall"; then
188-
log_error "Helm uninstall failed. Please check:"
189-
log_error " - Release name exists in the specified namespace"
190-
log_error " - Sufficient permissions to delete resources"
191-
elif echo "$cmd" | grep -q "kubectl"; then
192-
log_error "Kubectl command failed. Please check:"
193-
log_error " - Kubernetes cluster connectivity"
194-
log_error " - Sufficient permissions for the operation"
195-
log_error " - Resource names and namespaces are correct"
186+
# Execute the command and capture both stdout and stderr
187+
if eval "$current_command"; then
188+
log_success "Command $command_count completed successfully"
189+
else
190+
exit_code=$?
191+
log_error "Command $command_count failed with exit code $exit_code"
192+
log_error "Failed command: $current_command"
193+
194+
# Provide specific error guidance based on command type
195+
if echo "$current_command" | grep -q "helm registry login"; then
196+
log_error "Helm registry login failed. Please check:"
197+
log_error " - Registry URL is correct and accessible"
198+
log_error " - Username and password environment variables are set correctly"
199+
log_error " - Network connectivity to the registry"
200+
elif echo "$current_command" | grep -q "helm install"; then
201+
log_error "Helm install failed. Please check:"
202+
log_error " - Chart name and version are correct"
203+
log_error " - Namespace exists or --create-namespace is used"
204+
log_error " - Sufficient permissions in the cluster"
205+
log_error " - Chart repository is accessible"
206+
elif echo "$current_command" | grep -q "helm uninstall"; then
207+
log_error "Helm uninstall failed. Please check:"
208+
log_error " - Release name exists in the specified namespace"
209+
log_error " - Sufficient permissions to delete resources"
210+
elif echo "$current_command" | grep -q "kubectl"; then
211+
log_error "Kubectl command failed. Please check:"
212+
log_error " - Kubernetes cluster connectivity"
213+
log_error " - Sufficient permissions for the operation"
214+
log_error " - Resource names and namespaces are correct"
215+
fi
216+
217+
exit $exit_code
196218
fi
197219

198-
exit $exit_code
220+
# Reset for next command
221+
current_command=""
222+
223+
# Add a small delay between commands for better logging readability
224+
sleep 1
199225
fi
200-
201-
# Add a small delay between commands for better logging readability
202-
sleep 1
203-
done
226+
done <<< "$commands"
204227

205228
log_success "All commands completed successfully!"
206229
echo "--- Execution Summary ---"

0 commit comments

Comments
 (0)