12
12
- name : ' 🔍 Checkout Code'
13
13
uses : actions/checkout@v4
14
14
15
- # ========================
16
- # 🔐 Secrets & Config Setup
17
- # ========================
15
+ # (Secrets and .env setup steps remain the same)
18
16
- name : ' 🔒 Verify Secrets Exist'
19
17
run : |
20
18
if [ -z "${{ secrets.GOOGLE_SERVICES_JSON_BASE64 }}" ]; then
@@ -40,37 +38,44 @@ jobs:
40
38
echo "" >> .env
41
39
42
40
# =======================================================
43
- # 🐳 Docker Compose Operations (This section is updated)
41
+ # 🐳 Docker Operations (This section is updated)
44
42
# =======================================================
45
- - name : ' 🚀 Launch or Update Services'
43
+ - name : ' 🚀 Build, Launch, and Update Services'
46
44
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.
49
46
if ! docker network ls | grep -q "codebuilder-net"; then
50
47
echo "Network 'codebuilder-net' not found. Creating it..."
51
48
docker network create codebuilder-net
52
49
else
53
50
echo "Network 'codebuilder-net' already exists. Skipping creation."
54
51
fi
55
52
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
63
58
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
72
78
73
79
- 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