-
Notifications
You must be signed in to change notification settings - Fork 2
65 lines (58 loc) · 2.17 KB
/
deploy-to-gce.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
# Copyright 2020 Google, LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: Deployment
concurrency:
group: production
cancel-in-progress: true
on: workflow_dispatch
env:
PROJECT_ID: ${{ secrets.GCE_PROJECT }}
GCE_INSTANCE: rollbot-vm
GCE_INSTANCE_ZONE: us-central1-a
jobs:
setup-build-publish-deploy:
name: Setup, Build, Publish, and Deploy
runs-on: ubuntu-latest
# Add "id-token" with the intended permissions.
permissions:
contents: 'read'
id-token: 'write'
steps:
- name: Checkout
uses: actions/checkout@v4
- id: 'auth'
uses: 'google-github-actions/auth@v2'
with:
credentials_json: '${{ secrets.GCE_SA_KEY }}'
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v2
- run: |-
gcloud --quiet auth configure-docker us-central1-docker.pkg.dev
- name: Build
run: |-
docker build --tag "us-central1-docker.pkg.dev/$PROJECT_ID/rollbot-vm/$GCE_INSTANCE-image:$GITHUB_SHA" .
- name: Publish
run: |-
docker push "us-central1-docker.pkg.dev/$PROJECT_ID/rollbot-vm/$GCE_INSTANCE-image:$GITHUB_SHA"
- name: Update startup script to prune and update IP address
run: |-
gcloud compute instances add-metadata $GCE_INSTANCE \
--zone "$GCE_INSTANCE_ZONE" \
--metadata=startup-script="#! /bin/bash
docker image prune -af"
- name: Deploy
run: |-
gcloud compute instances update-container "$GCE_INSTANCE" \
--zone "$GCE_INSTANCE_ZONE" \
--container-image "us-central1-docker.pkg.dev/$PROJECT_ID/rollbot-vm/$GCE_INSTANCE-image:$GITHUB_SHA"