-
Notifications
You must be signed in to change notification settings - Fork 30
94 lines (86 loc) · 2.67 KB
/
build-jumpbox-image.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
84
85
86
87
88
89
90
91
92
93
94
name: Build Jumpbox Image
on:
schedule:
- cron: '0 10 * * *' # everyday at 10am
push:
branches:
- main
paths:
- 'packer/jumpbox/**'
- .github/workflows/build-jumpbox-image.yaml
pull_request:
branches:
- main
paths:
- 'packer/jumpbox/**'
- .github/workflows/build-jumpbox-image.yaml
jobs:
build_and_push_jumpbox:
name: Build Jumpbox GCP Compute Image
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
- uses: actions/checkout@v3
- name: Authenicate to Google Cloud
uses: google-github-actions/auth@v0
with:
credentials_json: ${{ secrets.GCP_SERVICE_ACCOUNT_KEY }}
- name: Setup Google Cloud SDK
id: auth
uses: google-github-actions/setup-gcloud@v0
with:
project_id: kots-field-labs
# initialize
- name: Initialize Packer
uses: hashicorp/packer-github-actions@master
with:
command: init
working_directory: ./packer
target: jumpbox
env:
PACKER_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# validate templates
- name: Validate Packer Template
uses: hashicorp/packer-github-actions@master
with:
command: validate
arguments: -syntax-only
working_directory: ./packer
target: jumpbox
env:
PACKER_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# build artifact for push/merge (use default name)
- name: Build VM Image
uses: hashicorp/packer-github-actions@master
if: ${{ github.event_name != 'pull_request' }}
with:
command: build
arguments: "-force"
working_directory: ./packer
target: jumpbox
env:
PACKER_LOG: 1
PKR_VAR_service_account_key: ${{secrets.GCP_SERVICE_ACCOUNT_KEY}}
PKR_VAR_zone: europe-west1-b
PACKER_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# build artifact for PRs (need to assign image name)
- name: Build VM Image
uses: hashicorp/packer-github-actions@master
if: ${{ github.event_name == 'pull_request' }}
with:
command: build
arguments: "-force"
working_directory: ./packer
target: jumpbox
env:
PACKER_LOG: 1
PKR_VAR_service_account_key: ${{secrets.GCP_SERVICE_ACCOUNT_KEY}}
PKR_VAR_image_name: airgap-jumpbox-${{github.sha}}
PACKER_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# delete built artifact for PRs (save storage costs)
- name: Delete VM Image
if: ${{ github.event_name == 'pull_request' }}
run: gcloud compute images delete --quiet airgap-jumpbox-${{github.sha}}
shell: bash