Skip to content

Commit

Permalink
docker-compose binary generator
Browse files Browse the repository at this point in the history
  • Loading branch information
ubnt-marc-khouri committed May 11, 2018
1 parent 0faf34b commit 70b56a8
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 2 deletions.
48 changes: 48 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Dockerfile to build docker-compose for aarch64
FROM arm64v8/python:3.6.5-stretch

# Add env
ENV LANG C.UTF-8

# Enable cross-build for aarch64
COPY ./vendor/qemu-bin /usr/bin/
RUN [ "cross-build-start" ]

# Set the versions
ENV DOCKER_COMPOSE_VER 1.21.2
# docker-compose requires pyinstaller 3.3.1 (check github.com/docker/compose/requirements-build.txt)
# If this changes, you may need to modify the version of "six" below
ENV PYINSTALLER_VER 3.3.1
# "six" is needed for PyInstaller. v1.11.0 is the latest as of PyInstaller 3.3.1
ENV SIX_VER 1.11.0

# Install dependencies
# RUN apt-get update && apt-get install -y
RUN pip install six==$SIX_VER

# Compile the pyinstaller "bootloader"
# https://pyinstaller.readthedocs.io/en/stable/bootloader-building.html
WORKDIR /build/pyinstallerbootloader
RUN curl -fsSL https://github.com/pyinstaller/pyinstaller/releases/download/v$PYINSTALLER_VER/PyInstaller-$PYINSTALLER_VER.tar.gz | tar xvz >/dev/null \
&& cd PyInstaller*/bootloader \
&& python3 ./waf all

# Clone docker-compose
WORKDIR /build/dockercompose
RUN git clone https://github.com/docker/compose.git . \
&& git checkout $DOCKER_COMPOSE_VER

# Run the build steps (taken from github.com/docker/compose/script/build/linux-entrypoint)
RUN mkdir ./dist \
&& pip install -q -r requirements.txt -r requirements-build.txt \
&& ./script/build/write-git-sha \
&& pyinstaller docker-compose.spec \
&& mv dist/docker-compose ./docker-compose-$(uname -s)-$(uname -m)

# Disable cross-build for aarch64
# Note: don't disable this, since we want to run this container on x86_64, not aarch64
# RUN [ "cross-build-end" ]

# Copy out the generated binary
VOLUME /dist
CMD cp docker-compose-* /dist
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,14 @@
# docker-compose-aarch64
generate a docker-compose binary for aarch64 / arm64
# docker-compose binaries for aarch64

This repository contains helpers to build a docker-compose binary for aarch64/arm64. This project exists because, currently, docker-compose [releases](https://github.com/docker/compose/releases) do not include an aarch64 binary.

## To build

You may wish to edit the docker-compose version inside the Dockerfile. Then:

```bash
docker build . -t docker-compose-aarch64-builder
docker run --rm -v "$(pwd)":/dist docker-compose-aarch64-builder
# this will generate a `docker-compose-Linux-aarch64` in "$(pwd)"
```

54 changes: 54 additions & 0 deletions vendor/get-qemu-bin.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/bash
# Script to generate a qemu binary for an arm64 target
set -euo pipefail

# Set the target platform
#TARGET="arm"
TARGET="arm64"

# Get the destination
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
DEST="$SCRIPT_DIR/qemu-bin/"

# Empty out the destination
rm -r "$DEST" || true

# Clone the resin patcher
cd "$(mktemp -d)"
git clone --depth 1 https://github.com/resin-io-projects/armv7hf-debian-qemu.git
cd armv7hf-debian-qemu

# Clean out the stuff we're about to build, then copy over the rest
rm bin/qemu-arm-static
md5 bin/resin-xbuild
rm bin/resin-xbuild
cp -a bin/ "$DEST"

# Build the binary and copy it over
# TBH, I don't know why we need to rebuild this binary... After a lot of experimentation,
# I found out that the binary shipped with the git repo (as of Apr 11 2018, Latest commit d4a214f on Jul 2, 2017)
# doesn't work in an aarch64 host. ?????
GOOS=linux GOARCH=amd64 ./build.sh
cp resin-xbuild "$DEST"

# Get qemu
case "$TARGET" in
"arm64")
curl -L https://github.com/resin-io/qemu/releases/download/v2.9.0%2Bresin1/qemu-2.9.0.resin1-aarch64.tar.gz | tar xzf -
;;
"arm")
curl -L https://github.com/resin-io/qemu/releases/download/v2.9.0%2Bresin1/qemu-2.9.0.resin1-arm.tar.gz | tar xzf -
;;
*)
echo "Unknown target $TARGET"
exit 1
;;
esac

# Copy qemu
cp qemu*/* "$DEST"

echo -e "\n\n"
echo "================================"
echo "Successfully built for $TARGET!"
echo "================================"
1 change: 1 addition & 0 deletions vendor/qemu-bin/cross-build-end
1 change: 1 addition & 0 deletions vendor/qemu-bin/cross-build-start
Binary file added vendor/qemu-bin/qemu-aarch64-static
Binary file not shown.
Binary file added vendor/qemu-bin/resin-xbuild
Binary file not shown.
1 change: 1 addition & 0 deletions vendor/qemu-bin/sh.real

0 comments on commit 70b56a8

Please sign in to comment.