-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_functions.sh
executable file
·70 lines (60 loc) · 2.27 KB
/
make_functions.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
#!/bin/sh
set -euf
# Path variables
BASE_DIR=$(realpath $(dirname "$0"))
PROJECT_DIR=${PROJECT_DIR:-${BASE_DIR}}
BUILD_DIR=${BUILD_DIR:-${PROJECT_DIR}/_build/$(go env GOOS)_$(go env GOARCH)}
JUJUD_BIN_DIR=${JUJUD_BIN_DIR:-${BUILD_DIR}/bin}
# Versioning variables
JUJU_BUILD_NUMBER=${JUJU_BUILD_NUMBER:-}
# Docker variables
DOCKER_USERNAME=${DOCKER_USERNAME:-jujusolutions}
DOCKER_STAGING_DIR="${BUILD_DIR}/docker-staging"
DOCKER_BIN=${DOCKER_BIN:-$(which docker)}
_base_image() {
IMG_linux_amd64="amd64/ubuntu:20.04" \
IMG_linux_arm64="arm64v8/ubuntu:20.04" \
IMG_linux_ppc64le="ppc64le/ubuntu:20.04" \
IMG_linux_s390x="s390x/ubuntu:20.04" \
printenv "IMG_$(go env GOOS)_$(go env GOARCH)"
}
_juju_version() {
"${JUJUD_BIN_DIR}/jujud" version | grep -E -o "^[[:digit:]]{1,9}\.[[:digit:]]{1,9}(\.|-[[:alpha:]]+)[[:digit:]]{1,9}(\.[[:digit:]]{1,9})?"
}
_strip_build_version() {
echo "$1" | grep -E -o "^[[:digit:]]{1,9}\.[[:digit:]]{1,9}(\.|-[[:alpha:]]+)[[:digit:]]{1,9}"
}
_image_version() {
_strip_build_version "$(_juju_version)"
}
operator_image_release_path() {
echo "${DOCKER_USERNAME}/jujud-operator:$(_image_version)"
}
operator_image_path() {
if [ -z "${JUJU_BUILD_NUMBER}" ] || [ ${JUJU_BUILD_NUMBER} -eq 0 ]; then
operator_image_release_path
else
echo "${DOCKER_USERNAME}/jujud-operator:$(_image_version).${JUJU_BUILD_NUMBER}"
fi
}
build_operator_image() {
WORKDIR="${DOCKER_STAGING_DIR}/jujud-operator"
rm -rf "${WORKDIR}"
mkdir -p "${WORKDIR}"
# Populate docker build context
cp "${JUJUD_BIN_DIR}/jujud" "${WORKDIR}/"
cp "${JUJUD_BIN_DIR}/jujuc" "${WORKDIR}/"
cp "${JUJUD_BIN_DIR}/containeragent" "${WORKDIR}/"
cp "${JUJUD_BIN_DIR}/pebble" "${WORKDIR}/"
cp "${PROJECT_DIR}/caas/Dockerfile" "${WORKDIR}/"
cp "${PROJECT_DIR}/caas/requirements.txt" "${WORKDIR}/"
# Build image. We tar up the build context to support docker snap confinement.
tar cf - -C "${WORKDIR}" . | "${DOCKER_BIN}" build \
--build-arg BASE_IMAGE=$(_base_image) \
-t "$(operator_image_path)" -
if [ "$(operator_image_path)" != "$(operator_image_release_path)" ]; then
"${DOCKER_BIN}" tag "$(operator_image_path)" "$(operator_image_release_path)"
fi
# Cleanup
rm -rf "${WORKDIR}"
}