-
Notifications
You must be signed in to change notification settings - Fork 0
96 lines (81 loc) · 3.28 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
89
90
91
92
93
94
95
96
# Build docker container, publish to Google Container Registry, deploy to Compute Engine.
#
# Based on https://github.com/actions/starter-workflows/blob/main/ci/google.yml
#
# To configure this workflow, set up secrets in your workspace:
# 1. GCP_PROJECT with the name of the project
# 2. GCP_SA_KEY with the Base64 encoded JSON service account key (https://github.com/GoogleCloudPlatform/github-actions/tree/docs/service-account-key/setup-gcloud#inputs).
# 3. AIVEN_*
name: sitewatch deploy
on:
workflow_run:
workflows: [ "sitewatch test" ]
branches: [ main ]
types:
- completed
env:
PROJECT_ID: ${{ secrets.GCP_PROJECT }}
AIVEN_TOKEN: ${{ secrets.AIVEN_TOKEN }}
AIVEN_EMAIL: ${{ secrets.AIVEN_EMAIL }}
AIVEN_PROJECT: ${{ secrets.AIVEN_PROJECT }}
AIVEN_PG_SERVICE: ${{ secrets.AIVEN_PG_SERVICE }}
AIVEN_KAFKA_SERVICE: ${{ secrets.AIVEN_KAFKA_SERVICE }}
GCP_ZONE: europe-north1-a
MACHINE_TYPE: e2-micro
IMAGE: sitewatch
jobs:
setup-build-publish-deploy:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
name: Setup, Build, Publish, and Deploy
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
# Setup gcloud CLI
- uses: google-github-actions/[email protected]
with:
service_account_key: ${{ secrets.GCP_SA_KEY }}
project_id: ${{ secrets.GCP_PROJECT }}
# Configure Docker to use the gcloud command-line tool as a credential
# helper for authentication
- run: |-
gcloud --quiet auth configure-docker
# Build the Docker image
- name: Build
run: |-
docker build --tag "gcr.io/$PROJECT_ID/$IMAGE" .
# Push the Docker image to Google Container Registry
- name: Publish
run: |-
docker push "gcr.io/$PROJECT_ID/$IMAGE"
- name: Delete watch instance, if exists
run: |-
gcloud compute instances delete $IMAGE-watch --zone $GCP_ZONE || true
- name: Delete report instance, if exists
run: |-
gcloud compute instances delete $IMAGE-report --zone $GCP_ZONE || true
# TODO: consider `gcloud compute instances update-container`
- name: Create watch instance
run: |-
gcloud compute instances create-with-container $IMAGE-watch \
--zone $GCP_ZONE \
--machine-type=$MACHINE_TYPE \
--container-image gcr.io/$(gcloud config get-value project)/$IMAGE \
--container-env AIVEN_TOKEN=$AIVEN_TOKEN \
--container-env AIVEN_EMAIL=$AIVEN_EMAIL \
--container-env AIVEN_PROJECT=$AIVEN_PROJECT \
--container-env AIVEN_PG_SERVICE=$AIVEN_PG_SERVICE \
--container-env AIVEN_KAFKA_SERVICE=$AIVEN_KAFKA_SERVICE \
--container-arg watch
- name: Create report instance
run: |-
gcloud compute instances create-with-container $IMAGE-report \
--zone $GCP_ZONE \
--machine-type=$MACHINE_TYPE \
--container-image gcr.io/$(gcloud config get-value project)/$IMAGE \
--container-env AIVEN_TOKEN=$AIVEN_TOKEN \
--container-env AIVEN_EMAIL=$AIVEN_EMAIL \
--container-env AIVEN_PROJECT=$AIVEN_PROJECT \
--container-env AIVEN_PG_SERVICE=$AIVEN_PG_SERVICE \
--container-env AIVEN_KAFKA_SERVICE=$AIVEN_KAFKA_SERVICE \
--container-arg report