-
-
Notifications
You must be signed in to change notification settings - Fork 19
242 lines (206 loc) · 7.9 KB
/
buildDocker.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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
#*******************************************************************************
# buidDocker.yml
#
# Workflow to build and push a multiplatform (amd64, arm64 & arm7) Linux Docker
# image for Medley. This workflow uses the latest Maiko docker image and the
# latest Medley release on github.
#
# This workflow contains a sentry that causes it to skip the build (as identified
# by its commit SHA) if its already been done. Setting the "force" input to true
# will bypass this sentry,
#
# Updated 2022-01-18 by Frank Halasz from on earlier buildDocker.yml
#
# Copyright 2022 by Interlisp.org
#
# ******************************************************************************
name: 'Build/Push Docker Image'
# Run this workflow on ...
on:
workflow_dispatch:
inputs:
draft:
description: "Mark this as a draft release"
type: choice
options:
- 'false'
- 'true'
force:
description: "Force build even if build already successfully completed for this commit"
type: choice
options:
- 'false'
- 'true'
workflow_call:
outputs:
successful:
description: "'True' if medley docker build completed successully"
value: ${{ jobs.complete.outputs.build_successful }}
inputs:
draft:
description: "Mark this as a draft release"
required: false
type: string
default: 'false'
force:
description: "Force build even if build already successfully completed for this commit"
required: false
type: string
default: 'false'
secrets:
DOCKER_USERNAME:
required: true
DOCKER_PASSWORD:
required: true
defaults:
run:
shell: bash
jobs:
######################################################################################
# Use sentry-action to determine if this release has already been built
# based on the latest commit to the repo
sentry:
runs-on: ubuntu-24.04
outputs:
release_not_built: ${{ steps.check.outputs.release_not_built }}
steps:
# Checkout the actions for this repo owner
- name: Checkout Actions
uses: actions/checkout@v4
with:
repository: ${{ github.repository_owner }}/.github
path: ./Actions_${{ github.sha }}
- run: mv ./Actions_${{ github.sha }}/actions ../actions && rm -rf ./Actions_${{ github.sha }}
# Check if build already run for this commit
- name: Build already completed?
id: check
continue-on-error: true
uses: ./../actions/check-sentry-action
with:
tag: "docker"
######################################################################################
#
# Build and push the medley docker image
#
build_and-push:
runs-on: ubuntu-24.04
needs: [sentry]
if: |
needs.sentry.outputs.release_not_built == 'true'
|| inputs.force == 'true'
steps:
# Checkout latest commit
- name: Checkout Medley
uses: actions/checkout@v4
# Find latest release (draft or normal)
# and download its assets
- name: Download linux debs from latest (draft) release
run: |
tag=""
if [ "${{ inputs.draft }}" = "true" ];
then
tag=$(gh release list | grep Draft | head -n 1 | awk '{ print $3 }')
fi
if [ -z "${tag}" ];
then
tag=$(gh release list | grep Latest | head -n 1 | awk '{ print $3 }')
fi
mkdir -p release_debs
gh release download ${tag} -D release_debs -p '*-linux-*.deb'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Get Maiko and Medley release information from name of deb files
# just downloaded from the Medley latest release
- name: Get info about Miako and Medley releases
id: release_info
run: |
regex="^medley-full-[^-]*-[^-]*-\([^_]*\)_\(.*\).deb\$"
ls -1 release_debs | head -n 1 > debname.tmp
medley_release="medley-$(sed -e "s/${regex}/\1/" debname.tmp)"
maiko_release="maiko-$(sed -e "s/${regex}/\2/" debname.tmp)"
rm -f debname.tmp
echo "MEDLEY_RELEASE=${medley_release}" >> ${GITHUB_ENV}
echo "MAIKO_RELEASE=${maiko_release}" >> ${GITHUB_ENV}
# regex="^[^0-9]*\([^_]*\)_\([^-]*-[^-]*\)-\([^-]*\)-\([^.]*\).*\$"
# Set repo env variables
- name: Set repo/docker env variables
id: repo_env
run: |
repo_name="${GITHUB_REPOSITORY#*/}"
docker_namespace="$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]')"
docker_image="${docker_namespace}/${repo_name}"
if [ "${{ inputs.draft }}" = "false" ];
then
docker_tags="${docker_image}:latest,${docker_image}:${MEDLEY_RELEASE#*-}_${MAIKO_RELEASE#*-}"
platforms="linux/amd64,linux/arm64"
else
docker_tags="${docker_image}:draft"
platforms="linux/amd64"
fi
echo "REPO_NAME=${repo_name}" >> ${GITHUB_ENV}
echo "DOCKER_NAMESPACE=${docker_namespace}" >> ${GITHUB_ENV}
echo "DOCKER_IMAGE=${docker_image}" >> ${GITHUB_ENV}
echo "DOCKER_TAGS=${docker_tags}" >> ${GITHUB_ENV}
echo "BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> ${GITHUB_ENV}
echo "PLATFORMS=${platforms}" >> ${GITHUB_ENV}
#linux/amd64,linux/arm64,linux/arm/v7
# Setup the Docker Machine Emulation environment.
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: linux/amd64,linux/arm64,linux/arm/v7
# Setup the Docker Buildx funtion
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
# Login into DockerHub - required to store the created image
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
# Do the Docker Build using the Dockerfile in the repository
# checked out and the release tars just downloaded.
# Push the result to Docker Hub
- name: Build Docker Image for Push to Docker Hub
uses: docker/build-push-action@v5
with:
builder: ${{ steps.buildx.outputs.name }}
build-args: |
BUILD_DATE=${{ env.BUILD_DATE }}
MEDLEY_RELEASE=${{ env.MEDLEY_RELEASE }}
MAIKO_RELEASE=${{ env.MAIKO_RELEASE }}
REPO_OWNER=${{ github.repository_owner }}
context: ./release_debs
file: ./.github/workflows/Dockerfile_medley
platforms: ${{ env.PLATFORMS }}
# Push the result to DockerHub
push: true
tags: ${{ env.DOCKER_TAGS }}
######################################################################################
# Use set-sentry-action to determine set the sentry that says this release has
# been successfully built
complete:
runs-on: ubuntu-24.04
outputs:
build_successful: ${{ steps.output.outputs.build_successful }}
needs: [sentry, build_and-push]
steps:
# Checkout the actions for this repo owner
- name: Checkout Actions
uses: actions/checkout@v4
with:
repository: ${{ github.repository_owner }}/.github
path: ./Actions_${{ github.sha }}
- run: mv ./Actions_${{ github.sha }}/actions ../actions && rm -rf ./Actions_${{ github.sha }}
# Set sentry
- name: Set flag that build for this commit has been completed
id: set
uses: ./../actions/set-sentry-action
with:
tag: "docker"
- name: Output
id: output
run: |
echo "build_successful='true'" >> ${GITHUB_OUTPUT}
######################################################################################