From 2c0c4e34c23c7209ac3c7cd529844c9ed1bc7807 Mon Sep 17 00:00:00 2001 From: TenX PM Date: Mon, 4 May 2026 16:07:46 +0000 Subject: [PATCH] fix: deploy.sh - ssl, port detection, deploy trigger --- deploy.sh | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/deploy.sh b/deploy.sh index 5ff0680..777c331 100755 --- a/deploy.sh +++ b/deploy.sh @@ -7,6 +7,12 @@ set -e PROJECT_NAME="${1:?Usage: deploy.sh [dockerfile|nixpacks|static]}" BUILD_TYPE="${2:-nixpacks}" +# Port: static/dockerfile use 80, nixpacks use 3000 +if [ "${BUILD_TYPE}" = "static" ] || [ "${BUILD_TYPE}" = "dockerfile" ]; then + BUILD_TYPE_PORT="80" +else + BUILD_TYPE_PORT="3000" +fi GITEA_URL="${GITEA_URL:?GITEA_URL not set}" GITEA_TOKEN="${GITEA_TOKEN:?GITEA_TOKEN not set}" @@ -106,6 +112,15 @@ echo "[deploy] Environment: ${ENV_UUID}" echo "[deploy] Creating Coolify application..." REPO_FULL_URL="${GITEA_URL}/${GITEA_USER}/${PROJECT_NAME}.git" +DESTINATION_UUID=$(curl -sk -H "Authorization: Bearer ${COOLIFY_ACCESS_TOKEN}" \ + "${COOLIFY_API}/servers/${SERVER_UUID}" | python3 -c " +import sys,json +d=json.load(sys.stdin) +dests=d.get('destinations',[]) +if dests: print(dests[0].get('uuid','')) +else: print('') +" 2>/dev/null) + APP_RESPONSE=$(curl -sk -X POST -H "Authorization: Bearer ${COOLIFY_ACCESS_TOKEN}" \ -H "Content-Type: application/json" \ "${COOLIFY_API}/applications" \ @@ -113,13 +128,14 @@ APP_RESPONSE=$(curl -sk -X POST -H "Authorization: Bearer ${COOLIFY_ACCESS_TOKEN \"project_uuid\": \"${PROJECT_UUID}\", \"environment_name\": \"production\", \"server_uuid\": \"${SERVER_UUID}\", + \"destination_uuid\": \"${DESTINATION_UUID}\", \"type\": \"public\", \"name\": \"${PROJECT_NAME}\", \"git_repository\": \"${REPO_FULL_URL}\", \"git_branch\": \"main\", \"build_pack\": \"${BUILD_TYPE}\", - \"ports_exposes\": \"3000\", - \"instant_deploy\": true + \"ports_exposes\": \"${BUILD_TYPE_PORT}\", + \"instant_deploy\": false }") APP_UUID=$(echo "${APP_RESPONSE}" | python3 -c "import sys,json; print(json.load(sys.stdin).get('uuid',''))" 2>/dev/null) @@ -141,7 +157,7 @@ print('') if [ -n "${APP_UUID}" ]; then echo "[deploy] Found existing app: ${APP_UUID}, redeploying..." curl -sk -X POST -H "Authorization: Bearer ${COOLIFY_ACCESS_TOKEN}" \ - "${COOLIFY_API}/applications/${APP_UUID}/restart" > /dev/null + "${COOLIFY_API}/deploy?uuid=${APP_UUID}&force=false" > /dev/null else echo "[deploy] ERROR: Could not create or find app" exit 1 @@ -150,6 +166,11 @@ fi echo "[deploy] App UUID: ${APP_UUID}" +# ── Step 7b: Trigger deploy ─────────────────────────────────────────── +echo "[deploy] Triggering deployment..." +curl -sk -X POST -H "Authorization: Bearer ${COOLIFY_ACCESS_TOKEN}" \ + "${COOLIFY_API}/deploy?uuid=${APP_UUID}&force=false" > /dev/null + # ── Step 8: Wait for deployment ────────────────────────────────────── echo "[deploy] Waiting for deployment..." for i in $(seq 1 30); do @@ -160,7 +181,7 @@ for i in $(seq 1 30); do if [ "${STATUS}" = "running" ]; then break fi - if [ "${STATUS}" = "exited" ] || [ "${STATUS}" = "error" ]; then + if [[ "${STATUS}" == exited* ]] || [ "${STATUS}" = "error" ]; then echo "[deploy] Deployment failed with status: ${STATUS}" # Get logs curl -sk -H "Authorization: Bearer ${COOLIFY_ACCESS_TOKEN}" \