-
Notifications
You must be signed in to change notification settings - Fork 0
88 lines (73 loc) · 3.06 KB
/
deploy.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
name: CI/CD Pipeline
on:
push:
branches: [main]
env:
PROJECT_ID: poke-like-api
GKE_CLUSTER: pokelike-cluster
GKE_ZONE: europe-west2-a
IMAGE: pokelike-artifacts
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: "8.0.x"
- name: Google Auth
uses: "google-github-actions/auth@v2"
with:
credentials_json: "${{ secrets.GCP_SA_KEY }}"
- name: Setup GCloud CLI
uses: google-github-actions/setup-gcloud@v2
with:
project_id: ${{ env.PROJECT_ID }}
- name: Create Artifact Registry Repository
run: |
if ! gcloud artifacts repositories describe pokelike-artifacts --location=europe-west2; then
gcloud artifacts repositories create pokelike-artifacts \
--repository-format=docker \
--location=europe-west2 \
--description="Docker repository for PokeLikeAPI"
fi
- name: Configure Docker
run: gcloud auth configure-docker europe-west2-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
- name: Create or Get GKE Cluster
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 }}
- 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
- 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
- name: Deploy API and Services
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