Debugging container early exit. #30
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: 'π Deploy NestJS API Docker App' | |
on: | |
push: | |
branches: [main] | |
jobs: | |
build-and-deploy: | |
runs-on: self-hosted | |
name: 'π³ Build & Deploy' | |
steps: | |
- name: 'π Checkout Code' | |
uses: actions/checkout@v4 | |
- name: 'π Verify Secrets Exist' | |
run: | | |
if [ -z "${{ secrets.GOOGLE_SERVICES_JSON_BASE64 }}" ]; then | |
echo "β Critical error: GOOGLE_SERVICES_JSON_BASE64 secret missing!" | |
exit 1 | |
fi | |
echo "β All secrets present" | |
- name: 'π Create google-services.json' | |
run: | | |
echo "$GOOGLE_SERVICES_JSON_BASE64" | base64 --decode > google-services.json | |
echo "π Validating JSON..." | |
if ! jq empty google-services.json; then | |
echo "β JSON validation failed!" | |
exit 1 | |
fi | |
env: | |
GOOGLE_SERVICES_JSON_BASE64: ${{ secrets.GOOGLE_SERVICES_JSON_BASE64 }} | |
- name: 'βοΈ Create .env File' | |
run: | | |
echo "${{ secrets.ENV_FILE_CONTENT }}" > .env | |
echo "" >> .env | |
# ======================================================= | |
# π³ Docker Operations | |
# ======================================================= | |
- name: 'οΏ½ Debug: List workspace files and show package.json' | |
run: | | |
echo '--- DEBUG: Listing workspace files ---' | |
ls -alh | |
echo '--- DEBUG: Showing package.json ---' | |
cat package.json | |
echo '--- DEBUG: Listing node_modules/.bin if exists ---' | |
if [ -d node_modules/.bin ]; then ls -l node_modules/.bin; else echo "node_modules/.bin does not exist"; fi | |
- name: 'οΏ½π Build, Launch, and Update Services' | |
run: | | |
# Step 1: Ensure the Docker network exists. | |
if ! docker network ls | grep -q "codebuilder-net"; then | |
echo "Network 'codebuilder-net' not found. Creating it..." | |
docker network create codebuilder-net | |
else | |
echo "Network 'codebuilder-net' already exists. Skipping creation." | |
fi | |
# Step 2: Ensure the database container is running. | |
DB_CONTAINER_NAME="codebuilder-postgres-db" | |
if [ $(docker ps -a -q -f name=^/${DB_CONTAINER_NAME}$) ]; then | |
if ! [ $(docker ps -q -f name=^/${DB_CONTAINER_NAME}$) ]; then | |
echo "Database container exists but is stopped. Starting it..." | |
docker start ${DB_CONTAINER_NAME} | |
fi | |
else | |
echo "Database container not found. Creating it..." | |
# Use 'codebuilder' as the stack prefix | |
docker compose -p codebuilder up -d db | |
fi | |
# Step 3: Wait for the database to be healthy. | |
echo "Waiting for database to become available on localhost:5434..." | |
while ! nc -z localhost 5434; do sleep 1; done | |
echo "β Database is healthy." | |
# ===================================================================== | |
# THE FIX: Force the build to run in default server mode. | |
# This overrides any conflicting environment variables. | |
# ===================================================================== | |
echo "Ensuring build runs in default server mode..." | |
export NEXT_OUTPUT_MODE='standalone' | |
# Step 4: Build the latest api image. | |
echo "Building the latest api image..." | |
# Use 'codebuilder' as the stack prefix | |
docker compose -p codebuilder build api | |
# Step 5: Forcefully remove the old api container to prevent conflicts. | |
echo "Forcefully removing old api container if it exists..." | |
docker rm -f codebuilder-api || true | |
# Step 6: Deploy the new api container. | |
echo "Deploying the new api container..." | |
# Use 'codebuilder' as the stack prefix | |
docker compose -p codebuilder up -d --no-deps api | |
- name: 'π Prune Old Docker Images' | |
if: always() | |
run: docker image prune -af |