Skip to content

Commit

Permalink
Docker multi-arch support for arm32v7/arm64v8 (#79)
Browse files Browse the repository at this point in the history
- Generate dockerfiles for arm32v7/arm64v8
- Use built binaries in release process
  • Loading branch information
shesek committed Jan 22, 2021
1 parent cec9fb0 commit fdf9702
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 15 deletions.
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ Dockerfile
stuff
scripts
.git
dist
contrib
examples
6 changes: 4 additions & 2 deletions Dockerfile → dockerfiles/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ RUN apt-get update && apt-get install -y pkg-config libssl-dev
WORKDIR /usr/src/bwt
COPY . .
ARG FEATURES=electrum,http,webhooks,track-spends
RUN cargo install --locked --path . --no-default-features --features "cli,$FEATURES"
ARG PREBUILT_BIN
RUN if [ -n "$PREBUILT_BIN" ]; then cp $PREBUILT_BIN /usr/local/bin; \
else cargo install --locked --path . --root /usr/local/ --no-default-features --features "cli,$FEATURES"; fi

# debian:buster-slim
FROM debian@sha256:59678da095929b237694b8cbdbe4818bb89a2918204da7fa0145dc4ba5ef22f9
ARG FEATURES=electrum,http,webhooks,track-spends
RUN echo $FEATURES | grep -v webhooks > /dev/null || (apt-get update && apt-get install -y libssl-dev)
COPY --from=builder /usr/local/cargo/bin/bwt /usr/local/bin/
COPY --from=builder /usr/local/bin/bwt /usr/local/bin/
ENTRYPOINT [ "bwt", "--bitcoind-dir", "/bitcoin" ]
1 change: 1 addition & 0 deletions dockerfiles/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Changing the `Dockerfile` requires running `scripts/docker-generate.sh` to generate the arm32v7/arm64v8 images.
16 changes: 16 additions & 0 deletions dockerfiles/arm32v7.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# rust:1.49-slim
FROM rust@sha256:58cb29151843a8ba8e0e78e3f80096ed2f9514cf81d4f85ef43727140631e67b as builder
RUN apt-get update && apt-get install -y pkg-config libssl-dev
WORKDIR /usr/src/bwt
COPY . .
ARG FEATURES=electrum,http,webhooks,track-spends
ARG PREBUILT_BIN
RUN if [ -n "$PREBUILT_BIN" ]; then cp $PREBUILT_BIN /usr/local/bin; \
else cargo install --locked --path . --root /usr/local/ --no-default-features --features "cli,$FEATURES"; fi

# debian:buster-slim
FROM debian@sha256:d31590f680577ffde6bd08943e9590eaabdc04529ea60f4bb6f58cddbc33f628
ARG FEATURES=electrum,http,webhooks,track-spends
RUN echo $FEATURES | grep -v webhooks > /dev/null || (apt-get update && apt-get install -y libssl-dev)
COPY --from=builder /usr/local/bin/bwt /usr/local/bin/
ENTRYPOINT [ "bwt", "--bitcoind-dir", "/bitcoin" ]
16 changes: 16 additions & 0 deletions dockerfiles/arm64v8.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# rust:1.49-slim
FROM rust@sha256:2a44876432ba0cfbe7f7fcddd9b16f316ee13abecdee43b25f0645529966bc40 as builder
RUN apt-get update && apt-get install -y pkg-config libssl-dev
WORKDIR /usr/src/bwt
COPY . .
ARG FEATURES=electrum,http,webhooks,track-spends
ARG PREBUILT_BIN
RUN if [ -n "$PREBUILT_BIN" ]; then cp $PREBUILT_BIN /usr/local/bin; \
else cargo install --locked --path . --root /usr/local/ --no-default-features --features "cli,$FEATURES"; fi

# debian:buster-slim
FROM debian@sha256:01b65c2928fed9427e59a679e287a75d98551ea2061cf03c61be0c7e1fc40fef
ARG FEATURES=electrum,http,webhooks,track-spends
RUN echo $FEATURES | grep -v webhooks > /dev/null || (apt-get update && apt-get install -y libssl-dev)
COPY --from=builder /usr/local/bin/bwt /usr/local/bin/
ENTRYPOINT [ "bwt", "--bitcoind-dir", "/bitcoin" ]
23 changes: 23 additions & 0 deletions scripts/docker-generate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash
set -xeo pipefail

# Generate the arm32v7/arm64v8 dockerfiles using the main dockerfile as a template
generate_dockerfile() {
local builder_image=$1
local runtime_image=$2
sed -r "s/^(FROM rust@sha256:)[^ ]+/\1$builder_image/; s/^(FROM debian@sha256:)[^ ]+/\1$runtime_image/;" dockerfiles/Dockerfile
}

# arm32v7/rust:1.49.0-slim and arm32v7/debian:buster-slim (10.7)
# https://hub.docker.com/r/arm32v7/rust/tags?name=slim
# https://hub.docker.com/r/arm32v7/debian/tags?name=buster-slim
generate_dockerfile 58cb29151843a8ba8e0e78e3f80096ed2f9514cf81d4f85ef43727140631e67b \
d31590f680577ffde6bd08943e9590eaabdc04529ea60f4bb6f58cddbc33f628 \
> dockerfiles/arm32v7.Dockerfile

# arm64v8/rust:1.49.0-slim and arm64v8/debian:buster-slim (10.7)
# https://hub.docker.com/r/arm64v8/rust/tags?name=slim
# https://hub.docker.com/r/arm64v8/debian/tags?name=buster-slim
generate_dockerfile 2a44876432ba0cfbe7f7fcddd9b16f316ee13abecdee43b25f0645529966bc40 \
01b65c2928fed9427e59a679e287a75d98551ea2061cf03c61be0c7e1fc40fef \
> dockerfiles/arm64v8.Dockerfile
49 changes: 49 additions & 0 deletions scripts/docker-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash
set -xeo pipefail
shopt -s expand_aliases

docker_name=shesek/bwt

version=$(grep -E '^version =' Cargo.toml | cut -d'"' -f2)
base_tag=$docker_name:$version

docker_name=shesek/bwt-test
base_tag=$docker_name:$version

build_variant() {
local docker_tag=$1
local docker_alias=$2

build $1-amd64 $2-amd64 $3 "$4" x86_64-linux Dockerfile
build $1-arm32v7 $2-arm32v7 $3 "$4" arm32v7-linux arm32v7.Dockerfile
build $1-arm64v8 $2-arm64v8 $3 "$4" arm64v8-linux arm64v8.Dockerfile

# can't tag manifests to create an alias, need to create them separately instead
for target in $docker_tag $docker_alias; do
docker manifest create --amend $target $docker_tag-amd64 $docker_tag-arm32v7 $docker_tag-arm64v8
docker manifest annotate $target $docker_tag-amd64 --os linux --arch amd64
docker manifest annotate $target $docker_tag-arm32v7 --os linux --arch arm --variant v7
docker manifest annotate $target $docker_tag-arm64v8 --os linux --arch arm64 --variant v8
docker manifest push $target -p
done
}

build() {
local docker_tag=$1
local docker_alias=$2
local features=$3
local bin_variant=$4
local bin_platform=$5
local dockerfile=$6

docker build -t $docker_tag --build-arg FEATURES=$features \
--build-arg PREBUILT_BIN=dist/bwt-$version$bin_variant-$bin_platform/bwt \
-f dockerfiles/$dockerfile .

docker tag $docker_tag $docker_alias
docker push $docker_tag
docker push $docker_alias
}

build_variant $base_tag $docker_name:latest http,electrum,webhooks,track-spends ''
build_variant $base_tag-electrum $docker_name:electrum electrum '-electrum_only'
15 changes: 3 additions & 12 deletions scripts/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,8 @@ if [ -z "$SKIP_BUILD" ]; then
./scripts/build.sh
fi

# remove subdirectories, keep release tarballs
rm -r dist/*/

echo Making SHA256SUMS...
(cd dist && sha256sum *) | sort | gpg --clearsign --digest-algo sha256 > SHA256SUMS.asc
(cd dist && sha256sum *.{tar.gz,zip}) | sort | gpg --clearsign --digest-algo sha256 > SHA256SUMS.asc
fi


Expand Down Expand Up @@ -96,7 +93,7 @@ if [[ -z "$SKIP_UPLOAD" && -n "$GH_TOKEN" ]]; then
|| curl -sf -H "$gh_auth" -d "$release_opt" $gh_base/releases)
gh_upload=$(echo "$gh_release" | jq -r .upload_url | sed -e 's/{?name,label}//')

for file in SHA256SUMS.asc dist/*; do
for file in SHA256SUMS.asc dist/*.{tar.gz,zip}; do
echo ">> Uploading $file"

curl -f --progress-bar -H "$gh_auth" -H "Content-Type: application/octet-stream" \
Expand All @@ -110,11 +107,5 @@ fi

if [ -z "$SKIP_DOCKER" ]; then
echo Releasing docker images...

docker_tag=$docker_name:$version
docker build -t $docker_tag .
docker build -t $docker_tag-electrum --build-arg FEATURES=electrum .
docker tag $docker_tag $docker_name:latest
docker tag $docker_tag-electrum $docker_name:electrum
docker push $docker_name
./scripts/docker-release.sh
fi

0 comments on commit fdf9702

Please sign in to comment.