-
-
Notifications
You must be signed in to change notification settings - Fork 67
/
build-containers.sh
executable file
·157 lines (132 loc) · 3.43 KB
/
build-containers.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
#! /bin/bash
#
# Arguments:
#
# --push Push images and manifest
# --latest Also tag as "latest"
#
# Variables:
#
# version EveBox version to containerize, default tag
# tag Override the tag which defaults to the version
set -e
REGISTRY=${REGISTRY:-docker.io}
BUILD_REV=$(git rev-parse --short HEAD)
DOCKER_NAME="${REGISTRY}/jasonish/evebox"
GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
GIT_TAG=$(git describe --tags --abbrev=0 --exact-match 2> /dev/null || echo "")
push="no"
latest="no"
aliases=()
for a in $@; do
case "$a" in
--push)
push="yes"
;;
--latest)
latest="yes"
aliases+=("latest")
;;
*)
echo "error: bad argument: $a"
exit 1
;;
esac
done
if [[ "${GIT_TAG}" ]]; then
echo "Building container for version ${GIT_TAG}"
version="${GIT_TAG}"
elif [[ "${GIT_BRANCH}" = "devel" ]]; then
version="devel"
tag="devel"
elif [[ "${GIT_BRANCH}" = "main" ]]; then
echo "Building devel version from branch main"
version="devel"
tag="main"
aliases+=("master")
else
echo "Not building from branch or tag."
echo " - version and tag must be set"
fi
echo "BRANCH=${GIT_BRANCH}"
if [[ "${version}" = "" ]]; then
echo "error: version must be set"
exit 1
fi
if [[ "${tag}" = "" ]]; then
echo "error: tag must be set"
exit 1
fi
if [[ "${tag}" = "master" ]]; then
echo "===> Will also push as 'main'"
aliases+=("main")
fi
if [[ "${tag}" = "main" ]]; then
echo "===> Will also push as 'master'"
aliases+=("master")
fi
bins=(
./dist/evebox-${version}-linux-x64/evebox
./dist/evebox-${version}-linux-arm64/evebox
)
for bin in ${bins}; do
if ! test -e ${bin}; then
echo "error: ${bin} does not exist"
exit 1
fi
done
tags_built=()
tags_pushed=()
manifests_pushed=()
name="${DOCKER_NAME}:${tag}-amd64"
${ECHO} docker build \
--platform linux/amd64 \
--build-arg "SRC=./dist/evebox-${version}-linux-x64/evebox" \
-t ${name} \
-f docker/Dockerfile .
tags_built+=(${name})
name="${DOCKER_NAME}:${tag}-arm64v8"
${ECHO} docker build \
--platform linux/arm64 \
--build-arg "SRC=./dist/evebox-${version}-linux-arm64/evebox" \
-t ${name} \
-f docker/Dockerfile .
tags_built+=(${name})
function push() {
source=$1
echo "Pushing ${source}"
${ECHO} docker push ${source}
tags_pushed+=(${source})
}
function push_manifest() {
manifest=$1
echo "Pushing ${manifest}"
${ECHO} docker manifest push --purge ${manifest}
manifests_pushed+=(${manifest})
}
if [[ "${push}" = "yes" ]]; then
push ${DOCKER_NAME}:${tag}-amd64
push ${DOCKER_NAME}:${tag}-arm64v8
${ECHO} docker manifest create -a ${DOCKER_NAME}:${tag} \
${DOCKER_NAME}:${tag}-amd64 \
${DOCKER_NAME}:${tag}-arm64v8
push_manifest ${DOCKER_NAME}:${tag}
for alias in ${aliases}; do
${ECHO} docker manifest create -a ${DOCKER_NAME}:${alias} \
${DOCKER_NAME}:${tag}-amd64 \
${DOCKER_NAME}:${tag}-arm64v8
push_manifest ${DOCKER_NAME}:${alias}
done
echo "Tags pushed:"
for tag in ${tags_pushed[@]}; do
echo " ${tag}"
done
echo "Manifests pushed:"
for manifest in ${manifests_pushed[@]}; do
echo " ${manifest}"
done
else
echo ""
echo "Re-run with --push to push."
echo ""
fi