-
Notifications
You must be signed in to change notification settings - Fork 8
187 lines (168 loc) · 5.89 KB
/
build_studio_images.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
name: Build Studio Images
on:
schedule:
- cron: '0 12 1 * *' # Once a month at 12:00 UTC
workflow_dispatch:
repository_dispatch:
types: [ helm-release ]
pull_request:
branches: [ "main" ]
paths:
- packer/**
- .github/workflows/build_studio_images.yml
permissions:
contents: read
id-token: write
packages: write
jobs:
build-kh-klipper-docker:
runs-on: ubuntu-latest
defaults:
run:
working-directory: packer
permissions:
contents: read
packages: write
# This is used to complete the identity challenge
# with sigstore/fulcio when running outside of PRs.
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
# Workaround: https://github.com/docker/build-push-action/issues/461
- name: Setup Docker buildx
uses: docker/setup-buildx-action@4c0219f9ac95b02789c1075625400b2acbff50b1
# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@a9794064588be971151ec5e7144cb535bcb56e36
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}
# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@4fad532b9fdbfb80f436784834374a1c11834153
with:
context: .
file: packer/kh-klipper.dockerfile
push: true
tags:
ghcr.io/${{ github.repository }}/kh-klipper-cache:${{ github.event_name != 'pull_request' && 'latest' || github.event.pull_request.head.sha }}
create-virtualbox-runner:
environment: aws
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Standard CML setup
uses: iterative/setup-cml@v1
with:
version: latest
- uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: us-west-1
role-to-assume: arn:aws:iam::260760892802:role/studio-selfhosted-packer
role-duration-seconds: 3600
- name: Create Runner
env:
REPO_TOKEN: ${{ secrets.REPO_TOKEN }}
run: |
cml runner \
--name="studio-virtualbox-builder-${{ github.run_id }}" \
--cloud-metadata="actions_link=https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" \
--cloud-startup-script=$(echo 'curl https://github.com/${{ github.actor }}.keys >> /home/ubuntu/.ssh/authorized_keys' | base64 -w 0) \
--single \
--labels=studio-selfhosted-virtualbox-builder \
--cloud=aws \
--cloud-image="studio-virtualbox-builder" \
--cloud-region=us-west-1 \
--cloud-type=c5n.metal \
--cloud-aws-security-group=sg-0da3ac1cdc286dd4e \
--cloud-aws-subnet=subnet-01c5f8c843b5c7759 \
--cloud-hdd-size 100
build-studio-aws-ami:
needs:
- build-kh-klipper-docker
environment: aws
runs-on: ubuntu-latest
defaults:
run:
working-directory: packer
steps:
- uses: actions/checkout@v4
- uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: us-west-1
role-to-assume: arn:aws:iam::260760892802:role/studio-selfhosted-packer
role-duration-seconds: 3600
- name: Setup `packer`
uses: hashicorp/setup-packer@main
id: setup
with:
version: "1.8.6"
- name: Run `packer init`
id: init
run: "packer init ./studio_ami.pkr.hcl"
- name: Run `packer fmt -diff`
id: fmt
run: "packer fmt -diff -recursive ."
- name: Run `packer validate`
id: validate
run: "packer validate ./studio_ami.pkr.hcl"
- name: Run `packer build`
id: build
run: "packer build ./studio_ami.pkr.hcl"
env:
PKR_VAR_skip_create_ami: ${{ github.event_name != 'pull_request' && 'false' || 'true' }}
PKR_VAR_kh_klipper_tag: ${{ github.event_name != 'pull_request' && 'latest' || github.event.pull_request.head.sha }}
build-studio-virtualbox-image:
needs:
- create-virtualbox-runner
- build-kh-klipper-docker
runs-on: [studio-selfhosted-virtualbox-builder]
environment: aws
timeout-minutes: 60
defaults:
run:
working-directory: packer
steps:
- uses: actions/checkout@v4
- uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: us-west-1
role-to-assume: arn:aws:iam::260760892802:role/studio-selfhosted-packer
role-duration-seconds: 3600
- name: CML Version Test
run: |
which cml
cml --version
- name: Setup `packer`
uses: hashicorp/setup-packer@main
id: setup
with:
version: "1.8.6"
- name: Run `packer init`
id: init
run: "packer init ./studio_virtualbox.pkr.hcl"
- name: Run `packer fmt -diff`
id: fmt
run: "packer fmt -diff -recursive ."
- name: Run `packer validate`
id: validate
run: "packer validate ./studio_virtualbox.pkr.hcl"
- name: Run `packer build`
id: build
run: "packer build ./studio_virtualbox.pkr.hcl"
env:
PKR_VAR_kh_klipper_tag: ${{ github.event_name != 'pull_request' && 'latest' || github.event.pull_request.head.sha }}
PKR_VAR_headless: true
- name: Zip artifacts
id: compress
run: gzip build/*
- name: Upload VirtualBox image to S3
id: upload
if: ${{ github.event_name != 'pull_request' }}
run: |
aws s3 cp build/*.gz s3://iterative-studio-selfhosted/virtualbox/ --storage-class STANDARD_IA --region us-east-2