1212 - name : ' 🔍 Checkout Code'
1313 uses : actions/checkout@v4
1414
15- # ========================
16- # 🔐 Secrets & Config Setup
17- # ========================
15+ # (Secrets and .env setup steps remain the same)
1816 - name : ' 🔒 Verify Secrets Exist'
1917 run : |
2018 if [ -z "${{ secrets.GOOGLE_SERVICES_JSON_BASE64 }}" ]; then
@@ -40,37 +38,44 @@ jobs:
4038 echo "" >> .env
4139
4240 # =======================================================
43- # 🐳 Docker Compose Operations (This section is updated)
41+ # 🐳 Docker Operations (This section is updated)
4442 # =======================================================
45- - name : ' 🚀 Launch or Update Services'
43+ - name : ' 🚀 Build, Launch, and Update Services'
4644 run : |
47- # Step 1: Explicitly check for the network and create it only if it's missing.
48- # This is more robust than the previous '|| true' syntax.
45+ # Step 1: Ensure the Docker network exists.
4946 if ! docker network ls | grep -q "codebuilder-net"; then
5047 echo "Network 'codebuilder-net' not found. Creating it..."
5148 docker network create codebuilder-net
5249 else
5350 echo "Network 'codebuilder-net' already exists. Skipping creation."
5451 fi
5552
56- # Step 2: Bring up all services defined in the compose file.
57- # This command is idempotent. On the first run, it creates and starts everything.
58- # On subsequent runs, it will connect to existing containers and ensure they
59- # are started if they were stopped, but it will NOT try to re-create them.
60- # This safely ensures the database is running before we proceed.
61- echo "Ensuring all services are up..."
62- docker compose up -d
53+ # Step 2: Start the database service independently.
54+ # The 'up -d' command is idempotent; it will start the 'db' if it's not running,
55+ # and do nothing if it already is.
56+ echo "Starting database service..."
57+ docker compose up -d db
6358
64- # Step 3: Force a rebuild and replacement of the webapp service ONLY.
65- # This is the key command for zero-downtime-style updates of your app.
66- # --no-deps: Guarantees that the 'db' container will not be touched.
67- # --build: Rebuilds the webapp image from your latest source code.
68- # --force-recreate: Explicitly stops the old webapp container and starts a new one
69- # from the new image, even if the configuration is the same.
70- echo "Rebuilding and force-recreating the webapp service..."
71- docker compose up -d --no-deps --build --force-recreate webapp
59+ # Step 3: Wait for the database to be fully ready.
60+ # We use netcat (nc) to poll the database port exposed to the host machine.
61+ # This is critical to ensure the build doesn't start prematurely.
62+ # NOTE: We use port 5434 because that is what you mapped in your docker-compose.yml
63+ echo "Waiting for database to become available on localhost:5434..."
64+ while ! nc -z localhost 5434; do
65+ sleep 1 # wait for 1 second before trying again
66+ done
67+ echo "✅ Database is healthy and listening."
68+
69+ # Step 4: NOW that the DB is running, build the webapp image.
70+ # The Docker builder will be able to connect to the 'db' service over the network.
71+ echo "Building the webapp image..."
72+ docker compose build webapp
73+
74+ # Step 5: Deploy the newly built webapp container.
75+ # This command surgically replaces the webapp without touching the database.
76+ echo "Deploying the new webapp container..."
77+ docker compose up -d --no-deps --force-recreate webapp
7278
7379 - name : ' 🗑 Prune Old Docker Images'
74- if : always() # This step will run even if the deployment fails.
75- run : |
76- docker image prune -af
80+ if : always()
81+ run : docker image prune -af
0 commit comments