From 246ec79a9eeebe8f122570b8bcbb7d4c2fe71071 Mon Sep 17 00:00:00 2001 From: Dmitry Smirnov Date: Wed, 15 Jan 2025 18:33:02 +0200 Subject: [PATCH 1/3] improve entrypoint logic --- Dockerfile | 2 +- Makefile | 4 ++-- Makefile.variables | 2 +- bin/entrypoint.sh | 16 +++------------- 4 files changed, 7 insertions(+), 17 deletions(-) diff --git a/Dockerfile b/Dockerfile index 0be0c6e6..7f22117e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -149,4 +149,4 @@ USER ${USER} ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] # Set the default command -CMD ["sh"] \ No newline at end of file +CMD ["tail", "-f", "/dev/null"] \ No newline at end of file diff --git a/Makefile b/Makefile index 3ca62eaf..568f10cd 100644 --- a/Makefile +++ b/Makefile @@ -57,12 +57,12 @@ run: clean # Run Docker container in interactive mode run-it: - @$(MAKE) run INTERACTIVE=true + @$(MAKE) run INTERACTIVE=true COMMAND=/bin/bash # Exec into the running container exec: @echo "Executing into Docker container..." - @docker exec -it $(CONTAINER_NAME) /bin/sh + @docker exec -it $(CONTAINER_NAME) /bin/bash # View the container logs log: diff --git a/Makefile.variables b/Makefile.variables index d824cc68..bd3197f1 100644 --- a/Makefile.variables +++ b/Makefile.variables @@ -6,6 +6,6 @@ CONTAINER_NAME ?= udx-worker-container TEST_WORKER_CONFIG ?= ./tests/configs/worker.yml VOLUMES ?= DEBUG ?= false -COMMAND ?=sh +COMMAND ?= MULTIPLATFORM ?= false FOLLOW_LOGS ?= false \ No newline at end of file diff --git a/bin/entrypoint.sh b/bin/entrypoint.sh index 04dfa4bb..71aac06d 100644 --- a/bin/entrypoint.sh +++ b/bin/entrypoint.sh @@ -11,15 +11,12 @@ log_info "Welcome to UDX Worker Container. Initializing environment..." source /usr/local/lib/environment.sh handle_services() { - local cmd_exit_status=$1 # Pass command exit status if any - + if check_active_services; then wait_for_services - log_info "Tailing Supervisor logs to keep the container alive." - tail -f /var/log/supervisor/supervisord.log + log_info "Services are fully running." else log_warn "No services are active." - tail -f /dev/null fi } @@ -50,7 +47,6 @@ wait_for_services() { return 1 } -# Main execution path # Main execution path if [ "$#" -gt 0 ]; then log_info "Executing command: $*" @@ -60,14 +56,8 @@ if [ "$#" -gt 0 ]; then log_info "Shell script execution completed. Exiting." exit 0 else + handle_services "$@" # Execute the provided command - cmd_exit_status=$? - - if [ $cmd_exit_status -eq 0 ]; then - exit 0 - else - handle_services $cmd_exit_status - fi fi else handle_services From 10ea6618140eb6624114f1c6924117b6a9cd95d8 Mon Sep 17 00:00:00 2001 From: Dmitry Smirnov Date: Wed, 15 Jan 2025 20:04:55 +0200 Subject: [PATCH 2/3] disabled supervisor nodaemon --- etc/home/supervisor.common.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etc/home/supervisor.common.conf b/etc/home/supervisor.common.conf index b46f2a7a..e212090d 100644 --- a/etc/home/supervisor.common.conf +++ b/etc/home/supervisor.common.conf @@ -4,7 +4,7 @@ logfile_maxbytes=50MB logfile_backups=10 loglevel=info pidfile=/var/run/supervisor/supervisord.pid -nodaemon=true +nodaemon=false minfds=1024 minprocs=200 From 4ddf922a6b14b1ebfc75aaa333f3a3b86304de63 Mon Sep 17 00:00:00 2001 From: Dmitry Smirnov Date: Thu, 16 Jan 2025 14:35:10 +0200 Subject: [PATCH 3/3] fix for gcp private key auth --- lib/auth/gcp.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/auth/gcp.sh b/lib/auth/gcp.sh index 52a90d62..fbe6d9da 100644 --- a/lib/auth/gcp.sh +++ b/lib/auth/gcp.sh @@ -23,7 +23,7 @@ gcp_authenticate() { local clientEmail privateKey projectId clientEmail=$(echo "$creds_content" | jq -r '.client_email') - privateKey=$(echo "$creds_content" | jq -r '.private_key') + privateKey=$(echo "$creds_content" | jq -r '.private_key' | sed 's/- /-\n/g' | sed 's/ -/\n-/g') projectId=$(echo "$creds_content" | jq -r '.project_id') if [[ -z "$clientEmail" || -z "$privateKey" || -z "$projectId" ]]; then @@ -31,9 +31,15 @@ gcp_authenticate() { return 1 fi + # Adjust privateKey formatting + # Replace "\\n" with actual new line, handle BEGIN and END markers + privateKey=$(echo "$privateKey" | sed 's/\\n/\n/g' | sed 's/- /\n-/g' | sed 's/ -/-\n/g') + # Create a temporary credentials file for gcloud authentication local temp_creds_file="/tmp/gcp_creds.json" - echo "$creds_content" > "$temp_creds_file" + # Use jq to create a valid JSON with the modified privateKey + jq -n --arg clientEmail "$clientEmail" --arg privateKey "$privateKey" --arg projectId "$projectId" \ + '{client_email: $clientEmail, private_key: $privateKey, project_id: $projectId}' > "$temp_creds_file" echo "[INFO] Authenticating GCP service account..." if ! gcloud auth activate-service-account "$clientEmail" --key-file="$temp_creds_file" >/dev/null 2>&1; then