-
Notifications
You must be signed in to change notification settings - Fork 75
/
deploy.sh
executable file
·150 lines (128 loc) · 3.3 KB
/
deploy.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
#! /bin/bash
set -e
REPOS=(
"docker.io/jasonish/suricata"
"quay.io/jasonish/suricata"
)
REPO=${REPO:-"docker.io/jasonish/suricata"}
MAJOR=$(basename $(pwd))
VERSION=$(cat VERSION)
LATEST=$(cat ../LATEST)
ARCHS=(amd64 arm64)
DOCKER=docker
TAGS=()
PUSHED_IMAGES=()
PUSHED_MANIFESTS=()
args=()
if test -e Dockerfile.arm32; then
ARCHS+=(arm32)
fi
while [ "$#" -gt 0 ]; do
key="$1"
case "${key}" in
--podman)
DOCKER="podman"
;;
--build)
build="yes"
;;
--push)
push="yes"
;;
--manifest)
manifest="yes"
;;
*)
args+=($key)
;;
esac
shift
done
if [[ "${manifest}" = "yes" && "${push}" != "yes" ]]; then
echo "error: --manifest requires --push"
exit 1
fi
set -- "${args[@]}"
build() {
arch="$1"; shift
if ! test -e Dockerfile.${arch}; then
echo "error: Dockerfile for arch ${arch} does not exist."
exit 1
fi
tag="${REPO}:${VERSION}-${arch}"
TAG=${tag} ARCH=${arch} ../build.sh
TAGS+=("${tag}")
tag="${REPO}:${VERSION}-${arch}-profiling"
TAG=${tag} ARCH=${arch} ../build.sh profiling
TAGS+=("${tag}")
}
manifest() {
version="$1"
variant="$2"
${DOCKER} manifest rm "${REPO}:${version}${variant}" > /dev/null 2>&1 || true
for arch in "${ARCHS[@]}"; do
if test -e Dockerfile.${arch}; then
${DOCKER} manifest create "${REPO}:${version}${variant}" \
-a "${REPO}:${VERSION}-${arch}${variant}"
fi
done
manifest_name="${REPO}:${version}${variant}"
echo "Pushing manifest ${manifest_name}"
PUSHED_MANIFESTS+=("${manifest_name}")
if [ "${DOCKER}" = "docker" ]; then
${DOCKER} manifest push "${manifest_name}"
elif [ "${DOCKER}" = "podman" ]; then
${DOCKER} manifest push --purge "${manifest_name}" \
docker://"${manifest_name}"
else
echo "error: unsupported docker command: ${DOCKER}"
exit 1
fi
}
if [[ "${build}" = "yes" ]]; then
for repo in "${REPOS[@]}"; do
for arch in "${ARCHS[@]}"; do
if test -e Dockerfile.${arch}; then
REPO=${repo} build "${arch}"
REPO=${repo} build "${arch}" "profiling"
fi
done
done
fi
if [[ "${push}" = "yes" ]]; then
for tag in "${TAGS[@]}"; do
echo "===> Pushing ${tag}"
${DOCKER} push ${tag}
PUSHED_IMAGES+=("${tag}")
done
fi
if [[ "${manifest}" = "yes" ]]; then
for repo in "${REPOS[@]}"; do
REPO=${repo} manifest ${VERSION}
REPO=${repo} manifest ${VERSION} "-profiling"
if [ "${MAJOR}" != "${VERSION}" ]; then
REPO=${repo} manifest ${MAJOR}
REPO=${repo} manifest ${MAJOR} "-profiling"
fi
if [ "${MAJOR}" = "${LATEST}" ]; then
REPO=${repo} manifest latest
REPO=${repo} manifest latest "-profiling"
fi
done
fi
echo "Tags built:"
for tag in "${TAGS[@]}"; do
echo "- ${tag}"
done
if [ "${PUSHED_IMAGES}" ]; then
echo "Tags pushed:"
for tag in "${PUSHED_IMAGES[@]}"; do
echo "- ${tag}"
done
fi
if [ "${PUSHED_MANIFESTS}" ]; then
echo "Manifests pushed:"
for tag in "${PUSHED_MANIFESTS[@]}"; do
echo "- ${tag}"
done
fi