Skip to content

Commit 0fdf294

Browse files
Fixing workflow.
1 parent 77bff3e commit 0fdf294

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

.github/workflows/deploy.yml

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,31 +50,35 @@ jobs:
5050
echo "Network 'codebuilder-net' already exists. Skipping creation."
5151
fi
5252
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
53+
# Step 2: Explicitly check and manage the database container.
54+
# This avoids the 'docker compose up' conflict entirely.
55+
DB_CONTAINER_NAME="codebuilder-postgres-db"
56+
if [ $(docker ps -a -q -f name=^/${DB_CONTAINER_NAME}$) ]; then
57+
# The container exists, check if it is running.
58+
if [ $(docker ps -q -f name=^/${DB_CONTAINER_NAME}$) ]; then
59+
echo "Database container '${DB_CONTAINER_NAME}' is already running."
60+
else
61+
# The container exists but is stopped, so start it.
62+
echo "Database container '${DB_CONTAINER_NAME}' exists but is stopped. Starting it..."
63+
docker start ${DB_CONTAINER_NAME}
64+
fi
65+
else
66+
# The container does not exist, so create it for the first time.
67+
echo "Database container '${DB_CONTAINER_NAME}' not found. Creating it..."
68+
docker compose up -d db
69+
fi
5870
5971
# 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
6372
echo "Waiting for database to become available on localhost:5434..."
6473
while ! nc -z localhost 5434; do
65-
sleep 1 # wait for 1 second before trying again
74+
sleep 1
6675
done
6776
echo "✅ Database is healthy and listening."
6877
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
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
7882
7983
- name: '🗑 Prune Old Docker Images'
8084
if: always()

0 commit comments

Comments
 (0)