This repository has been archived by the owner on Jul 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
container-release.sh
executable file
·88 lines (65 loc) · 2.26 KB
/
container-release.sh
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
#!/bin/bash -xe
###############################
# CHANGE THIS ON EVERY REPO #
DOCKER_IMAGE=$(basename `git rev-parse --show-toplevel`)
###############################
# default env vars in GH actions
GIT_BRANCH=$(echo ${GITHUB_REF} | awk -F'/' '{print $(NF)}' | sed -e 's/[^a-z0-9\._-]/-/g')
# non-tagged builds are not releases, so they always go on nuvladev
DOCKER_ORG=${DOCKER_ORG:-nuvladev}
MANIFEST=${DOCKER_ORG}/${DOCKER_IMAGE}:${GIT_BRANCH}
platforms=(amd64 arm64 arm)
#
# remove any previous builds
#
rm -Rf target/*.tar
mkdir -p target
#
# generate image for each platform
#
for platform in "${platforms[@]}"; do
GIT_BUILD_TIME=$(date --utc +%FT%T.%3NZ)
docker run --rm --privileged -v ${PWD}:/tmp/work --entrypoint buildctl-daemonless.sh moby/buildkit:master \
build \
--frontend dockerfile.v0 \
--opt platform=linux/${platform} \
--opt filename=./Dockerfile \
--opt build-arg:GIT_BRANCH=${GIT_BRANCH} \
--opt build-arg:GIT_BUILD_TIME=${GIT_BUILD_TIME} \
--opt build-arg:GIT_COMMIT_ID=${GITHUB_SHA} \
--opt build-arg:GITHUB_RUN_NUMBER=${GITHUB_RUN_NUMBER} \
--opt build-arg:GITHUB_RUN_ID=${GITHUB_RUN_ID} \
--opt build-arg:PROJECT_URL=${GIHUB_SERVER_URL}/${GITHUB_REPOSITORY} \
--output type=docker,name=${MANIFEST}-${platform},dest=/tmp/work/target/${DOCKER_IMAGE}-${platform}.docker.tar \
--local context=/tmp/work \
--local dockerfile=/tmp/work \
--progress plain
done
#
# load all generated images
#
for platform in "${platforms[@]}"; do
docker load --input ./target/${DOCKER_IMAGE}-${platform}.docker.tar
done
manifest_args=(${MANIFEST})
#
# login to docker hub
#
unset HISTFILE
echo ${DOCKER_PASSWORD} | docker login -u ${DOCKER_USERNAME} --password-stdin
#
# push all generated images
#
for platform in "${platforms[@]}"; do
docker push ${MANIFEST}-${platform}
manifest_args+=("${MANIFEST}-${platform}")
done
#
# create manifest, update, and push
#
export DOCKER_CLI_EXPERIMENTAL=enabled
docker manifest create "${manifest_args[@]}"
for platform in "${platforms[@]}"; do
docker manifest annotate ${MANIFEST} ${MANIFEST}-${platform} --arch ${platform}
done
docker manifest push --purge ${MANIFEST}