-
Notifications
You must be signed in to change notification settings - Fork 6
302 lines (240 loc) · 9.37 KB
/
on-tag.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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
name: Build & deploy on git tag push
env:
APP: lnd
# Capture groups in $TAG_FMT:
# \1 => TAG vX.Y.Z[.P][-VARIANT]+build<N>
# \2 => VERSION vX.Y.Z[.P]
# \3 => ignore (captures dot, and last number-group in version)
# \4 => VARIANT VARIANT
# \5 => BUILD N
TAG_FMT: '^refs/tags/((v(.?[0-9]+){3,4})-?([^+]+)?\+build([0-9]+))$'
on:
push:
tags: [ '*' ]
jobs:
build:
name: Build lnd
runs-on: ubuntu-20.04
strategy:
matrix:
arch:
- amd64
- arm32v6
- arm32v7
- arm64v8
env:
QEMU_VERSION: v5.1.0
DOCKER_BUILDKIT: 1
steps:
- uses: actions/checkout@v2
- name: Setup environment
run: |
if ! echo "$GITHUB_REF" | grep -qE "$TAG_FMT"; then
echo "ERR: TAG must be in format: vX.Y.Z[.P][-VARIANT]+build<N>"
exit 1
fi
VERSION="$(echo "$GITHUB_REF" | sed -E "s|$TAG_FMT|\2|")"
DIR="$(echo "${VERSION#v}" | cut -d. -f-2)"
if ! grep -q "^ARG VERSION=$VERSION\(-beta\)\?$" "$DIR/Dockerfile"; then
echo "ERR: $DIR/Dockerfile must contain VERSION=$VERSION"
exit 1
fi
echo "DIR=$DIR" >>"$GITHUB_ENV"
TAG="$(echo "$GITHUB_REF" | sed -E "s|$TAG_FMT|\1|")"
echo "TAG=$TAG" >>"$GITHUB_ENV"
echo "VARIANT=$(echo "$GITHUB_REF" | sed -E "s|$TAG_FMT|\4|")" >>"$GITHUB_ENV"
echo "BUILD=$(echo "$GITHUB_REF" | sed -E "s|$TAG_FMT|\5|")" >>"$GITHUB_ENV"
echo "FILE_SUFFIX=$(echo "$TAG" | tr + -)-${{ matrix.arch }}" >>"$GITHUB_ENV"
# GOARCH => arm|arm64
# GOARM => 6|7
- name: Setup Go environment
if: matrix.arch != 'amd64'
env:
ARCH: ${{ matrix.arch }}
run: |
GOARCH="${ARCH%32v?}"
echo "GOARCH=${GOARCH%v8}" >>"$GITHUB_ENV"
echo "GOARM=$(echo "$ARCH" | sed -En 's|^arm32v([6-7])$|\1|p')" >>"$GITHUB_ENV"
- name: Print ENV VARs set above
run: |
printf " APP: %s\n" "$APP"
printf " ARCH: %s\n" "${{ matrix.arch }}"
printf " TAG: %s\n" "$TAG"
printf "VARIANT: %s\n" "$VARIANT"
printf " DIR: %s\n" "$DIR"
printf " BUILD: %s\n" "$BUILD"
printf " SUFFIX: %s\n" "$FILE_SUFFIX"
printf " GOARCH: %s\n" "$GOARCH"
printf " GOARM: %s\n" "$GOARM"
- name: Apply variant patch (if any)
if: env.VARIANT != ''
run: (cd "$DIR/" && patch < variant-$VARIANT.patch)
- name: Build ${{ env.APP }}
run: >
docker build --no-cache "$DIR/"
--build-arg "ARCH=${{ matrix.arch }}"
--build-arg "GOARCH=$GOARCH"
--build-arg "GOARM=$GOARM"
--label "arch=${{ matrix.arch }}"
--label "commit=${{ github.sha }}"
--label "git-tag=$TAG"
--label "guilty=${{ github.actor }}"
--label "repo-url=${{ github.repositoryUrl }}"
--label "variant=$VARIANT"
--tag "$APP"
- name: Show built image details
run: docker images "$APP"
- name: Register self-compiled qemu
if: matrix.arch != 'amd64'
env:
ARCH: ${{ matrix.arch }}
run: docker run --rm --privileged "meedamian/simple-qemu:$QEMU_VERSION-${ARCH%32v6}" -p yes
- name: Run sanity checks
env:
DIR: /usr/local/bin
run: |
run() {
ENTRYPOINT="${1:-$APP}"; shift;
ARGS=${*:-"--version"}
printf "\n$ %s %s\n" "$ENTRYPOINT" "$ARGS"
docker run --rm --entrypoint "$ENTRYPOINT" "$APP" $ARGS
printf "\n"
}
docker inspect "$APP" | jq '.'
printf "\n"
run lnd
run lncli
run uname -a
run cat /etc/os-release
run sha256sum "$DIR/lnd" "$DIR/lncli"
docker run --rm --entrypoint=sh -u=root "$APP" -c "apk add --no-cache file && file $DIR/lnd $DIR/lncli"
- name: Save image to a .tgz file
run: |
mkdir -p images/
docker tag "$APP" "$APP:${{ matrix.arch }}"
docker save "$APP:${{ matrix.arch }}" | gzip > "images/docker-$APP-$FILE_SUFFIX.tgz"
- name: Print sha256sum of built image
run: (cd images/; sha256sum *)
- name: Upload docker image as build artifact
uses: actions/[email protected]
with:
name: docker-images
path: images/
- name: Extract binaries from the built image
env:
IMG: ${{ env.APP }}:${{ matrix.arch }}
SRC: /usr/local/bin
BINARIES: lnd lncli
DST: binaries
run: |
mkdir -p "$DST"
id="$(docker create "$IMG")"
for binary in $BINARIES; do
docker cp "$id:$SRC/$binary" - | gzip -n > "$DST/$binary-$FILE_SUFFIX.gz"
done
docker rm "$id"
(cd "$DST"; sha256sum *)
- name: Upload raw binaries as build artifacts
uses: actions/[email protected]
with:
name: binaries
path: binaries/
deploy:
name: Deploy to Docker Hub & Github Releases. Only after successful build.
runs-on: ubuntu-18.04
needs: build
env:
DOCKER_CLI_EXPERIMENTAL: enabled
steps:
- name: Setup environment
run: |
(
echo "SLUG=${GITHUB_REPOSITORY,,}" | sed 's|docker-||'
echo "TAG=$(echo "$GITHUB_REF" | sed -E "s|$TAG_FMT|\1|")"
echo "BUILD=$(echo "$GITHUB_REF" | sed -E "s|$TAG_FMT|\5|")"
VERSION="$(echo "$GITHUB_REF" | sed -E "s|$TAG_FMT|\2|")"
VARIANT="$(echo "$GITHUB_REF" | sed -E "s|$TAG_FMT|\4|")"
echo "VERSION=$VERSION"
echo "VARIANT=$VARIANT"
echo "BASE_TAG=$VERSION${VARIANT:+-$VARIANT}"
) >>"$GITHUB_ENV"
- name: Print just set ENV VARs
run: |
printf " APP: %s\n" "$APP"
printf " TAG: %s\n" "$TAG"
printf " SLUG: %s\n" "$SLUG"
printf "VERSION: %s\n" "$VERSION"
printf " BUILD: %s\n" "$BUILD"
printf "BASE_TAG: %s\n" "$BASE_TAG"
- name: Download all build artifacts
uses: actions/[email protected]
with:
name: docker-images
- name: Print sha256sum of downloaded images
run: sha256sum docker-images/*
- name: Load images locally
run: find docker-images -exec docker load -i "{}" \;
- name: Version-tag all images
run: |
for arch in $(docker images "$APP" --format "{{.Tag}}"); do
docker tag "$APP:$arch" "$SLUG:$BASE_TAG-$arch-build$BUILD"
docker tag "$APP:$arch" "$SLUG:$BASE_TAG-$arch"
done
- name: List all tagged images
run: docker images "$SLUG"
- name: Login to Docker Hub
env:
DOCKER_USER: ${{ secrets.DOCKER_TOKEN_USER }}
run: |
echo "Logging in as ${DOCKER_USER}…"
echo "${{ secrets.DOCKER_TOKEN }}" | docker login -u="$DOCKER_USER" --password-stdin
- name: Push all images
run: docker images "$SLUG" --format "{{.Repository}}:{{.Tag}}" | xargs -I % docker push %
- name: Create manifest
run: >
docker -D manifest create "$SLUG:$BASE_TAG" \
"$SLUG:$BASE_TAG-amd64" \
"$SLUG:$BASE_TAG-arm32v6" \
"$SLUG:$BASE_TAG-arm32v7" \
"$SLUG:$BASE_TAG-arm64v8"
- name: Annotate images for manifest
run: |
docker manifest annotate "$SLUG:$BASE_TAG" "$SLUG:$BASE_TAG-arm32v6" --os linux --arch arm --variant v6
docker manifest annotate "$SLUG:$BASE_TAG" "$SLUG:$BASE_TAG-arm32v7" --os linux --arch arm --variant v7
docker manifest annotate "$SLUG:$BASE_TAG" "$SLUG:$BASE_TAG-arm64v8" --os linux --arch arm64 --variant v8
- name: Print manifest details
run: docker manifest inspect "$SLUG:$BASE_TAG" | jq '.'
- name: Push manifest
run: docker manifest push "$SLUG:$BASE_TAG"
- name: Download binaries from build artifacts
uses: actions/[email protected]
with:
name: binaries
- name: Create & print SHA256SUMS file
run: |
(cd docker-images; sha256sum *) >> ./SHA256SUMS
(cd binaries; sha256sum *) >> ./SHA256SUMS
cat ./SHA256SUMS
- name: Add variant info to Release desc
if: env.VARIANT != ''
run: |
DIR="$(echo "${VERSION#v}" | cut -d. -f-2)"
URL="$(printf 'https://github.com/%s/blob/%s/%s/variant-%s.patch' \
"${{ github.repository }}" \
"${{ github.sha }}" \
"$DIR" \
"$VARIANT")"
echo "VARIANT_NOTE=$(printf ' and has been build in [`%s`](%s) variant' "$VARIANT" "$URL")" >>"$GITHUB_ENV"
- name: Upload binaries to Github Release
uses: meeDamian/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
name: ${{ env.BASE_TAG }}
body: |
This release packages `lnd` to be on par with https://github.com/lightningnetwork/lnd/releases/tag/${{ env.VERSION }}-beta${{ env.VARIANT_NOTE }}.
prerelease: true
gzip: false
files: >
docker-images/*
binaries/*
SHA256SUMS