Skip to content

Commit 513175d

Browse files
Trying again.
1 parent 0fdf294 commit 513175d

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

.github/workflows/deploy.yml

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ jobs:
1212
- name: '🔍 Checkout Code'
1313
uses: actions/checkout@v4
1414

15-
# (Secrets and .env setup steps remain the same)
1615
- name: '🔒 Verify Secrets Exist'
1716
run: |
1817
if [ -z "${{ secrets.GOOGLE_SERVICES_JSON_BASE64 }}" ]; then
@@ -38,11 +37,11 @@ jobs:
3837
echo "" >> .env
3938
4039
# =======================================================
41-
# 🐳 Docker Operations (This section is updated)
40+
# 🐳 Docker Operations
4241
# =======================================================
4342
- name: '🚀 Build, Launch, and Update Services'
4443
run: |
45-
# Step 1: Ensure the Docker network exists.
44+
# Step 1: Explicitly check for the network and create it only if it's missing.
4645
if ! docker network ls | grep -q "codebuilder-net"; then
4746
echo "Network 'codebuilder-net' not found. Creating it..."
4847
docker network create codebuilder-net
@@ -51,7 +50,6 @@ jobs:
5150
fi
5251
5352
# Step 2: Explicitly check and manage the database container.
54-
# This avoids the 'docker compose up' conflict entirely.
5553
DB_CONTAINER_NAME="codebuilder-postgres-db"
5654
if [ $(docker ps -a -q -f name=^/${DB_CONTAINER_NAME}$) ]; then
5755
# The container exists, check if it is running.
@@ -75,10 +73,18 @@ jobs:
7573
done
7674
echo "✅ Database is healthy and listening."
7775
78-
# Step 4: Build and deploy the webapp.
79-
# This part remains the same as it correctly targets only the webapp.
80-
echo "Building and deploying the webapp..."
81-
docker compose up -d --build --force-recreate --no-deps webapp
76+
# Step 4: Build the new webapp image.
77+
echo "Building the latest webapp image..."
78+
docker compose build webapp
79+
80+
# Step 5: Explicitly stop and remove the old webapp container to prevent conflicts.
81+
echo "Stopping and removing old webapp container if it exists..."
82+
docker compose stop webapp || true
83+
docker compose rm -f webapp || true
84+
85+
# Step 6: Deploy the new webapp container.
86+
echo "Deploying the new webapp container..."
87+
docker compose up -d --no-deps webapp
8288
8389
- name: '🗑 Prune Old Docker Images'
8490
if: always()

docker-compose.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,20 @@ services:
3131
- ./.env
3232
volumes:
3333
# Mount a named volume to persist the database data.
34-
# This is crucial to prevent data loss when the container is recreated.
3534
- postgres-data:/var/lib/postgresql/data
3635
networks:
3736
# Connect this service to our custom network.
3837
- codebuilder-net
39-
# Exposing the port is optional if only the webapp needs to connect,
40-
# but it's useful for debugging from your host machine.
38+
# Exposing the port is crucial for our new workflow health check.
4139
ports:
4240
- "5434:5432"
4341

4442
# Define the custom network that our services will share.
4543
networks:
4644
codebuilder-net:
47-
# This explicitly tells Compose that the network is created
48-
# and managed outside of its control, which our deploy.yml now does.
45+
# This correctly tells Compose that the network is managed outside its control.
4946
external: true
5047

5148
# Define the named volumes for persistent data storage.
52-
# Docker manages the lifecycle of these volumes.
5349
volumes:
5450
postgres-data:

0 commit comments

Comments
 (0)