diff --git a/dimension/Dockerfile b/dimension/Dockerfile new file mode 100644 index 0000000..0f63e47 --- /dev/null +++ b/dimension/Dockerfile @@ -0,0 +1,55 @@ +ARG ARCH=amd64 + +FROM $ARCH/alpine:3.14 as builder + +ARG TAG +ARG UID=991 +ARG GID=991 + +RUN \ + addgroup -g "${GID}" build && \ + adduser -D -G build -u "${UID}" -g "" -h /opt/build build && \ + apk add \ + g++ \ + gcc \ + git \ + make \ + musl-dev \ + nodejs \ + npm \ + python3 + +USER build +WORKDIR /opt/build + +RUN \ + git clone https://github.com/turt2live/matrix-dimension.git matrix-dimension + +WORKDIR /opt/build/matrix-dimension + +RUN \ + git checkout $TAG && \ + rm -r .git && \ + npm install && \ + npm run build + +FROM $ARCH/alpine:3.14 + +ARG UID=991 +ARG GID=991 + +RUN \ + addgroup -g "${GID}" app && \ + adduser -D -G app -u "${UID}" -g "" -h /opt/app app && \ + apk add nodejs npm tini + +USER app + +COPY --from=builder /opt/build/matrix-dimension /opt/app/matrix-dimension + +WORKDIR /opt/app/matrix-dimension + +ENV NODE_ENV=production + +ENTRYPOINT ["/sbin/tini", "--"] +CMD ["npm", "run", "start:app"] diff --git a/dimension/build.sh b/dimension/build.sh new file mode 100755 index 0000000..0bd9947 --- /dev/null +++ b/dimension/build.sh @@ -0,0 +1,99 @@ +#!/usr/bin/env bash + +function require() { + if [ "$1" = "" ]; then + echo "input '$2' required" + print_help + exit 1 + fi +} + +function print_help() { + echo "deploy.sh" + echo "" + echo "Usage:" + echo " deploy.sh [tag] [push]" + echo "" + echo "Args:" + echo " tag: The git tag to be applied to the repository and docker build" + echo " push: Whether or not to push the image" + echo "" + echo "Examples:" + echo " ./deploy.sh v0.2.0-r0 main true" + echo " ./deploy.sh v0.2.0-r0 asonix/shell-out" +} + +REPO=dimension + +function build_image() { + tag=$1 + arch=$2 + push=$3 + + sudo docker build \ + --pull \ + --build-arg TAG=$tag \ + --build-arg ARCH=$arch \ + -t asonix/$REPO:$arch-$tag \ + -f Dockerfile \ + . + + sudo docker tag \ + asonix/$REPO:$arch-$tag \ + asonix/$REPO:$arch-latest + + if [ "$push" == "true" ]; then + sudo docker push asonix/$REPO:$arch-$tag + sudo docker push asonix/$REPO:$arch-latest + fi +} + +function manifest() { + tag=$1 + push=$2 + + sudo docker manifest create asonix/$REPO:$TAG \ + -a asonix/$REPO:arm64v8-$tag \ + -a asonix/$REPO:amd64-$tag + + sudo docker manifest annotate asonix/$REPO:$tag \ + asonix/$REPO:arm64v8-$Tag --os linux --arch arm64 --variant v8 + + # sudo docker manifest annotate asonix/$REPO:$tag \ + # asonix/$REPO:arm32v7-$tag --os linux --arch arm --variant v7 + + sudo docker manifest annotate asonix/$REPO:$tag \ + asonix/$REPO:amd64-$tag --os linux --arch amd64 + + if [ "$push" == "true" ]; then + sudo docker manifest push asonix/$REPO:$tag --purge + fi +} + +# Creating the new tag +tag="$1" +push=${2:-false} + +require "$tag" "tag" +require "$push" "push" + +if ! sudo docker run --rm -it arm64v8/alpine:3.14 /bin/sh -c 'echo "docker is configured correctly"' +then + echo "docker is not configured to run on qemu-emulated architectures, fixing will require sudo" + sudo docker run --rm --privileged multiarch/qemu-user-static --reset -p yes +fi + +set -xe + +# Build for arm64v8, arm32v7 and amd64 +build_image $tag arm64v8 $push +# build_image $tag arm32v7 $push +build_image $tag amd64 $push + +# Build for other archs +# TODO + +if [ "$push" == "true" ]; then + manifest $tag $push + manifest latest $push +fi