-
Notifications
You must be signed in to change notification settings - Fork 0
83 lines (70 loc) · 2.65 KB
/
apply-on-merge.yaml
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
name: Apply On Merge
on:
push:
branches:
- main
# pull_request:
# branches:
# - main
env:
PROJECT_ID: ${{ secrets.PROJECT_ID }}
GKE_CLUSTER: fibonacci-app # TODO: update to cluster name
GKE_ZONE: northamerica-northeast1-a # TODO: update to cluster zone
jobs:
build-and-push:
name: Build application Docker images and push them to the registry
runs-on: ubuntu-latest
strategy:
matrix:
module:
- client
- server
- worker
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Run tests
if: ${{ matrix.module == 'client' }}
run: |
echo "Build a docker image for tests"
docker build -t client-test -f ./client/Dockerfile.dev ./client
echo "Run tests against that image"
docker run -e CI=true client-test npm test
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push the image for the module to the registry
run: |-
echo "Building the production docker image for the module"
docker build -t thecloudprofessional/${{ matrix.module }}:latest -t thecloudprofessional/${{ matrix.module }}:${{ github.sha }} ./${{ matrix.module }}
echo "Pushing the image to the registry..."
docker push thecloudprofessional/${{ matrix.module }}:latest
docker push thecloudprofessional/${{ matrix.module }}:${{ github.sha }}
deployStaging:
name: Deploy to Staging
runs-on: ubuntu-latest
needs: [build-and-push]
steps:
- name: Checkout
uses: actions/checkout@v3
- id: 'auth'
uses: 'google-github-actions/auth@v0'
with:
credentials_json: '${{ secrets.SA_KEY }}'
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v0
- name: Get the GKE credentials so we can deploy to the cluster
run: |-
gcloud container clusters get-credentials "$GKE_CLUSTER" --zone "$GKE_ZONE"
- name: Deploy
run: |-
kubectl apply -f k8s
kubectl set image deployments/server-deployment server=thecloudprofessional/server:${{ github.sha }}
kubectl set image deployments/worker-deployment worker=thecloudprofessional/worker:${{ github.sha }}
kubectl set image deployments/client-deployment client=thecloudprofessional/client:${{ github.sha }}
kubectl rollout status deployment/server-deployment
kubectl rollout status deployment/worker-deployment
kubectl rollout status deployment/client-deployment
kubectl get services -o wide