-
Notifications
You must be signed in to change notification settings - Fork 2
190 lines (183 loc) · 7.73 KB
/
build-multiarch.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
188
189
190
name: Build Multiarch Images
on:
workflow_dispatch:
inputs:
be-tag:
description: "The Lemmy Backend tag to build"
required: false
type: string
fe-tag:
description: "The Lemmy Frontend tag to build"
required: false
type: string
env:
LEMMY_ORG: LemmyNet
BE_REPO: lemmy
FE_REPO: lemmy-ui
DST_REGISTRY: ghcr.io
BE_TAG: ${{ github.event.inputs.be-tag }}
FE_TAG: ${{ github.event.inputs.fe-tag }}
jobs:
launch-runners:
runs-on: ubuntu-latest
if: github.event.inputs.fe-tag != '' || github.event.inputs.be-tag != ''
strategy:
matrix:
include:
- runner-arch: "x64"
docker-target: "linux/amd64"
target-short: "amd64"
ec2-ami: "ami-034de852f74caf71b"
ec2-instance-type: "c5d.large"
- runner-arch: "arm64"
docker-target: "linux/arm/v7"
target-short: "arm"
ec2-ami: "ami-015b0351eb1536708"
ec2-instance-type: "c6gn.large"
- runner-arch: "arm64"
docker-target: "linux/arm64"
target-short: "arm64"
ec2-ami: "ami-015b0351eb1536708"
ec2-instance-type: "c6gn.large"
steps:
- name: Launch Spot Runner (${{ matrix.runner-arch }}, ${{ matrix.docker-target }})
id: launch
uses: ubergeek77/aws-ec2-spot-runner@v1
with:
ec2-ami: ${{ matrix.ec2-ami }}
ec2-instance-type: ${{ matrix.ec2-instance-type }}
runner-arch: ${{ matrix.runner-arch }}
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
ec2-keypair-name: ${{ secrets.EC2_KEYPAIR }}
ec2-security-group-id: ${{ secrets.EC2_SG }}
github-repo: ${{ github.repository }}
github-token: ${{ secrets.RUNNER_TOKEN }}
- name: Export Runner Label
id: save-labels
run: echo "${{ matrix.target-short }}_label=${{ steps.launch.outputs.label }}" >> $GITHUB_OUTPUT
outputs:
amd64_label: ${{ steps.save-labels.outputs.amd64_label }}
arm_label: ${{ steps.save-labels.outputs.arm_label }}
arm64_label: ${{ steps.save-labels.outputs.arm64_label }}
build-images:
needs: launch-runners
if: github.event.inputs.fe-tag != '' || github.event.inputs.be-tag != ''
strategy:
matrix:
include:
- docker-target: "linux/amd64"
target-short: "amd64"
runs-on: ${{ needs.launch-runners.outputs.amd64_label }}
- docker-target: "linux/arm/v7"
target-short: "arm"
runs-on: ${{ needs.launch-runners.outputs.arm_label }}
- docker-target: "linux/arm64"
target-short: "arm64"
runs-on: ${{ needs.launch-runners.outputs.arm64_label }}
runs-on: ${{ matrix.runs-on }}
steps:
- name: Checkout Build Files
uses: actions/checkout@v4
- name: Checkout Lemmy Frontend Source (${{ env.FE_TAG }})
uses: actions/checkout@v4
if: env.FE_TAG != ''
with:
repository: ${{ env.LEMMY_ORG }}/${{ env.FE_REPO }}
ref: ${{ env.FE_TAG }}
path: ${{ env.FE_REPO }}
submodules: recursive
- name: Checkout Lemmy Backend Source (${{ env.BE_TAG }})
uses: actions/checkout@v4
if: github.event.inputs.be-tag != ''
with:
repository: ${{ env.LEMMY_ORG }}/${{ env.BE_REPO }}
ref: ${{ env.BE_TAG }}
path: ${{ env.BE_REPO }}
submodules: recursive
- name: Override Frontend Dockerfile
if: env.FE_TAG != ''
run: cp -f ./Dockerfile-frontend ./${{ env.FE_REPO }}/Dockerfile
- name: Override Backend Dockerfile
if: github.event.inputs.be-tag != ''
run: cp -f ./Dockerfile-backend ./${{ env.BE_REPO }}/Dockerfile
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.DST_REGISTRY }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Frontend (${{ env.FE_TAG }}, ${{ matrix.docker-target }})
if: env.FE_TAG != ''
uses: docker/build-push-action@v5
with:
context: ./${{ env.FE_REPO }}
file: ./${{ env.FE_REPO }}/Dockerfile
platforms: ${{ matrix.docker-target }}
push: true
tags: ${{ env.DST_REGISTRY }}/${{ github.repository_owner }}/${{ env.FE_REPO }}:${{ env.FE_TAG }}-${{ matrix.target-short }}
- name: Build and push Backend (${{ env.BE_TAG }}, ${{ matrix.docker-target }})
if: github.event.inputs.be-tag != ''
uses: docker/build-push-action@v5
with:
context: ./${{ env.BE_REPO }}
file: ./${{ env.BE_REPO }}/Dockerfile
platforms: ${{ matrix.docker-target }}
push: true
tags: ${{ env.DST_REGISTRY }}/${{ github.repository_owner }}/${{ env.BE_REPO }}:${{ env.BE_TAG }}-${{ matrix.target-short }}
stop-runners:
needs: [launch-runners,build-images]
runs-on: ubuntu-latest
if: (github.event.inputs.fe-tag != '' || github.event.inputs.be-tag != '') && always()
strategy:
matrix:
include:
- shutdown-label: ${{ needs.launch-runners.outputs.amd64_label }}
docker-target: "linux/amd64"
runner-arch: "x64"
- shutdown-label: ${{ needs.launch-runners.outputs.arm_label }}
docker-target: "linux/arm/v7"
runner-arch: "arm64"
- shutdown-label: ${{ needs.launch-runners.outputs.arm64_label }}
docker-target: "linux/arm64"
runner-arch: "arm64"
steps:
- name: Terminate Runner (${{ matrix.runner-arch }}, ${{ matrix.docker-target }})
uses: ubergeek77/aws-ec2-spot-runner@v1
with:
shutdown-label: ${{ matrix.shutdown-label }}
github-token: ${{ secrets.RUNNER_TOKEN }}
github-repo: ${{ github.repository }}
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
squash-images:
needs: build-images
if: github.event.inputs.fe-tag != '' || github.event.inputs.be-tag != ''
runs-on: ubuntu-latest
steps:
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.DST_REGISTRY }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Squash Frontend Multiarch Tags
if: env.FE_TAG != ''
uses: ubergeek77/squash-docker-tags@v1
with:
source-tags: |
${{ env.DST_REGISTRY }}/${{ github.repository_owner }}/${{ env.FE_REPO }}:${{ env.FE_TAG }}-amd64
${{ env.DST_REGISTRY }}/${{ github.repository_owner }}/${{ env.FE_REPO }}:${{ env.FE_TAG }}-arm
${{ env.DST_REGISTRY }}/${{ github.repository_owner }}/${{ env.FE_REPO }}:${{ env.FE_TAG }}-arm64
destination-tag: ${{ env.DST_REGISTRY }}/${{ github.repository_owner }}/${{ env.FE_REPO }}:${{ env.FE_TAG }}
- name: Squash Backend Multiarch Tags
if: github.event.inputs.be-tag != ''
uses: ubergeek77/squash-docker-tags@v1
with:
source-tags: |
${{ env.DST_REGISTRY }}/${{ github.repository_owner }}/${{ env.BE_REPO }}:${{ env.BE_TAG }}-amd64
${{ env.DST_REGISTRY }}/${{ github.repository_owner }}/${{ env.BE_REPO }}:${{ env.BE_TAG }}-arm
${{ env.DST_REGISTRY }}/${{ github.repository_owner }}/${{ env.BE_REPO }}:${{ env.BE_TAG }}-arm64
destination-tag: ${{ env.DST_REGISTRY }}/${{ github.repository_owner }}/${{ env.BE_REPO }}:${{ env.BE_TAG }}