Use docker manifests (#4315)
* create manifest * map fix * fix author info
Paweł Krupa committed
Sep 29, 2018 at 16:02 UTC
a40fb515bb9b4b29e15e4f0438107c32505163f3
1 file changed
+45
-19
docker/build.sh
+45
-19
@@ -1,51 +1,77 @@
1
#!/bin/bash
2
# SPDX-License-Identifier: GPL-3.0+
3
-# author : paulfantom
3
+# Author : Pawel Krupa (paulfantom)
4
# Cross-arch docker build helper script
5
6
-set +e
6
+set -e
7
8
REPOSITORY="${REPOSITORY:-netdata}"
9
10
if [ ${VERSION+x} ]; then
11
- VERSION="-${VERSION}"
11
+ VERSION="${VERSION}"
12
else
13
- VERSION=""
13
+ VERSION="latest"
14
fi
15
16
+declare -A ARCH_MAP
17
+ARCH_MAP=( ["i386"]="386" ["amd64"]="amd64" ["armhf"]="arm" ["aarch64"]="arm64")
18
+
19
docker run --rm --privileged multiarch/qemu-user-static:register --reset
20
21
if [ -f Dockerfile ]; then
22
cd ../ || exit 1
23
fi
24
25
+# Build images using multi-arch Dockerfile.
26
for ARCH in i386 armhf aarch64 amd64; do
23
- docker build --build-arg ARCH="${ARCH}-v3.8" --tag "${REPOSITORY}:${ARCH}${VERSION}" --file docker/Dockerfile ./
27
+ docker build --build-arg ARCH="${ARCH}-v3.8" --tag "${REPOSITORY}:${VERSION}-${ARCH}" --file docker/Dockerfile ./ &
28
done
25
-docker tag "${REPOSITORY}:${ARCH}${VERSION}" "${REPOSITORY}:latest"
29
+wait
30
27
-# Push images to registry
28
-if [ -z ${DOCKER_USERNAME+x} ]; then
29
- echo "No docker hub username specified. Exiting without pushing images to registry"
30
- exit 1
31
-fi
32
-if [ -z ${DOCKER_PASSWORD+x} ]; then
33
- echo "No docker hub password specified. Exiting without pushing images to registry"
31
+# Create temporary docker CLI config with experimental features enabled (manifests v2 need it)
32
+mkdir -p /tmp/docker
33
+echo '{"experimental":"enabled"}' > /tmp/docker/config.json
34
+
35
+# Login to docker hub to allow for futher operations
36
+if [ -z ${DOCKER_USERNAME+x} ] || [ -z ${DOCKER_PASSWORD+x} ]; then
37
+ echo "No docker hub username or password specified. Exiting without pushing images to registry"
38
exit 1
39
fi
36
-echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
40
+echo "$DOCKER_PASSWORD" | docker --config /tmp/docker login -u "$DOCKER_USERNAME" --password-stdin
41
+
42
+# Push images to registry
43
for ARCH in amd64 i386 armhf aarch64; do
38
- docker push "${REPOSITORY}:${ARCH}${VERSION}"
44
+ docker --config /tmp/docker push "${REPOSITORY}:${VERSION}-${ARCH}" &
45
done
40
-docker push "${REPOSITORY}:latest"
46
+wait
47
+
48
+# Recreate docker manifest
49
+docker --config /tmp/docker manifest create --amend \
50
+ "${REPOSITORY}:${VERSION}" \
51
+ "${REPOSITORY}:${VERSION}-i386" \
52
+ "${REPOSITORY}:${VERSION}-armhf" \
53
+ "${REPOSITORY}:${VERSION}-aarch64" \
54
+ "${REPOSITORY}:${VERSION}-amd64"
55
+
56
+# Annotate manifest with CPU architecture information
57
+for ARCH in i386 armhf aarch64 amd64; do
58
+ docker --config /tmp/docker manifest annotate "${REPOSITORY}:${VERSION}" "${REPOSITORY}:${VERSION}-${ARCH}" --os linux --arch "${ARCH_MAP[$ARCH]}"
59
+done
60
+
61
+# Push manifest to docker hub
62
+docker --config /tmp/docker manifest push -p "${REPOSITORY}:${VERSION}"
63
+
64
+# Show current manifest (debugging purpose only)
65
+docker --config /tmp/docker manifest inspect "${REPOSITORY}:${VERSION}"
66
67
+# Push netdata images to firehol organization
68
# TODO: Remove it after we decide to deprecate firehol/netdata docker repo
69
if [ "$REPOSITORY" != "netdata" ]; then
70
echo "$OLD_DOCKER_PASSWORD" | docker login -u "$OLD_DOCKER_USERNAME" --password-stdin
71
for ARCH in amd64 i386 armhf aarch64; do
46
- docker tag "${REPOSITORY}:${ARCH}${VERSION}" "firehol/netdata:${ARCH}${VERSION}"
47
- docker push "firehol/netdata:${ARCH}${VERSION}"
72
+ docker tag "${REPOSITORY}:${VERSION}-${ARCH}" "firehol/netdata:${ARCH}"
73
+ docker push "firehol/netdata:${ARCH}"
74
done
49
- docker tag "${REPOSITORY}:latest" "firehol/netdata:latest"
75
+ docker tag "${REPOSITORY}:${VERSION}" "firehol/netdata:${VERSION}"
76
docker push "firehol/netdata:latest"
77
fi