Skip to content
This repository was archived by the owner on May 21, 2026. It is now read-only.

Commit 79cd404

Browse files
Improve deployment logging and error handling
Enhance the Hostinger deployment step with better observability and robustness: add an envs declaration for GHCR_OWNER_LC and APP_NAME, print progress messages, switch to direct shell variable interpolation for image references, perform a guarded docker pull (exit on failure), stop/remove the old container, start the new container with conditional error handling that prints container status and logs on failure, and ensure .env.espacogeek is cleaned up. These changes make deployment failures easier to diagnose and fail-fast on errors.
1 parent a644aff commit 79cd404

1 file changed

Lines changed: 20 additions & 3 deletions

File tree

.github/workflows/cicd.yml

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,11 @@ jobs:
207207
username: ${{ secrets.HOSTINGER_USER }}
208208
key: ${{ secrets.HOSTINGER }}
209209
port: ${{ secrets.HOSTINGER_PORT }}
210+
envs: GHCR_OWNER_LC,APP_NAME
210211
script: |
211212
set -e
213+
echo "Starting deployment with image: ghcr.io/${GHCR_OWNER_LC}/${APP_NAME}:latest"
214+
212215
cat > .env.espacogeek << 'ENVEOF'
213216
SPRING_DATASOURCE_URL=${{ secrets.SPRING_DATASOURCE_URL }}
214217
SPRING_DATASOURCE_USERNAME=${{ secrets.SPRING_DATASOURCE_USERNAME }}
@@ -227,15 +230,29 @@ jobs:
227230
ENVEOF
228231
229232
echo "${{ secrets.GHCR_TOKEN }}" | docker login ghcr.io -u "${{ secrets.GHCR_USER }}" --password-stdin
230-
docker pull ghcr.io/${{ env.GHCR_OWNER_LC }}/${{ env.APP_NAME }}:latest
233+
234+
echo "Pulling image from GHCR..."
235+
docker pull ghcr.io/${GHCR_OWNER_LC}/${APP_NAME}:latest || { echo "Failed to pull image"; exit 1; }
236+
237+
echo "Stopping and removing old container..."
231238
docker stop espacogeek || true
232239
docker rm espacogeek || true
233-
docker run -d --name espacogeek \
240+
241+
echo "Starting new container..."
242+
if ! docker run -d --name espacogeek \
234243
-p 8080:8080 \
235244
--restart unless-stopped \
236245
--env-file .env.espacogeek \
237-
ghcr.io/${{ env.GHCR_OWNER_LC }}/${{ env.APP_NAME }}:latest
246+
ghcr.io/${GHCR_OWNER_LC}/${APP_NAME}:latest; then
247+
echo "Failed to start container"
248+
docker ps -a
249+
docker logs espacogeek || true
250+
rm -f .env.espacogeek
251+
exit 1
252+
fi
238253
254+
echo "Container started successfully"
255+
docker ps -a
239256
rm -f .env.espacogeek
240257
241258
# Final summary with generated tags

0 commit comments

Comments
 (0)