relay/docker/prod/deploy.sh

88 lines
2 KiB
Bash
Raw Normal View History

2020-06-10 22:45:59 +00:00
#!/usr/bin/env bash
function require() {
if [ "$1" = "" ]; then
echo "input '$2' required"
print_help
exit 1
fi
}
function print_help() {
2021-09-20 17:56:14 +00:00
echo "deploy.sh"
2020-06-10 22:45:59 +00:00
echo ""
echo "Usage:"
2021-09-20 17:56:14 +00:00
echo " deploy.sh [tag] [branch] [push]"
2020-06-10 22:45:59 +00:00
echo ""
echo "Args:"
2021-09-20 17:56:14 +00:00
echo " tag: The git tag to be applied to the repository and docker build"
echo " branch: The git branch to use for tagging and publishing"
echo " push: Whether or not to push the image"
echo ""
echo "Examples:"
echo " ./deploy.sh v0.3.0-alpha.13 main true"
echo " ./deploy.sh v0.3.0-alpha.13-shell-out asonix/shell-out false"
2020-06-10 22:45:59 +00:00
}
function build_image() {
2021-09-20 17:56:14 +00:00
tag=$1
arch=$2
push=$3
./build-image.sh asonix/relay $tag $arch
sudo docker tag asonix/relay:$arch-$tag asonix/relay:$arch-latest
if [ "$push" == "true" ]; then
sudo docker push asonix/relay:$arch-$tag
sudo docker push asonix/relay:$arch-latest
fi
2020-06-10 22:45:59 +00:00
}
2021-09-20 17:56:14 +00:00
# Creating the new tag
new_tag="$1"
branch="$2"
push=$3
2020-06-10 22:45:59 +00:00
2021-09-20 17:56:14 +00:00
require "$new_tag" "tag"
require "$branch" "branch"
require "$push" "push"
if ! sudo docker run --rm -it arm64v8/alpine:3.11 /bin/sh -c 'echo "docker is configured correctly"'
then
echo "docker is not configured to run on qemu-emulated architectures, fixing will require sudo"
2020-06-10 22:45:59 +00:00
sudo docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
fi
set -xe
2021-09-20 17:56:14 +00:00
git checkout $branch
# Changing the docker-compose prod
sed -i "s/asonix\/relay:.*/asonix\/relay:$new_tag/" docker-compose.yml
git add ../prod/docker-compose.yml
# The commit
git commit -m"Version $new_tag"
git tag $new_tag
2020-06-10 22:45:59 +00:00
2021-09-20 17:56:14 +00:00
# Push
git push origin $new_tag
2020-06-10 22:45:59 +00:00
git push
2021-09-20 17:56:14 +00:00
# Build for arm64v8, arm32v7 and amd64
build_image $new_tag arm64v8 $push
build_image $new_tag arm32v7 $push
build_image $new_tag amd64 $push
# Build for other archs
# TODO
2020-06-10 22:45:59 +00:00
2021-09-20 17:56:14 +00:00
if [ "$push" == "true" ]; then
./manifest.sh relay $new_tag
./manifest.sh relay latest
# pushd ../../
# cargo publish
# popd
fi