-
Notifications
You must be signed in to change notification settings - Fork 9
/
build
executable file
·75 lines (57 loc) · 2.34 KB
/
build
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
#!/bin/bash
# this is the preferred approach for building cross-platform
# images, over the `build-parallel` script, which builds all platforms at same time.
# it's best to build each arch image separately, then combine them,
# because if a build crashes you lose the cached progress.
# BUT this has been having problems with docker desktop crashing etc on windows.
#. get default version from package.json? use jq to extract?
repo_root="$(dirname "$(dirname "$(dirname "$(realpath "$0")")")")"
usage="
Usage: l99 build SERVICE
Build a multiplatform Docker image and push up to Docker hub.
Version is set in .l99_version file.
SERVICE service name - adapter, meter, relay, etc.
Might need to login to Docker Hub first, in order to push image there -
docker login --username ladder99 # password as in bitlocker.com
Example
l99 build adapter
"
# show help if count of params is zero
if [ $# -eq 0 ]; then
echo "$usage"
exit
fi
SERVICE=$1
# VERSION=$2
VERSION="$(cat "$repo_root/.l99_version")"
# note: arm/v7 is 32bit for older pi's
# need arm64/v8 ?
# PLATFORMS=${3:-"amd64 arm64"}
USERNAME=ladder99
# create a multiplatform buildx builder
# do this each time, per answer by guy with 200k rep in 2022-02 -
# The easy button is to use the binaries from the multiarch image. This is good in
# CI if you have a dedicated VM (less ideal if you are modifying the host used by
# other builds). However if you reboot, it breaks until you run the container again.
# And it requires you to remember to update it for any upstream patches.
# So I wouldn't recommend it for a long running build host.
# from https://stackoverflow.com/questions/60080264/docker-cannot-build-multi-platform-images-with-docker-buildx
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
docker buildx rm l99builder
docker buildx create --name l99builder --driver docker-container --use
docker buildx inspect --bootstrap
echo "Version is" $VERSION
for arch in amd64 arm64 ; do
echo "Building image for" $arch
docker buildx build \
--platform linux/$arch \
--output type=docker \
--tag $USERNAME/$SERVICE:$VERSION-${arch} \
"$repo_root/services/$SERVICE"
done
echo "Combining images and pushing to Docker Hub..."
docker buildx build \
--platform linux/amd64,linux/arm64 \
--tag $USERNAME/$SERVICE:$VERSION \
--push \
"$repo_root/services/$SERVICE"