Skip to content

Commit

Permalink
build: deploy containers without kubernetes
Browse files Browse the repository at this point in the history
  • Loading branch information
maxitect committed Nov 27, 2024
1 parent 57411f2 commit 77275cf
Showing 1 changed file with 30 additions and 40 deletions.
70 changes: 30 additions & 40 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ on:

env:
PROJECT_ID: poke-like-api
GKE_CLUSTER: pokelike-cluster
GKE_ZONE: europe-west2-a
IMAGE: pokelike-artifacts
REGION: europe-west2

jobs:
build-and-deploy:
Expand All @@ -33,56 +32,47 @@ jobs:

- name: Create Artifact Registry Repository
run: |
if ! gcloud artifacts repositories describe pokelike-artifacts --location=europe-west2; then
if ! gcloud artifacts repositories describe pokelike-artifacts --location=$REGION; then
gcloud artifacts repositories create pokelike-artifacts \
--repository-format=docker \
--location=europe-west2 \
--location=$REGION \
--description="Docker repository for PokeLikeAPI"
fi
- name: Configure Docker
run: gcloud auth configure-docker europe-west2-docker.pkg.dev
run: gcloud auth configure-docker $REGION-docker.pkg.dev

- name: Build and Push Image
run: |
docker build -t europe-west2-docker.pkg.dev/$PROJECT_ID/$IMAGE/$IMAGE:$GITHUB_SHA .
docker push europe-west2-docker.pkg.dev/$PROJECT_ID/$IMAGE/$IMAGE:$GITHUB_SHA
docker build -t $REGION-docker.pkg.dev/$PROJECT_ID/$IMAGE/$IMAGE:$GITHUB_SHA .
docker push $REGION-docker.pkg.dev/$PROJECT_ID/$IMAGE/$IMAGE:$GITHUB_SHA
- name: Create or Get GKE Cluster
- name: Create Cloud Run Service
run: |
if ! gcloud container clusters describe $GKE_CLUSTER --zone $GKE_ZONE; then
gcloud container clusters create $GKE_CLUSTER \
--machine-type=e2-small \
--num-nodes=1 \
--zone=$GKE_ZONE
fi
- name: Get GKE Credentials
uses: google-github-actions/get-gke-credentials@v2
with:
cluster_name: ${{ env.GKE_CLUSTER }}
location: ${{ env.GKE_ZONE }}
# Create network
gcloud compute networks create pokelike-network --subnet-mode=auto || true
- name: Delete Existing Resources
run: |
kubectl delete -f kubernetes/api-deployment.yaml --ignore-not-found
kubectl delete -f kubernetes/api-service.yaml --ignore-not-found
kubectl delete -f kubernetes/postgres-deployment.yaml --ignore-not-found
kubectl delete -f kubernetes/postgres-service.yaml --ignore-not-found
kubectl delete -f kubernetes/postgres-pvc.yaml --ignore-not-found
kubectl wait --for=delete deployment/pokelike-api --timeout=60s || true
kubectl wait --for=delete deployment/postgres --timeout=60s || true
# Deploy Postgres container
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 || true
- name: Deploy Infrastructure
run: |
kubectl apply -f kubernetes/postgres-pvc.yaml
kubectl apply -f kubernetes/postgres-service.yaml
kubectl apply -f kubernetes/postgres-deployment.yaml
kubectl wait --for=condition=available deployment/postgres --timeout=200s
# Deploy API container
gcloud run deploy pokelike-api \
--image=$REGION-docker.pkg.dev/$PROJECT_ID/$IMAGE/$IMAGE:$GITHUB_SHA \
--platform=managed \
--region=$REGION \
--set-env-vars="ConnectionStrings__PokeLikeDbContext=Host=postgres;Port=5432;Database=PokeLikeDb;Username=postgres;Password=welovepokemon" \
--allow-unauthenticated \
--vpc-connector=pokelike-connector
- name: Deploy API and Services
- name: Create VPC Connector
run: |
sed "s/:IMAGE_TAG/:$GITHUB_SHA/" kubernetes/api-deployment.yaml | kubectl apply -f -
kubectl apply -f kubernetes/api-service.yaml
kubectl wait --for=condition=available deployment/pokelike-api --timeout=180s
gcloud compute networks vpc-access connectors create pokelike-connector \
--network=pokelike-network \
--region=$REGION \
--range=10.8.0.0/28 || true

0 comments on commit 77275cf

Please sign in to comment.