Skip to content

Commit

Permalink
fix: delete container instances if they exist
Browse files Browse the repository at this point in the history
  • Loading branch information
maxitect committed Nov 28, 2024
1 parent d983b6e commit 88f1543
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,39 @@ jobs:
- name: Deploy Postgres
run: |
# Create the data directory first
gcloud compute ssh postgres --zone=$REGION-a --command="sudo mkdir -p /postgres-data && sudo chmod 777 /postgres-data" || true
# Deploy the container
# Configure firewall rules for SSH
gcloud compute firewall-rules create allow-ssh \
--network=pokelike-network \
--allow=tcp:22 \
--source-ranges=0.0.0.0/0 || true
# Delete existing instance if it exists
gcloud compute instances delete postgres --zone=$REGION-a --quiet || true
# Wait for instance deletion
sleep 30
# Create new instance
gcloud compute instances create-with-container postgres \
--container-image=postgres:latest \
--container-env="POSTGRES_DB=PokeLikeDb,POSTGRES_USER=postgres,POSTGRES_PASSWORD=welovepokemon" \
--container-mount-host-path=mount-path=/var/lib/postgresql/data,host-path=/postgres-data \
--machine-type=e2-micro \
--network=pokelike-network \
--zone=$REGION-a \
--metadata=startup-script='#! /bin/bash
mkdir -p /postgres-data
chmod 777 /postgres-data' \
--service-account=github-actions@poke-like-api.iam.gserviceaccount.com
- name: Deploy API
run: |
# Delete existing instance if it exists
gcloud compute instances delete pokelike-api --zone=$REGION-a --quiet || true
# Wait for instance deletion
sleep 30
gcloud run deploy pokelike-api \
--image=$REGION-docker.pkg.dev/$PROJECT_ID/$IMAGE/$IMAGE:$GITHUB_SHA \
--platform=managed \
Expand Down

0 comments on commit 88f1543

Please sign in to comment.