From 82d837b963560bbb1c4205aed35bb562f6c33c8a Mon Sep 17 00:00:00 2001 From: asonix Date: Sat, 21 Mar 2020 20:29:59 -0500 Subject: [PATCH] Add container build script --- .gitignore | 1 + Dockerfile.arm64v8 | 30 ++++++++++++++++++++++++++++ build.sh | 50 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+) create mode 100644 Dockerfile.arm64v8 create mode 100755 build.sh diff --git a/.gitignore b/.gitignore index ea8c4bf..d6b374c 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /target +/artifacts diff --git a/Dockerfile.arm64v8 b/Dockerfile.arm64v8 new file mode 100644 index 0000000..f0ace77 --- /dev/null +++ b/Dockerfile.arm64v8 @@ -0,0 +1,30 @@ +FROM arm64v8/alpine:3.11.3 AS build + +COPY relay /relay + +RUN \ + apk add binutils && \ + strip /relay + +FROM arm64v8/alpine:3.11.3 + +ARG UID=991 +ARG GID=991 + +RUN \ + apk add tini && \ + echo "Etc/UTC" > /etc/localtime && \ + mkdir -p /opt/relay && \ + addgroup --gid $GID relay && \ + adduser -D -u $UID -G relay -h /opt/relay relay && \ + echo "relay:`head /dev/urandom | tr -dc A-Za-z0-9 | head -c 24 | mkpasswd -s -m sha-256`" | chpasswd && \ + chown -R relay:relay /opt/relay + +COPY --from=build /relay /usr/bin/relay + +USER relay + +EXPOSE 8080 + +ENTRYPOINT ["/sbin/tini", "--"] +CMD ["relay"] diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..54c5945 --- /dev/null +++ b/build.sh @@ -0,0 +1,50 @@ +#!/usr/bin/env bash + +BUILD_DATE=$(date) +VERSION=$1 + +function require() { + if [ "$1" = "" ]; then + echo "input '$2' required" + print_help + exit 1 + fi +} + +function print_help() { + echo "build.sh" + echo "" + echo "Usage:" + echo " build.sh [version]" + echo "" + echo "Args:" + echo " version: The version of the current container" +} + +require "$VERSION" "version" + +set -xe + +# from `cargo install cross` +cross build \ + --target aarch64-unknown-linux-musl \ + --release + +mkdir -p artifacts +cp ./target/aarch64-unknown-linux-musl/release/relay artifacts/relay + +# from `sudo docker run --rm --privileged multiarch/qemu-user-static --reset -p yes` +docker build \ + --pull \ + --no-cache \ + --build-arg BUILD_DATE="${BUILD_DATE}" \ + --build-arg TAG="${TAG}" \ + -f "Dockerfile.arm64v8" \ + -t "asonix/relay:${VERSION}-arm64v8" \ + -t "asonix/relay:latest-arm64v8" \ + -t "asonix/relay:latest" \ + ./artifacts + +docker push "asonix/relay:${VERSION}-arm64v8" +docker push "asonix/relay:latest-arm64v8" +docker push "asonix/relay:latest"