12
12
- name : ' 🔍 Checkout Code'
13
13
uses : actions/checkout@v4
14
14
15
- # (Secrets and .env setup steps remain the same)
16
15
- name : ' 🔒 Verify Secrets Exist'
17
16
run : |
18
17
if [ -z "${{ secrets.GOOGLE_SERVICES_JSON_BASE64 }}" ]; then
@@ -38,11 +37,11 @@ jobs:
38
37
echo "" >> .env
39
38
40
39
# =======================================================
41
- # 🐳 Docker Operations (This section is updated)
40
+ # 🐳 Docker Operations
42
41
# =======================================================
43
42
- name : ' 🚀 Build, Launch, and Update Services'
44
43
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 .
46
45
if ! docker network ls | grep -q "codebuilder-net"; then
47
46
echo "Network 'codebuilder-net' not found. Creating it..."
48
47
docker network create codebuilder-net
51
50
fi
52
51
53
52
# Step 2: Explicitly check and manage the database container.
54
- # This avoids the 'docker compose up' conflict entirely.
55
53
DB_CONTAINER_NAME="codebuilder-postgres-db"
56
54
if [ $(docker ps -a -q -f name=^/${DB_CONTAINER_NAME}$) ]; then
57
55
# The container exists, check if it is running.
@@ -75,10 +73,18 @@ jobs:
75
73
done
76
74
echo "✅ Database is healthy and listening."
77
75
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
82
88
83
89
- name : ' 🗑 Prune Old Docker Images'
84
90
if : always()
0 commit comments