From 605ca74c0ec30d3982a8aefc8a87e8b8292f9537 Mon Sep 17 00:00:00 2001 From: Florian Kinder Date: Thu, 2 May 2019 17:28:20 +0200 Subject: [PATCH] Add travis ci, linter, merge shellcheck, fix some issues (#241) * Quote all vars, remove useless echo/sub-shell, add shebands, fail on unset vars, enable pipefail, formatting * Add CI including linting via hadolint nad shellcheck * Update all base images to tag 3.9 * Switch to maintainer labels * Quote vars * Remove commented code * Ignore if the folder exists --- .hadolint.yaml | 14 ++++++++++++++ .travis.yml | 35 +++++++++++++++++++++++++++++++++++ 0.14/Dockerfile | 6 +++--- 0.14/docker-entrypoint.sh | 2 +- 0.15/Dockerfile | 6 +++--- 0.16/Dockerfile | 4 ++-- 0.17/Dockerfile | 2 +- build.sh | 12 ++++++++++++ lint.sh | 2 ++ 9 files changed, 73 insertions(+), 10 deletions(-) create mode 100644 .hadolint.yaml create mode 100644 .travis.yml create mode 100755 build.sh create mode 100755 lint.sh diff --git a/.hadolint.yaml b/.hadolint.yaml new file mode 100644 index 0000000..4801b95 --- /dev/null +++ b/.hadolint.yaml @@ -0,0 +1,14 @@ +ignored: + # ignore apt version pinning + - DL3008 + # ignore pip version pinning + - DL3013 + # ignore apk version pinning + - DL3018 + # ignore pipefail cause Balena/resin.io images do not work with it + - DL4006 + # ignore false positive regex + - SC1083 + - SC2086 + # ignore as need for debug + - SC2005 diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..2d533b3 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,35 @@ +dist: xenial +sudo: required +language: bash +services: + - docker +addons: + apt: + packages: + - jq + +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} + - bash -c 'shopt -s globstar; shellcheck **/*.sh' + - &build + stage: build + env: VERSION=0.17 + 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 + env: VERSION=0.16 + - <<: *build + env: VERSION=0.15 + - <<: *build + env: VERSION=0.14 diff --git a/0.14/Dockerfile b/0.14/Dockerfile index b536cb5..1a9d07f 100644 --- a/0.14/Dockerfile +++ b/0.14/Dockerfile @@ -1,11 +1,11 @@ -FROM frolvlad/alpine-glibc:alpine-3.4 +FROM frolvlad/alpine-glibc:alpine-3.9 -MAINTAINER https://github.com/dtandersen/docker_factorio_server +LABEL maintainer="https://github.com/dtandersen/docker_factorio_server" ENV VERSION=0.14.23 \ SHA1=6ef84341c6fc1cf45cfdd6acc8468aaa117b9e8a -RUN mkdir /opt && \ +RUN mkdir -p /opt && \ apk --no-cache add curl tini pwgen && \ curl -sSL https://www.factorio.com/get-download/$VERSION/headless/linux64 \ -o /tmp/factorio_headless_x64_$VERSION.tar.gz && \ diff --git a/0.14/docker-entrypoint.sh b/0.14/docker-entrypoint.sh index 5f8f3d5..dba48b1 100755 --- a/0.14/docker-entrypoint.sh +++ b/0.14/docker-entrypoint.sh @@ -30,6 +30,6 @@ fi exec /opt/factorio/bin/x64/factorio \ --port 34197 \ --start-server-load-latest \ - --server-settings $CONFIG/server-settings.json \ + --server-settings "$CONFIG/server-settings.json" \ --rcon-port 27015 \ --rcon-password "$(cat "$CONFIG/rconpw")" diff --git a/0.15/Dockerfile b/0.15/Dockerfile index a2c8c73..381e12d 100644 --- a/0.15/Dockerfile +++ b/0.15/Dockerfile @@ -1,13 +1,13 @@ -FROM frolvlad/alpine-glibc:alpine-3.6 +FROM frolvlad/alpine-glibc:alpine-3.9 -MAINTAINER https://github.com/dtandersen/docker_factorio_server +LABEL maintainer="https://github.com/dtandersen/docker_factorio_server" ENV PORT=34197 \ RCON_PORT=27015 \ VERSION=0.15.40 \ SHA1=f79a975f6b8c0ee87e2fa60f7d1f7133f332c3ec -RUN mkdir /opt && \ +RUN mkdir -p /opt && \ apk add --update --no-cache tini pwgen && \ apk add --update --no-cache --virtual .build-deps curl && \ curl -sSL https://www.factorio.com/get-download/$VERSION/headless/linux64 \ diff --git a/0.16/Dockerfile b/0.16/Dockerfile index 3516201..a4bd2ec 100644 --- a/0.16/Dockerfile +++ b/0.16/Dockerfile @@ -1,6 +1,6 @@ -FROM frolvlad/alpine-glibc:alpine-3.7 +FROM frolvlad/alpine-glibc:alpine-3.9 -MAINTAINER https://github.com/dtandersen/docker_factorio_server +LABEL maintainer="https://github.com/dtandersen/docker_factorio_server" ARG USER=factorio ARG GROUP=factorio diff --git a/0.17/Dockerfile b/0.17/Dockerfile index 986028d..868f890 100644 --- a/0.17/Dockerfile +++ b/0.17/Dockerfile @@ -1,6 +1,6 @@ FROM frolvlad/alpine-glibc:alpine-3.9 -MAINTAINER https://github.com/dtandersen/docker_factorio_server +LABEL maintainer="https://github.com/dtandersen/docker_factorio_server" ARG USER=factorio ARG GROUP=factorio diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..0c5ddba --- /dev/null +++ b/build.sh @@ -0,0 +1,12 @@ +#!/bin/bash +set -eo pipefail + +if [ -z "$1" ] ; then + echo "Usage: ./build.sh \$VERSION" +else + VERSION="$1" +fi + +cd "$VERSION" || exit + +docker build . -t "factoriotools/docker_factorio_server:$VERSION" diff --git a/lint.sh b/lint.sh new file mode 100755 index 0000000..261d377 --- /dev/null +++ b/lint.sh @@ -0,0 +1,2 @@ +#!/bin/bash +git ls-files --exclude='*Dockerfile' --ignored | xargs --max-lines=1 ./hadolint