From c6bae962a03499f2eee6bc7b60e753bbe8e80712 Mon Sep 17 00:00:00 2001 From: Andrea Spacca Date: Sat, 20 Jun 2020 20:15:24 +0200 Subject: [PATCH] ISSUE-313-BUILDX --- .github/workflows/build-docker-images.yml | 78 +++++++++++++++++++++++ .github/workflows/buildx.yml | 67 ------------------- 2 files changed, 78 insertions(+), 67 deletions(-) create mode 100644 .github/workflows/build-docker-images.yml delete mode 100644 .github/workflows/buildx.yml diff --git a/.github/workflows/build-docker-images.yml b/.github/workflows/build-docker-images.yml new file mode 100644 index 0000000..c13f156 --- /dev/null +++ b/.github/workflows/build-docker-images.yml @@ -0,0 +1,78 @@ +name: Deploy multi-architecture Docker images for transfer.sh with buildx + +on: + schedule: + - cron: '0 0 * * *' # everyday at midnight UTC + pull_request: + branches: master + push: + branches: master + tags: + - v* + +jobs: + buildx: + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v2 + - + name: Prepare + id: prepare + run: | + DOCKER_IMAGE=dutchcoders/transfer.sh + DOCKER_PLATFORMS=linux/amd64,linux/arm/v7,linux/arm64,linux/386 + VERSION=edge + + if [[ $GITHUB_REF == refs/tags/* ]]; then + VERSION=${GITHUB_REF#refs/tags/v} + fi + + if [ "${{ github.event_name }}" = "schedule" ]; then + VERSION=nightly + fi + + TAGS="--tag ${DOCKER_IMAGE}:${VERSION}" + + if [ $VERSION = edge -o $VERSION = nightly ]; then + TAGS="$TAGS --tag ${DOCKER_IMAGE}:latest" + fi + + echo ::set-output name=docker_image::${DOCKER_IMAGE} + echo ::set-output name=version::${VERSION} + echo ::set-output name=buildx_args::--platform ${DOCKER_PLATFORMS} \ + --build-arg VERSION=${VERSION} \ + --build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') \ + --build-arg VCS_REF=${GITHUB_SHA::8} \ + ${TAGS} . + - + name: Set up Docker Buildx + uses: crazy-max/ghaction-docker-buildx@v3 + - + name: Docker Buildx (build) + run: | + docker buildx build --no-cache --pull --output "type=image,push=false" ${{ steps.prepare.outputs.buildx_args }} + - + name: Docker Login + if: success() + env: + DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} + DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} + run: | + echo "${DOCKER_PASSWORD}" | docker login --username "${DOCKER_USERNAME}" --password-stdin + - + name: Docker Buildx (push) + if: success() + run: | + docker buildx build --output "type=image,push=true" ${{ steps.prepare.outputs.buildx_args }} + - + name: Docker Check Manifest + if: always() + run: | + docker run --rm mplatform/mquery ${{ steps.prepare.outputs.docker_image }}:${{ steps.prepare.outputs.version }} + - + name: Clear + if: always() + run: | + rm -f ${HOME}/.docker/config.json diff --git a/.github/workflows/buildx.yml b/.github/workflows/buildx.yml deleted file mode 100644 index d72f49e..0000000 --- a/.github/workflows/buildx.yml +++ /dev/null @@ -1,67 +0,0 @@ -# ref: https://github.com/crazy-max/diun/blob/master/.github/workflows/build.yml - -name: Docker -on: [push] -jobs: - build: - runs-on: ubuntu-18.04 - steps: - - name: Prepare - id: prepare - run: | - if [[ $GITHUB_REF == refs/tags/* ]]; then - echo ::set-output name=version::${GITHUB_REF#refs/tags/v} - elif [[ $GITHUB_REF == refs/heads/master ]]; then - echo ::set-output name=version::latest - elif [[ $GITHUB_REF == refs/heads/* ]]; then - echo ::set-output name=version::${GITHUB_REF#refs/heads/} - else - echo ::set-output name=version::snapshot - fi - echo ::set-output name=docker_platforms::linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64 - echo ::set-output name=docker_image::ductchcoders/transfer.sh - # https://github.com/crazy-max/ghaction-docker-buildx - - name: Set up Docker Buildx - id: buildx - uses: crazy-max/ghaction-docker-buildx@v1 - with: - version: latest - - - name: Environment - run: | - echo home=$HOME - echo git_ref=$GITHUB_REF - echo git_sha=$GITHUB_SHA - echo version=${{ steps.prepare.outputs.version }} - echo image=${{ steps.prepare.outputs.docker_image }} - echo platforms=${{ steps.prepare.outputs.docker_platforms }} - echo avail_platforms=${{ steps.buildx.outputs.platforms }} - # https://github.com/actions/checkout - - name: Checkout - uses: actions/checkout@v2 - - - name: Docker Buildx (no push) - run: | - docker buildx bake \ - --set transfersh.platform=${{ steps.prepare.outputs.docker_platforms }} \ - --set transfersh.output=type=image,push=false \ - --set transfersh.tags="${{ steps.prepare.outputs.docker_image }}:${{ steps.prepare.outputs.version }}" \ - --file docker-compose.yaml - - name: Docker Login - if: success() - env: - DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} - run: | - echo "${DOCKER_PASSWORD}" | docker login --username "${{ secrets.DOCKER_USERNAME }}" --password-stdin - - name: Docker Buildx (push) - if: success() - run: | - docker buildx bake \ - --set transfersh.platform=${{ steps.prepare.outputs.docker_platforms }} \ - --set transfersh.output=type=image,push=true \ - --set transfersh.tags="${{ steps.prepare.outputs.docker_image }}:${{ steps.prepare.outputs.version }}" \ - --file docker-compose.yaml - - name: Clear - if: always() - run: | - rm -f ${HOME}/.docker/config.json \ No newline at end of file