Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements [UAT-68] #73

Merged
merged 3 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,4 @@ USER ${USER}
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]

# Set the default command
CMD ["sh"]
CMD ["tail", "-f", "/dev/null"]
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion Makefile.variables
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 3 additions & 13 deletions bin/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -50,7 +47,6 @@ wait_for_services() {
return 1
}

# Main execution path
# Main execution path
if [ "$#" -gt 0 ]; then
log_info "Executing command: $*"
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion etc/home/supervisor.common.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 8 additions & 2 deletions lib/auth/gcp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,23 @@ 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
echo "[ERROR] Missing required GCP credentials." >&2
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
Expand Down
Loading