2019-05-02 17:28:20 +02:00
|
|
|
#!/bin/bash
|
2019-07-06 16:17:03 +02:00
|
|
|
set -eoux pipefail
|
2019-05-02 17:28:20 +02:00
|
|
|
|
2019-07-06 16:46:56 +02:00
|
|
|
if [[ -z ${1:-} ]] && [[ -n ${CI:-} ]]; then
|
2019-10-18 10:51:06 +02:00
|
|
|
echo 'Usage: ./build.sh $VERSION_SHORT'
|
2019-05-18 13:26:04 +02:00
|
|
|
exit 1
|
2019-07-06 16:46:56 +02:00
|
|
|
elif [[ $CI == true ]]; then
|
2019-05-16 19:23:07 +02:00
|
|
|
VERSION_SHORT="$1"
|
2019-05-18 13:26:04 +02:00
|
|
|
else
|
2019-07-06 16:46:56 +02:00
|
|
|
VERSION_SHORT=$(find . -maxdepth 1 -type d | sort | tail -1 | grep -o "[[0-9]].[[0-9]]*")
|
2019-05-18 13:26:04 +02:00
|
|
|
EXTRA_TAG=latest
|
2019-05-02 17:28:20 +02:00
|
|
|
fi
|
|
|
|
|
2019-07-06 16:46:56 +02:00
|
|
|
cd "$VERSION_SHORT" || exit 1
|
2019-05-02 17:28:20 +02:00
|
|
|
|
2019-05-18 13:26:04 +02:00
|
|
|
VERSION=$(grep -oP '[0-9]+\.[0-9]+\.[0-9]+' Dockerfile | head -1)
|
|
|
|
DOCKER_REPO=factoriotools/factorio
|
|
|
|
|
2019-07-06 16:46:56 +02:00
|
|
|
if [[ $TRAVIS_PULL_REQUEST == true ]]; then
|
2019-05-18 13:26:04 +02:00
|
|
|
TAGS="$DOCKER_REPO:$TRAVIS_PULL_REQUEST_SLUG"
|
2019-05-16 19:23:07 +02:00
|
|
|
else
|
2019-07-06 16:46:56 +02:00
|
|
|
# we are either on master or on a tag build
|
|
|
|
if [[ $TRAVIS_BRANCH == master ]] || [[ $TRAVIS_BRANCH == "$VERSION" ]]; then
|
2019-05-18 13:26:04 +02:00
|
|
|
TAGS="$DOCKER_REPO:$VERSION -t $DOCKER_REPO:$VERSION_SHORT"
|
2019-07-06 16:46:56 +02:00
|
|
|
# we are on an incremental build of a tag
|
2019-07-06 17:26:15 +02:00
|
|
|
elif [[ $VERSION == "${TRAVIS_BRANCH%-*}" ]]; then
|
2019-07-06 16:46:56 +02:00
|
|
|
TAGS="$DOCKER_REPO:$TRAVIS_BRANCH -t $DOCKER_REPO:$VERSION -t $DOCKER_REPO:$VERSION_SHORT"
|
|
|
|
# we build a other branch than master
|
|
|
|
elif [[ -n $TRAVIS_BRANCH ]]; then
|
2019-05-18 13:26:04 +02:00
|
|
|
TAGS="$DOCKER_REPO:$TRAVIS_BRANCH"
|
2019-07-06 16:46:56 +02:00
|
|
|
# we are not in CI and tag version and version short
|
|
|
|
elif [[ $CI == "" ]]; then
|
2019-05-18 13:26:04 +02:00
|
|
|
TAGS="$DOCKER_REPO:$VERSION -t $DOCKER_REPO:$VERSION_SHORT"
|
2019-05-16 19:23:07 +02:00
|
|
|
fi
|
|
|
|
|
2019-07-06 16:56:59 +02:00
|
|
|
if [[ -n ${EXTRA_TAG:-} ]]; then
|
2019-10-18 10:50:25 +02:00
|
|
|
IFS=","
|
|
|
|
for TAG in $EXTRA_TAG; do
|
|
|
|
TAGS="$TAGS -t $DOCKER_REPO:$EXTRA_TAG"
|
|
|
|
done
|
2019-05-16 19:23:07 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2019-10-18 10:51:06 +02:00
|
|
|
docker build . -t "${TAGS[@]}"
|
2019-05-16 19:23:07 +02:00
|
|
|
docker images
|
|
|
|
|
2019-07-06 16:46:56 +02:00
|
|
|
# only push when:
|
|
|
|
# latest changes where made in the folder corosponding to the version we build, we are on master and don#t build a PR.
|
|
|
|
if [[ $(dirname "$(git diff --name-only HEAD^)") =~ $VERSION_SHORT ]] && [[ $TRAVIS_BRANCH == master ]] && [[ $TRAVIS_PULL_REQUEST_BRANCH == "" ]] ||
|
|
|
|
# we build a tag and we are not on master
|
2019-07-06 17:18:58 +02:00
|
|
|
[[ $VERSION == "${TRAVIS_BRANCH%-*}" ]] && [[ $TRAVIS_PULL_REQUEST_BRANCH == "" ]] ||
|
2019-07-06 16:46:56 +02:00
|
|
|
# we are not in CI
|
|
|
|
[[ $CI == "" ]]; then
|
2019-05-18 13:40:25 +02:00
|
|
|
|
2019-07-06 16:46:56 +02:00
|
|
|
if [[ $CI == true ]]; then
|
2019-05-18 13:26:04 +02:00
|
|
|
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
|
2019-05-16 19:23:07 +02:00
|
|
|
fi
|
|
|
|
|
2019-07-06 16:46:56 +02:00
|
|
|
# push a tag on a branch other than master
|
2019-07-06 17:18:58 +02:00
|
|
|
if [[ -n $TRAVIS_BRANCH ]] && [[ $VERSION != "${TRAVIS_BRANCH%-*}" ]] && [[ $TRAVIS_BRANCH != "master" ]]; then
|
2019-05-18 13:26:04 +02:00
|
|
|
docker push "$DOCKER_REPO:$TRAVIS_BRANCH"
|
|
|
|
fi
|
2019-07-06 16:46:56 +02:00
|
|
|
|
|
|
|
# push an incremental tag
|
2019-07-06 17:32:35 +02:00
|
|
|
if [[ $VERSION == "${TRAVIS_BRANCH%-*}" ]]; then
|
2019-07-06 16:46:56 +02:00
|
|
|
docker push "$DOCKER_REPO:$TRAVIS_BRANCH"
|
|
|
|
fi
|
|
|
|
|
2019-07-06 16:56:59 +02:00
|
|
|
if [[ -n $TRAVIS_TAG ]] || [[ $CI == "" ]]; then
|
2019-05-16 19:23:07 +02:00
|
|
|
docker push "$DOCKER_REPO:$VERSION"
|
|
|
|
docker push "$DOCKER_REPO:$VERSION_SHORT"
|
|
|
|
fi
|
2019-07-06 16:46:56 +02:00
|
|
|
|
2019-07-06 16:56:59 +02:00
|
|
|
if [[ -n ${EXTRA_TAG:-} ]]; then
|
2019-10-18 10:50:25 +02:00
|
|
|
IFS=","
|
|
|
|
for TAG in $EXTRA_TAG; do
|
|
|
|
docker push "$DOCKER_REPO:$TAG"
|
|
|
|
done
|
2019-05-18 13:26:04 +02:00
|
|
|
fi
|
2019-05-16 19:23:07 +02:00
|
|
|
|
|
|
|
curl -X POST https://hooks.microbadger.com/images/factoriotools/factorio/TmmKGNp8jKcFqZvcJhTCIAJVluw=
|
|
|
|
fi
|