forked from balena-io-experimental/browser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-images.sh
57 lines (43 loc) · 2.22 KB
/
build-images.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
#!/bin/bash
set -e
BLOCK_NAME="browser"
function build_image () {
local DOCKER_REPO=$1
local BALENA_MACHINE_NAME=$2
local DOCKER_ARCH=$3
echo "Building for machine name $BALENA_MACHINE_NAME, platform $DOCKER_ARCH, pushing to $DOCKER_REPO/$BLOCK_NAME"
# The RPIs all use the same dockerfile for now
if [[ $BALENA_MACHINE_NAME = raspberry* ]]; then
sed "s/%%BALENA_MACHINE_NAME%%/$BALENA_MACHINE_NAME/g" ./Dockerfile.raspberrypi > ./Dockerfile.$BALENA_MACHINE_NAME
else
sed "s/%%BALENA_MACHINE_NAME%%/$BALENA_MACHINE_NAME/g" ./Dockerfile.template > ./Dockerfile.$BALENA_MACHINE_NAME
fi
docker buildx build -t $DOCKER_REPO/$BLOCK_NAME:$BALENA_MACHINE_NAME --push --platform $DOCKER_ARCH --file Dockerfile.$BALENA_MACHINE_NAME .
echo "Cleaning up temporary dockerfiles..."
rm Dockerfile.$BALENA_MACHINE_NAME
}
function retag_image () {
local DOCKER_REPO=$1
local BUILT_TAG=$2
local NEW_TAG=$3
echo "Taging $DOCKER_REPO/$BLOCK_NAME:$BUILT_TAG as $DOCKER_REPO/$BLOCK_NAME:$NEW_TAG"
docker tag $DOCKER_REPO/$BLOCK_NAME:$BUILT_TAG $DOCKER_REPO/$BLOCK_NAME:$NEW_TAG
# echo "Publishing..."
docker push $DOCKER_REPO/$BLOCK_NAME:$NEW_TAG
}
function create_and_push_manifest() {
local DOCKER_REPO=$1
docker manifest rm $DOCKER_REPO/$BLOCK_NAME:latest || true
docker manifest create $DOCKER_REPO/$BLOCK_NAME:latest --amend $DOCKER_REPO/$BLOCK_NAME:raspberrypi3 --amend $DOCKER_REPO/$BLOCK_NAME:raspberrypi4-64 --amend $DOCKER_REPO/$BLOCK_NAME:genericx86-64-ext
docker manifest annotate --arch arm64 $DOCKER_REPO/$BLOCK_NAME:latest $DOCKER_REPO/$BLOCK_NAME:raspberrypi4-64
docker manifest annotate --variant v8 $DOCKER_REPO/$BLOCK_NAME:latest $DOCKER_REPO/$BLOCK_NAME:raspberrypi4-64
docker manifest push $DOCKER_REPO/$BLOCK_NAME:latest
}
# YOu can pass in a repo (such as a test docker repo) or accept the default
DOCKER_REPO=${1:-balenablocks}
#only need to build once per arch, and retag & push for clones
build_image $DOCKER_REPO "raspberrypi3" "linux/arm/v7"
#RPI4 is built as ARMv7 because there are currently (jan 2021) no 64-bit chromium sources from RPI
retag_image $DOCKER_REPO "raspberrypi3" "raspberrypi4-64"
build_image $DOCKER_REPO "genericx86-64-ext" "linux/amd64"
create_and_push_manifest $DOCKER_REPO