diff --git a/docker/prod/build-image.sh b/docker/prod/build-image.sh deleted file mode 100755 index 003ece1..0000000 --- a/docker/prod/build-image.sh +++ /dev/null @@ -1,45 +0,0 @@ -#!/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 [repo] [tag] [arch]" - echo "" - echo "Args:" - echo " repo: The docker repository to publish the image" - echo " tag: The tag applied to the docker image" - echo " arch: The architecuture of the doker image" -} - -function build() { - REPO=$1 - ARCH=$2 - TAG=$3 - - sudo docker build \ - --pull \ - --build-arg TAG=$TAG \ - --build-arg ARCH_REPO=$ARCH \ - -t $REPO:$ARCH-$TAG \ - -f Dockerfile \ - . -} - -REPO=$1 -TAG=$2 -ARCH=$3 - -require "$REPO" "repo" -require "$TAG" "tag" -require "$ARCH" "arch" - -build "$REPO" "$ARCH" "$TAG" diff --git a/docker/prod/build.sh b/docker/prod/build.sh index 168a456..a19d22f 100755 --- a/docker/prod/build.sh +++ b/docker/prod/build.sh @@ -25,24 +25,74 @@ function print_help() { } function build_image() { - tag=$1 - arch=$2 - push=$3 + repo=$1 + tag=$2 + arch=$3 + push=$4 - ./build-image.sh asonix/rust-builder $tag $arch + sudo docker build \ + --pull \ + --build-arg TAG=$tag \ + --build-arg ARCH_REPO=$arch \ + -t $repo:$arch-$tag \ + -f Dockerfile \ + . - sudo docker tag asonix/rust-builder:$arch-$tag asonix/rust-builder:$arch-latest + sudo docker tag asonix/$repo:$arch-$tag asonix/$repo:$arch-latest if [ "$push" == "true" ]; then - sudo docker push asonix/rust-builder:$arch-$tag - sudo docker push asonix/rust-builder:$arch-latest + sudo docker push asonix/$repo:$arch-$tag + sudo docker push asonix/$repo:$arch-latest fi } +function copy_binary() { + repo=$1 + arch=$2 + + mkdir -p artifacts/ + + sudo docker run \ + --rm -it \ + -v "${pwd}/artifacts:/mnt" \ + asonix/$repo:latest-$arch \ + cp /opt/build/binary /mnt/${repo}-${arch} +} + +function push_manifest() { + repo=$1 + tag=$2 + + sudo docker manifest create asonix/$REPO:$TAG \ + -a asonix/$REPO:arm64v8-$TAG \ + -a asonix/$REPO:arm32v7-$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 + + sudo docker manifest push asonix/$REPO:$TAG --purge +} + # Creating the new tag +repo=wg-mon new_tag="$1" branch="$2" -push=$3 +push="${3:-false}" require "$new_tag" "tag" require "$branch" "branch" @@ -63,11 +113,15 @@ git tag $new_tag git push origin $new_tag git push -build_image $new_tag arm64v8 $push -build_image $new_tag arm32v7 $push -build_image $new_tag amd64 $push +build_image $repo $new_tag arm64v8 $push +build_image $repo $new_tag arm32v7 $push +build_image $repo $new_tag amd64 $push + +copy_binary $repo arm64v8 +copy_binary $repo arm32v7 +copy_binary $repo amd64 if [ "$push" == "true" ]; then - ./manifest.sh rust-builder $new_tag - ./manifest.sh rust-builder latest + push_manifest $repo $new_tag + push_manifest $repo latest fi diff --git a/docker/prod/manifest.sh b/docker/prod/manifest.sh deleted file mode 100755 index d426a97..0000000 --- a/docker/prod/manifest.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/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 " manifest.sh [repo] [tag]" - echo "" - echo "Args:" - echo " repo: The docker repository to update" - echo " tag: The git tag to be applied to the image manifest" -} - -REPO=$1 -TAG=$2 - -require "$REPO" "repo" -require "$TAG" "tag" - -set -xe - -sudo docker manifest create asonix/$REPO:$TAG \ - -a asonix/$REPO:arm64v8-$TAG \ - -a asonix/$REPO:arm32v7-$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 - -sudo docker manifest push asonix/$REPO:$TAG --purge