2019-05-02 17:28:20 +02:00
|
|
|
#!/bin/bash
|
2019-05-16 19:23:07 +02:00
|
|
|
set -eox pipefail
|
2019-05-02 17:28:20 +02:00
|
|
|
|
2019-05-16 19:23:07 +02:00
|
|
|
if [ -z "$1" ]; then
|
|
|
|
echo "Usage: ./build.sh \$VERSION_SHORT"
|
2019-05-02 17:28:20 +02:00
|
|
|
else
|
2019-05-16 19:23:07 +02:00
|
|
|
VERSION_SHORT="$1"
|
2019-05-02 17:28:20 +02:00
|
|
|
fi
|
|
|
|
|
2019-05-16 19:23:07 +02:00
|
|
|
VERSION=$(grep -oP '[0-9]+\.[0-9]+\.[0-9]+' "$VERSION_SHORT/Dockerfile" | head -1)
|
|
|
|
DOCKER_REPO=factoriotools/docker_factorio_server
|
|
|
|
cd "$VERSION_SHORT" || exit
|
2019-05-02 17:28:20 +02:00
|
|
|
|
2019-05-16 19:23:07 +02:00
|
|
|
if [ "$TRAVIS_PULL_REQUEST" == "true" ]; then
|
|
|
|
TAG="$TRAVIS_PULL_REQUEST_SLUG"
|
|
|
|
else
|
|
|
|
if [ "$TRAVIS_BRANCH" == "master" ]; then
|
|
|
|
TAG="$VERSION -t $DOCKER_REPO:$VERSION_SHORT"
|
|
|
|
else
|
|
|
|
TAG="$TRAVIS_BRANCH"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$EXTRA_TAG" ]; then
|
|
|
|
TAG="$TAG -t $DOCKER_REPO:$EXTRA_TAG"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# shellcheck disable=SC2086
|
|
|
|
docker build . -t $DOCKER_REPO:$TAG
|
|
|
|
|
|
|
|
docker images
|
2019-05-16 19:43:44 +02:00
|
|
|
if [[ "$(dirname "$(git diff --name-only HEAD^)")" =~ $VERSION ]] && [ "$TRAVIS_BRANCH" == "master" ]; then
|
2019-05-16 19:39:23 +02:00
|
|
|
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
|
2019-05-16 19:23:07 +02:00
|
|
|
docker push "$DOCKER_REPO:latest"
|
|
|
|
|
|
|
|
if [ -n "$EXTRA_TAG" ]; then
|
|
|
|
docker push "$DOCKER_REPO:$EXTRA_TAG"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$TRAVIS_TAG" ]; then
|
|
|
|
docker push "$DOCKER_REPO:$VERSION"
|
|
|
|
docker push "$DOCKER_REPO:$VERSION_SHORT"
|
|
|
|
fi
|
|
|
|
|
|
|
|
curl -X POST https://hooks.microbadger.com/images/factoriotools/factorio/TmmKGNp8jKcFqZvcJhTCIAJVluw=
|
|
|
|
fi
|