From 1eb9ef0361b2e5227a1f417b9339f309103f5c53 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Fri, 31 Jul 2020 20:17:14 +0200 Subject: [PATCH 1/5] Moved docker image build to github actions --- .github/workflows/docker-image-build.yml | 22 +++++++++++++++++++ .travis.yml | 9 -------- data/infra/ci/install-docker.sh | 12 ----------- docker/build | 27 +++++++++--------------- 4 files changed, 32 insertions(+), 38 deletions(-) create mode 100644 .github/workflows/docker-image-build.yml delete mode 100755 data/infra/ci/install-docker.sh diff --git a/.github/workflows/docker-image-build.yml b/.github/workflows/docker-image-build.yml new file mode 100644 index 00000000..84bfc16d --- /dev/null +++ b/.github/workflows/docker-image-build.yml @@ -0,0 +1,22 @@ +name: Build docker image + +on: + push: + branches: + - develop + tags: + - * + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Install buildx + id: buildx + uses: crazy-max/ghaction-docker-buildx@v1 + with: + version: latest + - name: Build the image + run: bash ./docker/build diff --git a/.travis.yml b/.travis.yml index e2d901d1..c36f9984 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,14 +18,6 @@ jobs: allow_failures: - php: 'nightly' include: - - name: "Docker publish" - if: NOT type = pull_request - # Overwrite all common steps that have to be different - before_install: echo "Before install" - install: sudo ./data/infra/ci/install-docker.sh - before_script: echo "Before script" - script: bash ./docker/build - after_success: echo "After success" - name: "CI - 8.0" php: 'nightly' env: @@ -47,7 +39,6 @@ jobs: on: tags: true -# Common steps for all jobs before_install: - echo 'extension = apcu.so' >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini - phpenv config-rm xdebug.ini || return 0 diff --git a/data/infra/ci/install-docker.sh b/data/infra/ci/install-docker.sh deleted file mode 100755 index 58289a16..00000000 --- a/data/infra/ci/install-docker.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env bash - -set -ex - -# install latest docker version -curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - -add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" -apt-get update -apt-get -y -o Dpkg::Options::="--force-confnew" install docker-ce - -# enable multiarch execution -docker run --rm --privileged multiarch/qemu-user-static --reset -p yes diff --git a/docker/build b/docker/build index a2855fdf..95386811 100755 --- a/docker/build +++ b/docker/build @@ -2,33 +2,26 @@ set -e -# PLATFORMS="linux/arm/v7,linux/arm64/v8,linux/amd64" -PLATFORMS="linux/amd64" +PLATFORMS="linux/arm/v7,linux/arm64/v8,linux/amd64" +# PLATFORMS="linux/amd64" DOCKER_IMAGE="shlinkio/shlink" -BUILDX_VER=v0.4.1 -export DOCKER_CLI_EXPERIMENTAL=enabled - -mkdir -vp ~/.docker/cli-plugins/ ~/dockercache -curl --silent -L "https://github.com/docker/buildx/releases/download/${BUILDX_VER}/buildx-${BUILDX_VER}.linux-amd64" > ~/.docker/cli-plugins/docker-buildx -chmod a+x ~/.docker/cli-plugins/docker-buildx - -docker buildx create --use echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin +echo "Building version $GITHUB_REF" -# If there is a tag, regardless the branch, build that docker tag and also "stable" -if [[ ! -z $TRAVIS_TAG ]]; then - TAGS="-t ${DOCKER_IMAGE}:${TRAVIS_TAG#?}" +# If ref is not develop, then this is a tag. Build that docker tag and also "stable" +if [[ "$GITHUB_REF" != *"develop"* ]]; then + TAGS="-t ${DOCKER_IMAGE}:${GITHUB_REF#?}" # Push stable tag only if this is not an alpha or beta tag - [[ $TRAVIS_TAG != *"alpha"* && $TRAVIS_TAG != *"beta"* ]] && TAGS="${TAGS} -t ${DOCKER_IMAGE}:stable" + [[ $GITHUB_REF != *"alpha"* && $GITHUB_REF != *"beta"* ]] && TAGS="${TAGS} -t ${DOCKER_IMAGE}:stable" docker buildx build --push \ - --build-arg SHLINK_VERSION=${TRAVIS_TAG#?} \ + --build-arg SHLINK_VERSION=${GITHUB_REF#?} \ --platform ${PLATFORMS} \ ${TAGS} . -# If build branch is develop, build latest (on main branch, when there's no tag, do not build anything) -elif [[ "$TRAVIS_BRANCH" == 'develop' ]]; then +# If build branch is develop, build latest +elif [[ "$GITHUB_REF" == *"develop"* ]]; then docker buildx build --push \ --platform ${PLATFORMS} \ -t ${DOCKER_IMAGE}:latest . From 53bbcd34a60e3fcdafab10f6b87d628629149865 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Fri, 31 Jul 2020 20:19:46 +0200 Subject: [PATCH 2/5] Replaced built image by lab one while testing functionality --- docker/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/build b/docker/build index 95386811..82efb8d4 100755 --- a/docker/build +++ b/docker/build @@ -4,7 +4,7 @@ set -e PLATFORMS="linux/arm/v7,linux/arm64/v8,linux/amd64" # PLATFORMS="linux/amd64" -DOCKER_IMAGE="shlinkio/shlink" +DOCKER_IMAGE="shlinkio/lab" echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin echo "Building version $GITHUB_REF" From 977af0ee436bdc667b8efc61e5f232a77e25dac4 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Fri, 31 Jul 2020 20:24:44 +0200 Subject: [PATCH 3/5] Fixed pattern for tags on github action --- .github/workflows/docker-image-build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker-image-build.yml b/.github/workflows/docker-image-build.yml index 84bfc16d..202b8902 100644 --- a/.github/workflows/docker-image-build.yml +++ b/.github/workflows/docker-image-build.yml @@ -5,7 +5,7 @@ on: branches: - develop tags: - - * + - 'v*' jobs: build: From a32651aab3ea96be6902c27a38d8649bb3b8b1ad Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Fri, 31 Jul 2020 20:30:30 +0200 Subject: [PATCH 4/5] Replace -u by --username on docker login command --- .github/workflows/docker-image-build.yml | 2 +- docker/build | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/docker-image-build.yml b/.github/workflows/docker-image-build.yml index 202b8902..1c2baf4e 100644 --- a/.github/workflows/docker-image-build.yml +++ b/.github/workflows/docker-image-build.yml @@ -17,6 +17,6 @@ jobs: id: buildx uses: crazy-max/ghaction-docker-buildx@v1 with: - version: latest + buildx-version: latest - name: Build the image run: bash ./docker/build diff --git a/docker/build b/docker/build index 82efb8d4..a8cb1c90 100755 --- a/docker/build +++ b/docker/build @@ -6,8 +6,7 @@ PLATFORMS="linux/arm/v7,linux/arm64/v8,linux/amd64" # PLATFORMS="linux/amd64" DOCKER_IMAGE="shlinkio/lab" -echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin -echo "Building version $GITHUB_REF" +echo "$DOCKER_PASSWORD" | docker login --username "$DOCKER_USERNAME" --password-stdin # If ref is not develop, then this is a tag. Build that docker tag and also "stable" if [[ "$GITHUB_REF" != *"develop"* ]]; then From a7a69506a0c97ce9cfb39061ec03d1d8b111c269 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Fri, 31 Jul 2020 20:37:14 +0200 Subject: [PATCH 5/5] Fixed how docker credentials are read from secrets --- .github/workflows/docker-image-build.yml | 2 ++ docker/build | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docker-image-build.yml b/.github/workflows/docker-image-build.yml index 1c2baf4e..64ccaa17 100644 --- a/.github/workflows/docker-image-build.yml +++ b/.github/workflows/docker-image-build.yml @@ -18,5 +18,7 @@ jobs: uses: crazy-max/ghaction-docker-buildx@v1 with: buildx-version: latest + - name: Login to docker hub + run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin - name: Build the image run: bash ./docker/build diff --git a/docker/build b/docker/build index a8cb1c90..0302d607 100755 --- a/docker/build +++ b/docker/build @@ -6,8 +6,6 @@ PLATFORMS="linux/arm/v7,linux/arm64/v8,linux/amd64" # PLATFORMS="linux/amd64" DOCKER_IMAGE="shlinkio/lab" -echo "$DOCKER_PASSWORD" | docker login --username "$DOCKER_USERNAME" --password-stdin - # If ref is not develop, then this is a tag. Build that docker tag and also "stable" if [[ "$GITHUB_REF" != *"develop"* ]]; then TAGS="-t ${DOCKER_IMAGE}:${GITHUB_REF#?}"