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
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()
0 commit comments