diff --git a/.travis.yml b/.travis.yml index 2d533b3..3c2b681 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,25 +11,17 @@ addons: jobs: include: - stage: test - env: HADOLINT=${HOME}/hadolint - install: curl -sLo ${HADOLINT} $(curl -s https://api.github.com/repos/hadolint/hadolint/releases/latest?access_token=${GITHUB_TOKEN} | jq -r '.assets | .[] | select(.name=="hadolint-Linux-x86_64") | .browser_download_url') - && chmod 700 ${HADOLINT} script: - - git ls-files --exclude='*Dockerfile' --ignored | xargs --max-lines=1 ${HADOLINT} + - git ls-files --exclude='*Dockerfile' --ignored | xargs --max-lines=1 -I{} sh -c 'docker run --rm -i -v ${PWD}/.hadolint.yaml:/.hadolint.yaml hadolint/hadolint < "$1"' -- {} - bash -c 'shopt -s globstar; shellcheck **/*.sh' - &build stage: build - env: VERSION=0.17 + env: VERSION_SHORT=0.17 EXTRA_TAG=latest script: - - ./build.sh $VERSION - after_success: - - if [ "$TRAVIS_BRANCH" == "master" ]; then - echo "$DOCKER_PASSWORD" | DOCKER login -u "$DOCKER_USERNAME" --password-stdin - docker push "factoriotools/docker_factorio_server:$VERSION" - fi + - ./build.sh $VERSION_SHORT - <<: *build - env: VERSION=0.16 + env: VERSION_SHORT=0.16 EXTRA_TAG=stable - <<: *build - env: VERSION=0.15 + env: VERSION_SHORT=0.15 - <<: *build - env: VERSION=0.14 + env: VERSION_SHORT=0.14 diff --git a/0.17/files/docker-entrypoint.sh b/0.17/files/docker-entrypoint.sh index 19253be..aab4386 100755 --- a/0.17/files/docker-entrypoint.sh +++ b/0.17/files/docker-entrypoint.sh @@ -30,7 +30,7 @@ if [ ! -f "$CONFIG/map-settings.json" ]; then fi NRTMPSAVES=$( find -L "$SAVES" -iname \*.tmp.zip -mindepth 1 | wc -l ) -if [ $NRTMPSAVES -gt 0 ]; then +if [ "$NRTMPSAVES" -gt 0 ]; then # Delete incomplete saves (such as after a forced exit) rm -f "$SAVES/*.tmp.zip" fi @@ -48,7 +48,7 @@ else fi NRSAVES=$( find -L "$SAVES" -iname \*.zip -mindepth 1 | wc -l ) -if [ $NRSAVES -eq 0 ]; then +if [ "$NRSAVES" -eq 0 ]; then # Generate a new map if no save ZIPs exist $SU_EXEC /opt/factorio/bin/x64/factorio \ --create "$SAVES/_autosave1.zip" \ diff --git a/build.sh b/build.sh index 0c5ddba..1fc688e 100755 --- a/build.sh +++ b/build.sh @@ -1,12 +1,47 @@ #!/bin/bash -set -eo pipefail +set -eox pipefail -if [ -z "$1" ] ; then - echo "Usage: ./build.sh \$VERSION" +if [ -z "$1" ]; then + echo "Usage: ./build.sh \$VERSION_SHORT" else - VERSION="$1" + VERSION_SHORT="$1" fi -cd "$VERSION" || exit +VERSION=$(grep -oP '[0-9]+\.[0-9]+\.[0-9]+' "$VERSION_SHORT/Dockerfile" | head -1) +DOCKER_REPO=factoriotools/docker_factorio_server +cd "$VERSION_SHORT" || exit -docker build . -t "factoriotools/docker_factorio_server:$VERSION" +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 + +if [ "$(dirname "$(git diff --name-only HEAD^)" | head -1)" == "$VERSION" ] && [ "$TRAVIS_BRANCH" == "master" ]; then + # echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin + 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