-
Notifications
You must be signed in to change notification settings - Fork 5
66 lines (51 loc) · 2.05 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
66
# more details this workflow and other at https://github.com/didier-durand/gcloud-tests
name: Deploy to GCE
on:
workflow_dispatch:
inputs:
push:
#protection to avoid triggering when other workflow is modified
paths:
- '!.github/workflows/**'
- '.github/workflows/deploy-to-gce.yml'
schedule:
- cron: '0 2 * * MON'
env:
GCP_ZONE: us-central1-c
GCP_VERBOSITY: warning
GCE_INSTANCE: test-gce-instance
jobs:
deploy-to-GCE:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2.3.4
- name: Setup gcloud CLI
uses: google-github-actions/setup-gcloud@master
with:
project_id: ${{ secrets.GCP_PROJECT }}
service_account_key: ${{ secrets.GCP_SA_KEY }}
- name: Get gcloud version & info
run: |-
echo '--- gcloud version ---'
gcloud version
echo '--- gcloud info ---'
gcloud info --anonymize
- name: List existing instances on Google Compute Engine (GCE) & clean-up if needed
run: |-
gcloud compute instances list
gcloud compute instances stop $GCE_INSTANCE --zone $GCP_ZONE --quiet || true
gcloud compute instances delete $GCE_INSTANCE --zone $GCP_ZONE --quiet || true
- name: Start instance on Google Compute Engine (GCE)
run: |-
gcloud config set compute/zone $GCP_ZONE
gcloud compute instances create $GCE_INSTANCE --zone $GCP_ZONE --quiet
gcloud compute instances start $GCE_INSTANCE --zone $GCP_ZONE --quiet
- name: Describe started instance on Google Compute Engine (GCE)
run: |-
gcloud compute instances describe $GCE_INSTANCE --zone $GCP_ZONE
grep 'status: RUNNING' <<< $(gcloud compute instances describe $GCE_INSTANCE --zone $GCP_ZONE)
- name: Stop & delete instance on Google Compute Engine (GCE)
run: |-
gcloud compute instances stop $GCE_INSTANCE --zone $GCP_ZONE --quiet
gcloud compute instances delete $GCE_INSTANCE --zone $GCP_ZONE --quiet