-
Notifications
You must be signed in to change notification settings - Fork 23
/
build.sh
executable file
·113 lines (91 loc) · 3.13 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
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/bin/bash
# Uses docker buildx and https://github.com/estesp/manifest-tool
# -----------------------------------------------------------------------------
# Globals
# -----------------------------------------------------------------------------
PUSH=0
TARGETS=()
MANIFEST_TOOL=manifest-tool
MANIFEST_FILE=manifest.yaml
# -----------------------------------------------------------------------------
# Check dependencies
# -----------------------------------------------------------------------------
# Check we have buildx extension for docker
if ! docker buildx version &> /dev/null; then
echo "ERROR: docker or docker buildx extension are not installed"
exit 1
fi
# Check we have the manifest modifier tool
if ! hash ${MANIFEST_TOOL} &> /dev/null; then
echo "ERROR: ${MANIFEST_TOOL} could not be found!"
exit 1
fi
# -----------------------------------------------------------------------------
# Parse arguments
# -----------------------------------------------------------------------------
while [[ $# -gt 0 ]]; do
if [[ "${1,,}" == "--push" ]]; then
PUSH=1
else
TARGETS+=( "$1" )
fi
shift
done
# -----------------------------------------------------------------------------
# Export settings for builder
# -----------------------------------------------------------------------------
TAG=$( git rev-parse --short HEAD )
VERSION=$( git describe --abbrev=0 --tags )
MAJOR=$( git describe --abbrev=0 --tags | cut -d '.' -f1 )
BUILD_DATE=$( date -u +"%Y-%m-%dT%H:%M:%SZ" )
REGISTRY=${REGISTRY:-"rakwireless/udp-packet-forwarder"}
export TAG
export VERSION
export MAJOR
export BUILD_DATE
export REGISTRY
# -----------------------------------------------------------------------------
# Ask for confirmation if pushing
# -----------------------------------------------------------------------------
if [[ ${PUSH} -eq 1 ]]; then
# 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
# -----------------------------------------------------------------------------
if [[ ${PUSH} -eq 1 ]]; then
time docker buildx bake --push "${TARGETS[@]}"
else
time docker buildx bake --load "${TARGETS[@]}"
fi
# -----------------------------------------------------------------------------
# Merge individual archs into the same tags
# -----------------------------------------------------------------------------
if [[ ${PUSH} -eq 1 ]] && [[ ${#TARGETS[@]} -eq 0 ]]; then
cat > ${MANIFEST_FILE} << EOL
image: ${REGISTRY}:${TAG}
tags: ['${VERSION}', '${MAJOR}', 'latest']
manifests:
- image: ${REGISTRY}:aarch64-latest
platform:
architecture: arm64
os: linux
- image: ${REGISTRY}:armv7hf-latest
platform:
architecture: arm
os: linux
- image: ${REGISTRY}:amd64-latest
platform:
architecture: amd64
os: linux
EOL
${MANIFEST_TOOL} push from-spec ${MANIFEST_FILE}
rm ${MANIFEST_FILE}
fi