Commit 81aa1690 authored by noplanman's avatar noplanman

Initial commit.

parents
ARG BORG_ARCH
FROM resin/${BORG_ARCH}-python:3.6-slim
ARG BORG_ARCH
ARG BORG_VERSION=1.1.7
ENV BORG_DIR /borg
ENV BORG_BUILD_DIR ${BORG_DIR}/dist
WORKDIR ${BORG_DIR}
# install dev requirements
RUN set -ex; \
apt-get update; \
apt-get install -y --no-install-recommends \
build-essential git \
fuse libfuse-dev pkg-config \
libssl-dev libacl1-dev \
zlib1g-dev liblz4-dev; \
rm -rf /var/lib/apt/lists/*;
# install borg + dependencies
RUN set -ex; \
git clone https://github.com/borgbackup/borg.git .; \
git checkout ${BORG_VERSION}; \
pip install --upgrade pip;
RUN set -ex; pip install -r requirements.d/development.txt;
RUN set -ex; pip install -r requirements.d/fuse.txt;
RUN set -ex; pip install -e .;
# create standalone binary
RUN set -ex; \
pip install pyinstaller; \
pyinstaller --log-level DEBUG -F -n borg-${BORG_ARCH} src/borg/__main__.py;
RUN ln -s "${BORG_BUILD_DIR}/borg-${BORG_ARCH}" /usr/bin/borg
# Borg Binary Builder
Build [BorgBackup] binaries on any platform, for any architecture, using docker.
## Usage
### Build image
`./build.sh <arch> [<version>]`
See the [list of available architectures] ([on GitHub][available-architectures-github])
*Examples:*
- Build version `1.1.7` for `aarch64`
`./build.sh aarch64 1.1.7`
- Build version `1.1.5` for Raspberry Pi 3
`./build.sh raspberrypi3 1.1.5`
### Extract borg binary
`./extract.sh <arch> [<binary_save_location>]`
**Note:** This will overwrite the file at `binary_save_location` if it already exists!
*Examples:*
- Extract borg binary for `aarch64` to `borg-aarch64` in current folder
`./extract.sh aarch64 borg-aarch64`
- Extract borg binary for Raspberry Pi 3 to `/homes/lemoi/borg`
`./extract.sh raspberrypi3 /homes/lemoi/borg`
## How this works
### Build
The `build.sh` script downloads the appropriate starter docker image that contains the necessary QEMU binary for building and registers it in the build agent.
For more details, check the [Hypriot blog post] that explains it in more depth.
Then, the docker image is built for the requested architecture.
This is basically done by following the flow of setting up a [BorgBackup development environment] and [creating the standalone binary]. (For more info on this, just have a look at the `Dockerfile`)
### Extract
The `extract.sh` script extracts the built binary from the image created using `build.sh`.
This basically starts a container from the built image for your selected architecture and writes the binary out to the file path you passed as a parameter.
[BorgBackup]: https://github.com/borgbackup/borg/ "BorgBackup on GitHub"
[BorgBackup development environment]: https://borgbackup.readthedocs.io/en/stable/development.html#building-a-development-environment "BorgBackup development environment"
[creating the standalone binary]: https://borgbackup.readthedocs.io/en/stable/development.html#creating-standalone-binaries "Create standalone binary"
[list of available architectures]: https://docs.resin.io/reference/base-images/base-images/ "List of available Architectures"
[available-architectures-github]: https://github.com/resin-io-library/base-images/tree/master/python "List of available Architectures on GitHub"
[Hypriot blog post]: https://blog.hypriot.com/post/setup-simple-ci-pipeline-for-arm-images/ "Setup a simple CI pipeline to build Docker images for ARM"
#!/usr/bin/env bash
# Usage: ./build.sh <arch> [<version>]
# For available architectures see:
# https://docs.resin.io/reference/base-images/base-images/
BORG_ARCH=${1}
BORG_VERSION=${2:-1.1.7}
if [ -z "${BORG_ARCH}" ]; then
echo "Usage: ./build.sh <arch> [<version>]";
echo "- No arch provided -";
exit 1;
fi
echo "Building BorgBackup ${BORG_VERSION} for ${BORG_ARCH}"
# 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}" \
-t "borg:${BORG_ARCH}" .
#!/usr/bin/env bash
# Usage: ./extract.sh <arch> [<binary_save_location>]
BORG_ARCH=${1:-aarch64}
BORG_BINARY=${2:-borg-${BORG_ARCH}}
#if [[ "$(docker images -q "borg:${BORG_ARCH}" 2> /dev/null)" == "" ]]; then
if ! docker inspect "borg:${BORG_ARCH}" >/dev/null 2>&1; then
echo "Couldn't find the 'borg:${BORG_ARCH}' image!"
echo "Create the image first, using './build.sh ${BORG_ARCH}'"
exit 1
fi
#docker run -v "${PWD}":"/opt/mount" --rm --entrypoint \
# cp "borg:${BORG_ARCH}" "/usr/bin/borg" "/opt/mount/${BORG_BINARY}"
docker run --rm --entrypoint cat "borg:${BORG_ARCH}" /usr/bin/borg > "${BORG_BINARY}"
chmod +x "${BORG_BINARY}"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment