forked from vectordotdev/vector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-docker.sh
executable file
·90 lines (77 loc) · 2.1 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
83
84
85
86
87
88
89
90
#!/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:-"$(cargo vdev release channel)"}"
VERSION="${VECTOR_VERSION:-"$(cargo vdev version)"}"
DATE="${DATE:-"$(date -u +%Y-%m-%d)"}"
PLATFORM="${PLATFORM:-}"
PUSH="${PUSH:-"true"}"
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
ARGS=()
if [[ "$PUSH" == "true" ]]; then
ARGS+=(--push)
fi
docker buildx build \
--platform="$PLATFORM" \
--tag "$TAG" \
target/artifacts \
-f "$DOCKERFILE" \
"${ARGS[@]}"
else
docker build \
--tag "$TAG" \
target/artifacts \
-f "$DOCKERFILE"
if [[ "$PUSH" == "true" ]]; then
docker push "$TAG"
fi
fi
}
#
# Build
#
echo "Building $REPO:* Docker images"
if [[ "$CHANNEL" == "release" ]]; 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
for VERSION_TAG in "nightly-$DATE" nightly; do
build alpine "$VERSION_TAG"
build debian "$VERSION_TAG"
build distroless-static "$VERSION_TAG"
build distroless-libc "$VERSION_TAG"
done
elif [[ "$CHANNEL" == "custom" ]]; then
build alpine "$VERSION"
build debian "$VERSION"
build distroless-static "$VERSION"
build distroless-libc "$VERSION"
elif [[ "$CHANNEL" == "test" ]]; then
build "${BASE:-"alpine"}" "${TAG:-"test"}"
build "${BASE:-"distroless-libc"}" "${TAG:-"test"}"
build "${BASE:-"distroless-static"}" "${TAG:-"test"}"
fi