forked from vectordotdev/vector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-docker.sh
executable file
·82 lines (69 loc) · 1.97 KB
/
build-docker.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
#!/usr/bin/env bash
set -euo pipefail
# build-docker.sh
#
# SUMMARY
#
# Builds the Vector docker images and optionally
# pushes it to the Docker registry
set -x
CHANNEL="${CHANNEL:-"$(scripts/release-channel.sh)"}"
VERSION="${VERSION:-"$(scripts/version.sh)"}"
DATE="${DATE:-"$(date -u +%Y-%m-%d)"}"
PUSH="${PUSH:-}"
PLATFORM="${PLATFORM:-}"
REPO="${REPO:-"timberio/vector"}"
#
# Functions
#
build() {
local BASE="$1"
local VERSION="$2"
local TAG="$REPO:$VERSION-$BASE"
local DOCKERFILE="distribution/docker/$BASE/Dockerfile"
if [ -n "$PLATFORM" ]; then
export DOCKER_CLI_EXPERIMENTAL=enabled
docker run --rm --privileged docker/binfmt:66f9012c56a8316f9244ffd7622d7c21c1f6f28d
docker buildx rm vector-builder || true
docker buildx create --use --name vector-builder
docker buildx install
docker buildx build \
--platform="$PLATFORM" \
--tag "$TAG" \
target/artifacts \
-f "$DOCKERFILE" ${PUSH:+--push}
else
docker build \
--tag "$TAG" \
target/artifacts \
-f "$DOCKERFILE"
if [ -n "$PUSH" ]; then
docker push "$TAG"
fi
fi
}
#
# Build
#
echo "Building $REPO:* Docker images"
if [[ "$CHANNEL" == "latest" ]]; then
VERSION_EXACT="$VERSION"
# shellcheck disable=SC2001
VERSION_MINOR_X=$(echo "$VERSION" | sed 's/\.[0-9]*$/.X/g')
# shellcheck disable=SC2001
VERSION_MAJOR_X=$(echo "$VERSION" | sed 's/\.[0-9]*\.[0-9]*$/.X/g')
for VERSION_TAG in "$VERSION_EXACT" "$VERSION_MINOR_X" "$VERSION_MAJOR_X" latest; do
build alpine "$VERSION_TAG"
build debian "$VERSION_TAG"
build distroless-static "$VERSION_TAG"
build distroless-libc "$VERSION_TAG"
done
elif [[ "$CHANNEL" == "nightly" ]]; then
build alpine nightly
build distroless-static nightly
build distroless-libc nightly
elif [[ "$CHANNEL" == "test" ]]; then
build "${BASE:-"alpine"}" "${TAG:-"test"}"
build "${BASE:-"distroless-libc"}" "${TAG:-"test"}"
build "${BASE:-"distroless-static"}" "${TAG:-"test"}"
fi