-
Notifications
You must be signed in to change notification settings - Fork 8
/
annotations.sh
189 lines (153 loc) · 6.15 KB
/
annotations.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
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
#!/bin/bash
# Heavily edited by Montana Mendy for this Travis use case
set -o errexit
main() {
# arg 1 holds switch string
# arg 2 holds node version
# arg 3 holds tag suffix
case $1 in
"prepare")
docker_prepare
;;
"build")
docker_build
;;
"test")
docker_test
;;
"tag")
docker_tag
;;
"push")
docker_push
;;
"manifest-list-version")
docker_manifest_list_version "$2" "$3"
;;
"manifest-list-test-beta-latest")
docker_manifest_list_test_beta_latest "$2" "$3"
;;
*)
echo "none of above!"
;;
esac
}
function docker_prepare() {
# Prepare the machine before any code installation scripts
setup_dependencies
# Update docker configuration to enable docker manifest command
update_docker_configuration
# Prepare qemu to build images other then x86_64 on travis
prepare_qemu
}
function docker_build() {
# Build Docker image
echo "DOCKER BUILD: Build Docker image."
echo "DOCKER BUILD: arch - ${ARCH}."
echo "DOCKER BUILD: build version -> ${BUILD_VERSION}."
echo "DOCKER BUILD: webtrees version -> ${WT_VERSION}."
echo "DOCKER BUILD: qemu arch - ${QEMU_ARCH}."
echo "DOCKER BUILD: docker file - ${DOCKER_FILE}."
docker build --no-cache \
--build-arg ARCH=${ARCH} \
--build-arg BUILD_DATE=$(date +"%Y-%m-%dT%H:%M:%SZ") \
--build-arg BUILD_VERSION=${BUILD_VERSION} \
--build-arg BUILD_REF=${TRAVIS_COMMIT} \
--build-arg WT_VERSION=${WT_VERSION} \
--build-arg QEMU_ARCH=${QEMU_ARCH} \
--file ./${DOCKER_FILE} \
--tag ${TARGET}:build .
}
function docker_test() {
echo "DOCKER TEST: Test Docker image."
echo "DOCKER TEST: testing image -> ${TARGET}:build"
docker run -d --rm --name=testing ${TARGET}:build
if [ $? -ne 0 ]; then
echo "DOCKER TEST: FAILED - Docker container testing failed to start."
exit 1
else
echo "DOCKER TEST: PASSED - Docker container testing succeeded to start."
fi
}
function docker_tag() {
echo "DOCKER TAG: Tag Docker image."
echo "DOCKER TAG: tagging image - ${TARGET}:${BUILD_VERSION}-${ARCH}"
docker tag ${TARGET}:build ${TARGET}:${BUILD_VERSION}-${ARCH}
}
function docker_push() {
echo "DOCKER PUSH: Push Docker image."
echo "DOCKER TAG: pushing image - ${TARGET}:${BUILD_VERSION}-${ARCH}"
docker push ${TARGET}:${BUILD_VERSION}-${ARCH}
}
function docker_manifest_list_version() {
echo "DOCKER MANIFEST: Create and Push docker manifest list - ${TARGET}:${BUILD_VERSION}."
docker manifest create ${TARGET}:${BUILD_VERSION} \
${TARGET}:${BUILD_VERSION}-amd64 \
${TARGET}:${BUILD_VERSION}-arm32v7 \
${TARGET}:${BUILD_VERSION}-arm64v8 \
${TARGET}:${BUILD_VERSION}-ppc64le \
${TARGET}:${BUILD_VERSION}-s390x
docker manifest annotate ${TARGET}:${BUILD_VERSION} ${TARGET}:${BUILD_VERSION}-arm32v7 --os=linux --arch=arm --variant=v7
docker manifest annotate ${TARGET}:${BUILD_VERSION} ${TARGET}:${BUILD_VERSION}-arm64v8 --os=linux --arch=arm64 --variant=v8
docker manifest annotate ${TARGET}:${BUILD_VERSION} ${TARGET}:${BUILD_VERSION}-ppc64le --os=linux --arch=ppc64le
docker manifest annotate ${TARGET}:${BUILD_VERSION} ${TARGET}:${BUILD_VERSION}-s390x --os=linux --arch=s390x
docker manifest push ${TARGET}:${BUILD_VERSION}
docker run --rm mplatform/mquery ${TARGET}:${BUILD_VERSION}
}
function docker_manifest_list_test_beta_latest() {
if [[ ${BUILD_VERSION} == *"test"* ]]; then
export TAG_PREFIX="test";
elif [[ ${BUILD_VERSION} == *"beta"* ]]; then
export TAG_PREFIX="beta";
else
export TAG_PREFIX="latest";
fi
echo "DOCKER MANIFEST: Create and Push docker manifest list - ${TARGET}:${TAG_PREFIX}."
docker manifest create ${TARGET}:${TAG_PREFIX} \
${TARGET}:${BUILD_VERSION}-amd64 \
${TARGET}:${BUILD_VERSION}-arm32v7 \
${TARGET}:${BUILD_VERSION}-arm64v8 \
${TARGET}:${BUILD_VERSION}-ppc64le \
${TARGET}:${BUILD_VERSION}-s390x
docker manifest annotate ${TARGET}:${TAG_PREFIX} ${TARGET}:${BUILD_VERSION}-arm32v7 --os=linux --arch=arm --variant=v7
docker manifest annotate ${TARGET}:${TAG_PREFIX} ${TARGET}:${BUILD_VERSION}-arm64v8 --os=linux --arch=arm64 --variant=v8
docker manifest annotate ${TARGET}:${TAG_PREFIX} ${TARGET}:${BUILD_VERSION}-ppc64le --os=linux --arch=ppc64le
docker manifest annotate ${TARGET}:${TAG_PREFIX} ${TARGET}:${BUILD_VERSION}-s390x --os=linux --arch=s390x
docker manifest push ${TARGET}:${TAG_PREFIX}
docker run --rm mplatform/mquery ${TARGET}:${TAG_PREFIX}
}
function setup_dependencies() {
echo "PREPARE: Setting up dependencies."
sudo apt update -y
sudo apt install --only-upgrade docker-ce -y
}
function update_docker_configuration() {
echo "PREPARE: Updating docker configuration"
mkdir $HOME/.docker
# enable experimental to use docker manifest command
echo '{
"experimental": "enabled"
}' | tee $HOME/.docker/config.json
# enable experimental
echo '{
"experimental": true,
"storage-driver": "overlay2",
"max-concurrent-downloads": 50,
"max-concurrent-uploads": 50
}' | sudo tee /etc/docker/daemon.json
sudo service docker restart
}
function prepare_qemu() {
echo "PREPARE: Qemu"
# Prepare qemu to build non amd64 / x86_64 images
docker run --rm --privileged multiarch/qemu-user-static:register --reset
mkdir tmp
pushd tmp &&
curl -L -o qemu-x86_64-static.tar.gz https://github.com/multiarch/qemu-user-static/releases/download/$QEMU_VERSION/qemu-x86_64-static.tar.gz && tar xzf qemu-x86_64-static.tar.gz &&
curl -L -o qemu-arm-static.tar.gz https://github.com/multiarch/qemu-user-static/releases/download/$QEMU_VERSION/qemu-arm-static.tar.gz && tar xzf qemu-arm-static.tar.gz &&
curl -L -o qemu-ppc64le-static.tar.gz https://github.com/multiarch/qemu-user-static/releases/download/$QEMU_VERSION/qemu-ppc64le-static.tar.gz && tar xzf qemu-ppc64le-static.tar.gz &&
curl -L -o qemu-s390x-static.tar.gz https://github.com/multiarch/qemu-user-static/releases/download/$QEMU_VERSION/qemu-s390x-static.tar.gz && tar xzf qemu-s390x-static.tar.gz &&
curl -L -o qemu-aarch64-static.tar.gz https://github.com/multiarch/qemu-user-static/releases/download/$QEMU_VERSION/qemu-aarch64-static.tar.gz && tar xzf qemu-aarch64-static.tar.gz &&
popd
}
main "$1" "$2" "$3"