build.sh 1.15 KB
Newer Older
noplanman's avatar
noplanman committed
1
#!/usr/bin/env sh
noplanman's avatar
noplanman committed
2 3 4 5

# Usage: ./build.sh <arch> [<version>]

# For available architectures see:
6
# https://www.balena.io/docs/reference/base-images/base-images/#balena-base-images
noplanman's avatar
noplanman committed
7

8 9
set -ex

noplanman's avatar
noplanman committed
10
BORG_ARCH=${1}
11
BORG_VERSION=${2:-1.1.14}
noplanman's avatar
noplanman committed
12 13 14

if [ -z "${BORG_ARCH}" ]; then
    echo "Usage: ./build.sh <arch> [<version>]";
noplanman's avatar
noplanman committed
15
    echo "No arch provided";
noplanman's avatar
noplanman committed
16 17 18
    exit 1;
fi

19 20 21 22 23 24 25 26
DOCKER_FILE=Dockerfile
# For building the hot binary, make use of the prebuilt base docker image to speed things up.
# Note: Only a limited number of architectures are supported, check here:
#       https://hub.docker.com/r/noplanman/borg-binary-builder/tags/
if [ ! -z "${BBB_HOT}" ]; then
    DOCKER_FILE=Dockerfile.hot
fi

27
DOCKER_IMAGE=borg:${BORG_VERSION}-${BORG_ARCH}
28
echo "Building ${DOCKER_IMAGE}"
noplanman's avatar
noplanman committed
29 30 31 32 33 34 35

# https://blog.hypriot.com/post/setup-simple-ci-pipeline-for-arm-images/
docker run --rm --privileged multiarch/qemu-user-static:register --reset

docker build \
    --build-arg "BORG_ARCH=${BORG_ARCH}" \
    --build-arg "BORG_VERSION=${BORG_VERSION}" \
36 37
    -t "${DOCKER_IMAGE}" \
    -f "${DOCKER_FILE}" .
38

39
# Output built borg binary version to ensure the binary works.
40
docker run --rm "${DOCKER_IMAGE}" borg --version