Skip to content

Commit e7f8a24

Browse files
More forceful removal of existing container.
1 parent 42a5672 commit e7f8a24

File tree

1 file changed

+13
-19
lines changed

1 file changed

+13
-19
lines changed

.github/workflows/deploy.yml

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

15+
# (Secrets and .env setup steps remain the same)
1516
- name: '🔒 Verify Secrets Exist'
1617
run: |
1718
if [ -z "${{ secrets.GOOGLE_SERVICES_JSON_BASE64 }}" ]; then
@@ -41,46 +42,39 @@ jobs:
4142
# =======================================================
4243
- name: '🚀 Build, Launch, and Update Services'
4344
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.
4546
if ! docker network ls | grep -q "codebuilder-net"; then
4647
echo "Network 'codebuilder-net' not found. Creating it..."
4748
docker network create codebuilder-net
4849
else
4950
echo "Network 'codebuilder-net' already exists. Skipping creation."
5051
fi
5152
52-
# Step 2: Explicitly check and manage the database container.
53+
# Step 2: Ensure the database container is running.
5354
DB_CONTAINER_NAME="codebuilder-postgres-db"
5455
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..."
6158
docker start ${DB_CONTAINER_NAME}
6259
fi
6360
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..."
6662
docker compose up -d db
6763
fi
6864
69-
# Step 3: Wait for the database to be fully ready.
65+
# Step 3: Wait for the database to be healthy.
7066
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."
7569
7670
# Step 4: Build the new webapp image.
7771
echo "Building the latest webapp image..."
7872
docker compose build webapp
7973
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
8478
8579
# Step 6: Deploy the new webapp container.
8680
echo "Deploying the new webapp container..."

0 commit comments

Comments
 (0)