|
12 | 12 | - name: '🔍 Checkout Code' |
13 | 13 | uses: actions/checkout@v4 |
14 | 14 |
|
| 15 | + # (Secrets and .env setup steps remain the same) |
15 | 16 | - name: '🔒 Verify Secrets Exist' |
16 | 17 | run: | |
17 | 18 | if [ -z "${{ secrets.GOOGLE_SERVICES_JSON_BASE64 }}" ]; then |
@@ -41,46 +42,39 @@ jobs: |
41 | 42 | # ======================================================= |
42 | 43 | - name: '🚀 Build, Launch, and Update Services' |
43 | 44 | run: | |
44 | | - # Step 1: Explicitly check for the network and create it only if it's missing. |
| 45 | + # Step 1: Ensure the Docker network exists. |
45 | 46 | if ! docker network ls | grep -q "codebuilder-net"; then |
46 | 47 | echo "Network 'codebuilder-net' not found. Creating it..." |
47 | 48 | docker network create codebuilder-net |
48 | 49 | else |
49 | 50 | echo "Network 'codebuilder-net' already exists. Skipping creation." |
50 | 51 | fi |
51 | 52 |
|
52 | | - # Step 2: Explicitly check and manage the database container. |
| 53 | + # Step 2: Ensure the database container is running. |
53 | 54 | DB_CONTAINER_NAME="codebuilder-postgres-db" |
54 | 55 | if [ $(docker ps -a -q -f name=^/${DB_CONTAINER_NAME}$) ]; then |
55 | | - # The container exists, check if it is running. |
56 | | - if [ $(docker ps -q -f name=^/${DB_CONTAINER_NAME}$) ]; then |
57 | | - echo "Database container '${DB_CONTAINER_NAME}' is already running." |
58 | | - else |
59 | | - # The container exists but is stopped, so start it. |
60 | | - echo "Database container '${DB_CONTAINER_NAME}' exists but is stopped. Starting it..." |
| 56 | + if ! [ $(docker ps -q -f name=^/${DB_CONTAINER_NAME}$) ]; then |
| 57 | + echo "Database container exists but is stopped. Starting it..." |
61 | 58 | docker start ${DB_CONTAINER_NAME} |
62 | 59 | fi |
63 | 60 | else |
64 | | - # The container does not exist, so create it for the first time. |
65 | | - echo "Database container '${DB_CONTAINER_NAME}' not found. Creating it..." |
| 61 | + echo "Database container not found. Creating it..." |
66 | 62 | docker compose up -d db |
67 | 63 | fi |
68 | 64 |
|
69 | | - # Step 3: Wait for the database to be fully ready. |
| 65 | + # Step 3: Wait for the database to be healthy. |
70 | 66 | echo "Waiting for database to become available on localhost:5434..." |
71 | | - while ! nc -z localhost 5434; do |
72 | | - sleep 1 |
73 | | - done |
74 | | - echo "✅ Database is healthy and listening." |
| 67 | + while ! nc -z localhost 5434; do sleep 1; done |
| 68 | + echo "✅ Database is healthy." |
75 | 69 |
|
76 | 70 | # Step 4: Build the new webapp image. |
77 | 71 | echo "Building the latest webapp image..." |
78 | 72 | docker compose build webapp |
79 | 73 |
|
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 |
| 74 | + # Step 5: THE DEFINITIVE FIX. Forcefully remove the old webapp container by its exact name. |
| 75 | + # This is the most direct command and bypasses any ambiguity from Docker Compose's state. |
| 76 | + echo "Forcefully removing old webapp container to prevent conflicts..." |
| 77 | + docker rm -f codebuilder-webapp || true |
84 | 78 |
|
85 | 79 | # Step 6: Deploy the new webapp container. |
86 | 80 | echo "Deploying the new webapp container..." |
|
0 commit comments