mirror of
https://github.com/factoriotools/factorio-docker.git
synced 2024-11-07 03:07:24 +01:00
parent
fd7b8cd839
commit
4afbed52c8
50
build.sh
50
build.sh
@ -1,33 +1,39 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -eoux pipefail
|
set -eoux pipefail
|
||||||
|
|
||||||
if [ -z "$1" ] && [ -n "$CI" ]; then
|
if [[ -z ${1:-} ]] && [[ -n ${CI:-} ]]; then
|
||||||
echo "Usage: ./build.sh \$VERSION_SHORT"
|
echo "Usage: ./build.sh \$VERSION_SHORT"
|
||||||
exit 1
|
exit 1
|
||||||
elif [ "$CI" == "true" ]; then
|
elif [[ $CI == true ]]; then
|
||||||
VERSION_SHORT="$1"
|
VERSION_SHORT="$1"
|
||||||
else
|
else
|
||||||
VERSION_SHORT=$(find . -maxdepth 1 -type d | sort | tail -1 | grep -o "[0-9].[0-9]*")
|
VERSION_SHORT=$(find . -maxdepth 1 -type d | sort | tail -1 | grep -o "[[0-9]].[[0-9]]*")
|
||||||
EXTRA_TAG=latest
|
EXTRA_TAG=latest
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cd "$VERSION_SHORT" || exit
|
cd "$VERSION_SHORT" || exit 1
|
||||||
|
|
||||||
VERSION=$(grep -oP '[0-9]+\.[0-9]+\.[0-9]+' Dockerfile | head -1)
|
VERSION=$(grep -oP '[0-9]+\.[0-9]+\.[0-9]+' Dockerfile | head -1)
|
||||||
DOCKER_REPO=factoriotools/factorio
|
DOCKER_REPO=factoriotools/factorio
|
||||||
|
|
||||||
if [ "$TRAVIS_PULL_REQUEST" == "true" ]; then
|
if [[ $TRAVIS_PULL_REQUEST == true ]]; then
|
||||||
TAGS="$DOCKER_REPO:$TRAVIS_PULL_REQUEST_SLUG"
|
TAGS="$DOCKER_REPO:$TRAVIS_PULL_REQUEST_SLUG"
|
||||||
else
|
else
|
||||||
if [ "$TRAVIS_BRANCH" == "master" ] || [ "$TRAVIS_BRANCH" == "$VERSION" ]; then
|
# we are either on master or on a tag build
|
||||||
|
if [[ $TRAVIS_BRANCH == master ]] || [[ $TRAVIS_BRANCH == "$VERSION" ]]; then
|
||||||
TAGS="$DOCKER_REPO:$VERSION -t $DOCKER_REPO:$VERSION_SHORT"
|
TAGS="$DOCKER_REPO:$VERSION -t $DOCKER_REPO:$VERSION_SHORT"
|
||||||
elif [ -n "$TRAVIS_BRANCH" ]; then
|
# we are on an incremental build of a tag
|
||||||
|
elif [[ $TRAVIS_BRANCH == "${VERSION%-*}" ]]; then
|
||||||
|
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
|
||||||
TAGS="$DOCKER_REPO:$TRAVIS_BRANCH"
|
TAGS="$DOCKER_REPO:$TRAVIS_BRANCH"
|
||||||
elif [ "$CI" == "" ]; then
|
# we are not in CI and tag version and version short
|
||||||
|
elif [[ $CI == "" ]]; then
|
||||||
TAGS="$DOCKER_REPO:$VERSION -t $DOCKER_REPO:$VERSION_SHORT"
|
TAGS="$DOCKER_REPO:$VERSION -t $DOCKER_REPO:$VERSION_SHORT"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "$EXTRA_TAG" ]; then
|
if [[ -n $EXTRA_TAG ]]; then
|
||||||
TAGS="$TAGS -t $DOCKER_REPO:$EXTRA_TAG"
|
TAGS="$TAGS -t $DOCKER_REPO:$EXTRA_TAG"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@ -36,22 +42,34 @@ fi
|
|||||||
docker build . -t $TAGS
|
docker build . -t $TAGS
|
||||||
docker images
|
docker images
|
||||||
|
|
||||||
if [[ "$(dirname "$(git diff --name-only HEAD^)")" =~ $VERSION_SHORT ]] && [ "$TRAVIS_BRANCH" == "master" ] && [ "$TRAVIS_PULL_REQUEST_BRANCH" == "" ] ||
|
# only push when:
|
||||||
[ "$TRAVIS_BRANCH" == "$VERSION" ] && [ "$TRAVIS_PULL_REQUEST_BRANCH" == "" ] ||
|
# latest changes where made in the folder corosponding to the version we build, we are on master and don#t build a PR.
|
||||||
[ "$CI" == "" ]; then
|
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
|
||||||
|
[[ $TRAVIS_BRANCH == "${VERSION%-*}" ]] && [[ $TRAVIS_PULL_REQUEST_BRANCH == "" ]] ||
|
||||||
|
# we are not in CI
|
||||||
|
[[ $CI == "" ]]; then
|
||||||
|
|
||||||
if [ "$CI" == "true" ]; then
|
if [[ $CI == true ]]; then
|
||||||
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
|
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "$TRAVIS_BRANCH" ] && [ "$TRAVIS_BRANCH" != "$VERSION" ] && [ "$TRAVIS_BRANCH" != "master" ]; then
|
# push a tag on a branch other than master
|
||||||
|
if [[ -n "$TRAVIS_BRANCH" ]] && [[ "$TRAVIS_BRANCH" != "${VERSION%-*}" ]] && [[ "$TRAVIS_BRANCH" != "master" ]]; then
|
||||||
docker push "$DOCKER_REPO:$TRAVIS_BRANCH"
|
docker push "$DOCKER_REPO:$TRAVIS_BRANCH"
|
||||||
fi
|
fi
|
||||||
if [ -n "$TRAVIS_TAG" ] || [ "$CI" == "" ]; then
|
|
||||||
|
# push an incremental tag
|
||||||
|
if [[ "$TRAVIS_BRANCH" != "${VERSION%-*}" ]]; then
|
||||||
|
docker push "$DOCKER_REPO:$TRAVIS_BRANCH"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -n "$TRAVIS_TAG" ]] || [[ "$CI" == "" ]]; then
|
||||||
docker push "$DOCKER_REPO:$VERSION"
|
docker push "$DOCKER_REPO:$VERSION"
|
||||||
docker push "$DOCKER_REPO:$VERSION_SHORT"
|
docker push "$DOCKER_REPO:$VERSION_SHORT"
|
||||||
fi
|
fi
|
||||||
if [ -n "$EXTRA_TAG" ]; then
|
|
||||||
|
if [[ -n "$EXTRA_TAG" ]]; then
|
||||||
docker push "$DOCKER_REPO:$EXTRA_TAG"
|
docker push "$DOCKER_REPO:$EXTRA_TAG"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user