generated from ReiFan49/golang-static-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate
executable file
·54 lines (45 loc) · 1.72 KB
/
generate
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
#!/bin/bash
# [[ ! -f ver.json ]] && curl -q -o ver.json 'https://api.github.com/repos/ochinchina/supervisord/tags?per_page=100'
# VERSIONS_ONLINE=$(cat ver.json)
GITHUB_REPOSITORY='aptly-dev/aptly'
DOCKER_IMAGE='reifan49/aptly'
DOCKER_IMAGE_AUTHOR='Rei Hakurei'
DOCKER_IMAGE_DESCRIPTION='aptly and supervisord in a lightweight image'
[[ -z ${GITHUB_REPOSITORY} ]] && exit 1
[[ -z ${DOCKER_IMAGE} ]] && exit 1
# Version from main repository
VERSIONS_ONLINE=$(curl -s "https://api.github.com/repos/${GITHUB_REPOSITORY}/tags?per_page=100")
# Version with go.mod
# Use comparison operators to select versions.
VERSIONS_WITH_MODULES=$(echo "${VERSIONS_ONLINE}" | jq '
map(.name) |
map(select(
test("v[1-9][0-9]+.[0-9]+.[0-9]+") //
test("v[2-9].[0-9]+.[0-9]+") //
test("v1.([5-9]|[1-9][0-9]+).[0-9]+")
)) |
map(.[1:]) | .[]' |
sort -V |
sed -E 's|"||g; s|^v||g'
)
# Version with no error on compilation
# Use grep to select versions.
VERSIONS_CAN_BUILD="${VERSIONS_WITH_MODULES}"
# Version already built locally
VERSIONS_ALREADY_BUILT=$(docker image ls --format='{{.Tag}}' "${DOCKER_IMAGE}" | sort -V)
VERSIONS_AVAILABLE="${VERSIONS_CAN_BUILD}"
BUILT_COUNT=
for image_ver in ${VERSIONS_AVAILABLE}; do
(echo "${VERSIONS_ALREADY_BUILT}" | grep -qF "${image_ver}") && continue
docker build -t "${DOCKER_IMAGE}:${image_ver}" \
--build-arg "BRANCH=v${image_ver}" \
--label org.opencontainers.image.authors="${DOCKER_IMAGE_AUTHOR}" \
--label org.opencontainers.image.description="${DOCKER_IMAGE_DESCRIPTION}" \
.
[[ $? -ne 0 ]] || continue
BUILT_COUNT="${BUILT_COUNT}1"
done
[[ -n "${BUILT_COUNT}" ]] && docker push -a "${DOCKER_IMAGE}"
# Perform cleanup
docker builder prune -f
docker image prune -f