Files
gorunner/entrypoint.sh
2025-06-06 17:33:37 +02:00

59 lines
1.1 KiB
Bash

#!/bin/bash
set -e
error() {
echo "[ERROR] $1" >&2
exit 1
}
if [ -z "$GIT_REPO" ]; then
error "GIT_REPO is not set."
fi
# Install runtime packages if specified
if [ -n "$PACKAGES" ]; then
echo "[PKG] Installing additional APK packages: $PACKAGES"
apk update >/dev/null
apk add --no-cache $(echo "$PACKAGES" | tr ',' ' ')
fi
# Extract Git host
GIT_HOST=$(echo "$GIT_REPO" | awk -F/ '{print $3}')
# Configure .netrc
if [ -n "$GIT_USERNAME" ] && [ -n "$GIT_TOKEN" ]; then
echo "[AUTH] Configuring .netrc for Git authentication..."
cat <<EOF > ~/.netrc
machine $GIT_HOST
login $GIT_USERNAME
password $GIT_TOKEN
EOF
chmod 600 ~/.netrc
export GIT_ASKPASS=true
export GIT_TERMINAL_PROMPT=0
fi
# Clean previous checkout
rm -rf /app/repo
echo "[CLONE] Cloning repository: $GIT_REPO"
git clone "$GIT_REPO" repo
cd repo
# Checkout specific branch, tag, or commit if provided
if [ -n "$GIT_REF" ]; then
echo "[GIT] Checking out ref: $GIT_REF"
git fetch --all --tags
git checkout "$GIT_REF"
fi
cd "${APP_PATH:-.}"
echo "[BUILD] Building..."
go build -o /app/app .
echo "[RUN] Starting application..."
exec /app/app