2019-11-18 20:33:15 +03:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
set -e
|
|
|
|
cd $(dirname "${BASH_SOURCE[0]}")/..
|
|
|
|
|
2020-11-04 00:36:07 +03:00
|
|
|
# GIT_BRANCH is the current branch name
|
|
|
|
export GIT_BRANCH=$(git branch --show-current)
|
2019-11-18 20:33:15 +03:00
|
|
|
# GIT_VERSION - always the last verison number, like 1.12.1.
|
2023-05-04 10:39:21 +03:00
|
|
|
export GIT_VERSION=$(git describe --tags --abbrev=0)
|
2019-11-18 20:33:15 +03:00
|
|
|
# GIT_COMMIT_SHORT - the short git commit number, like a718ef0.
|
|
|
|
export GIT_COMMIT_SHORT=$(git rev-parse --short HEAD)
|
|
|
|
# DOCKER_REPO - the base repository name to push the docker build to.
|
|
|
|
export DOCKER_REPO=$DOCKER_USER/tile38
|
|
|
|
|
2020-11-04 00:36:07 +03:00
|
|
|
if [ "$GIT_BRANCH" != "master" ]; then
|
2019-11-18 20:33:15 +03:00
|
|
|
echo "Not pushing, not on master"
|
2020-11-04 00:36:07 +03:00
|
|
|
elif [ "$DOCKER_USER" == "" ]; then
|
2023-05-04 10:39:21 +03:00
|
|
|
echo "Not pushing, DOCKER_USER not set"
|
2020-11-04 00:36:07 +03:00
|
|
|
exit 1
|
|
|
|
elif [ "$DOCKER_LOGIN" == "" ]; then
|
2023-05-04 10:39:21 +03:00
|
|
|
echo "Not pushing, DOCKER_LOGIN not set"
|
2020-11-04 00:36:07 +03:00
|
|
|
exit 1
|
|
|
|
elif [ "$DOCKER_PASSWORD" == "" ]; then
|
|
|
|
echo "Not pushing, DOCKER_PASSWORD not set"
|
|
|
|
exit 1
|
2023-05-04 10:39:21 +03:00
|
|
|
else
|
2023-05-03 12:02:40 +03:00
|
|
|
# setup cross platform builder
|
|
|
|
# https://github.com/tonistiigi/binfmt
|
|
|
|
docker run --privileged --rm tonistiigi/binfmt --install all
|
|
|
|
docker buildx create --name multiarch --platform linux/amd64,linux/amd64/v2,linux/amd64/v3,linux/arm64,linux/386,linux/arm/v7 --use default
|
|
|
|
|
2019-11-18 20:33:15 +03:00
|
|
|
# docker login
|
|
|
|
echo $DOCKER_PASSWORD | docker login -u $DOCKER_LOGIN --password-stdin
|
|
|
|
if [ "$(curl -s https://hub.docker.com/v2/repositories/$DOCKER_REPO/tags/$GIT_VERSION/ | grep "digest")" == "" ]; then
|
2023-05-03 12:02:40 +03:00
|
|
|
# build the docker image
|
|
|
|
docker buildx build \
|
|
|
|
-f Dockerfile \
|
|
|
|
--platform linux/arm64,linux/amd64 \
|
|
|
|
--build-arg VERSION=$GIT_VERSION \
|
|
|
|
--tag $DOCKER_REPO:$GIT_VERSION \
|
|
|
|
--tag $DOCKER_REPO:latest \
|
|
|
|
--tag $DOCKER_REPO:edge \
|
|
|
|
--push \
|
|
|
|
.
|
|
|
|
else
|
|
|
|
# build the docker image
|
|
|
|
docker buildx build \
|
|
|
|
-f Dockerfile \
|
|
|
|
--platform linux/arm64,linux/amd64 \
|
|
|
|
--build-arg VERSION=$GIT_VERSION \
|
|
|
|
--tag $DOCKER_REPO:edge \
|
|
|
|
--push \
|
|
|
|
.
|
2019-11-18 20:33:15 +03:00
|
|
|
fi
|
2023-05-03 12:02:40 +03:00
|
|
|
fi
|