-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.sh
executable file
·65 lines (52 loc) · 1.53 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
64
65
#!/bin/bash
# Uses docker buildx and https://github.com/estesp/manifest-tool
ACTION=$@
MANIFEST_TOOL=manifest-tool
export TAG=$(git rev-parse --short HEAD)
export VERSION=$(git describe --abbrev=0 --tags)
export MAJOR=$(git describe --abbrev=0 --tags | cut -d '.' -f1)
export REGISTRY=${REGISTRY:-"rakwireless/lorawan-bacnet-bridge"}
export BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
# Check we have buildx extension for docker
docker buildx version &> /dev/null
if [[ $? -ne 0 ]]; then
echo "ERROR: docker or docker buildx extension are not installed"
exit 1
fi
if [ "$ACTION" == "--push" ]; then
# Check we have the manifest modifier tool
hash $MANIFEST_TOOL &> /dev/null
if [[ $? -ne 0 ]]; then
echo "ERROR: $MANIFEST_TOOL could not be found!"
exit 1
fi
# Ask confirmation if pushing to a registry
echo "Pushing image into $REGISTRY"
echo "Tags: $MAJOR, $VERSION, $TAG, latest"
read -r -p "Are you sure? [y/N] " response
if [[ ! "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then
echo "Cancelled"
exit 1
fi
fi
# Building
time docker buildx bake $ACTION
# Merge individual archs into the same tags
if [ "$ACTION" == "--push" ]; then
MANIFEST=manifest.yaml
cat > $MANIFEST << EOL
image: $REGISTRY:$TAG
tags: ['$VERSION', '$MAJOR', 'latest']
manifests:
- image: $REGISTRY:aarch64-latest
platform:
architecture: arm64
os: linux
- image: $REGISTRY:amd64-latest
platform:
architecture: amd64
os: linux
EOL
$MANIFEST_TOOL push from-spec $MANIFEST
rm $MANIFEST
fi