-
Notifications
You must be signed in to change notification settings - Fork 11
/
build.sh
executable file
·63 lines (53 loc) · 1.61 KB
/
build.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
#!/bin/bash
set -o errexit -o nounset -o pipefail
v="$(head -n 1 VERSION)"
v="${v}-$(date '+%Y%m%d')-$(git rev-parse --short HEAD)"
t=${IMAGE_TAG:-}
if [[ -n "$t" ]]; then
v=$t
fi
echo "version=${v}"
image="${DOCKER_REGISTRY}/erda-fluent-bit:${v}"
echo "image: ${image}"
platforms=${PLATFORMS:-"linux/amd64,linux/arm64"}
echo "platforms: ${platforms}"
function local_build_func() {
docker login -u "${DOCKER_REGISTRY_USERNAME}" -p "${DOCKER_REGISTRY_PASSWORD}" "${DOCKER_REGISTRY}"
docker buildx create --use
docker buildx build --platform ${platforms} -t "${image}" \
--label "branch=$(git rev-parse --abbrev-ref HEAD)" \
--label "commit=$(git rev-parse HEAD)" \
--label "build-time=$(date '+%Y-%m-%d %T%z')" \
--push \
-f dockerfiles/Dockerfile .
}
function k8s_build_func() {
docker login -u "${DOCKER_REGISTRY_USERNAME}" -p "${DOCKER_REGISTRY_PASSWORD}" "${DOCKER_REGISTRY}"
buildctl --addr tcp://buildkitd.default.svc.cluster.local:1234 \
--tlscacert=/.buildkit/ca.pem \
--tlscert=/.buildkit/cert.pem \
--tlskey=/.buildkit/key.pem \
build \
--frontend dockerfile.v0 \
--opt platform=${platforms} \
--local context=/.pipeline/container/context/fluent-bit \
--local dockerfile=/.pipeline/container/context/fluent-bit/dockerfiles \
--output type=image,name=${image},push=true
echo "image=${image}" >> $METAFILE
}
# switch by local or k8s
local_build=${LOCAL_BUILD:-"false"}
case $local_build in
"true")
echo "local build"
local_build_func
;;
"false")
echo "k8s build"
k8s_build_func
;;
*)
echo "unknown build"
exit 1
;;
esac