forked from bitnami/minideb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpushmanifest
executable file
·89 lines (76 loc) · 2.04 KB
/
pushmanifest
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
#!/bin/bash
set -e
set -u
set -o pipefail
DISTS=${DISTS:-"stretch
buster
bullseye
latest
"}
DISTS_WITH_SNAPSHOT=${DISTS_WITH_SNAPSHOT:-buster}
BASENAME=bitnami/minideb
GCR_BASENAME=gcr.io/bitnami-containers/minideb
PLATFORMS=${PLATFORMS:-amd64 arm64}
DRY_RUN=${DRY_RUN:-}
SNAPSHOT_ID=${SNAPSHOT_ID:-}
read -r -a ARCHS <<<"$PLATFORMS"
run_docker() {
if [[ -n "${DRY_RUN:-}" ]]; then
echo "DRY RUN docker ${*}"
else
docker "$@"
fi
}
list_includes() {
local list=""
local element=""
list=${1?You must provide a list}
element=${2:?You must provide an element}
for candidate in $list; do
if [[ "$candidate" == "$element" ]]; then
true
return
fi
done
false
return
}
if [ -n "${DOCKER_PASSWORD:-}" ]; then
echo "$DOCKER_PASSWORD" | run_docker login -u "$DOCKER_USERNAME" --password-stdin
fi
if [ -n "${GCR_KEY:-}" ]; then
gcloud auth activate-service-account "$GCR_EMAIL" --key-file <(echo "$GCR_KEY")
gcloud auth print-access-token | run_docker login -u oauth2accesstoken --password-stdin gcr.io
elif [ -n "${GCR_TOKEN:-}" ]; then
echo "${GCR_TOKEN:-}" | run_docker login -u oauth2accesstoken --password-stdin gcr.io
fi
push_manifest() {
local image=""
local archs=""
image="${1:?You must provide the image base to publish}"
archs=("${@:2}")
local arch_images=()
for arch in "${archs[@]}"; do
arch_images+=("$image-$arch")
done
run_docker manifest create "$image" "${arch_images[@]}"
run_docker manifest push "$image"
}
tags=()
for DIST in $DISTS; do
tags+=("$DIST")
if list_includes "$DISTS_WITH_SNAPSHOT" "$DIST" ; then
tags+=("$DIST-snapshot-${SNAPSHOT_ID:-$(./snapshot_id)}")
fi
done
repositories=("$BASENAME")
if [[ -n "${GCR_KEY:-}" || -n "${GCR_TOKEN:-}" ]]; then
repositories+=("$GCR_BASENAME")
else
echo "Skipping repository gcr.io (empty password)"
fi
for tag in "${tags[@]}"; do
for repo in "${repositories[@]}"; do
push_manifest "$repo:$tag" "${ARCHS[@]}"
done
done