From 695b3357c18148484fe8bbba666b48cabd40b617 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Sun, 14 Jun 2020 09:10:57 +0200 Subject: [PATCH] Update workflows --- .github/workflows/build.yml | 73 +++++++++++++++++++------------------ .github/workflows/test.yml | 22 +++++------ Dockerfile | 1 - README.md | 2 +- 4 files changed, 50 insertions(+), 48 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a70cc53..1da0287 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -2,12 +2,17 @@ name: build on: push: - branches: 'master' - tags: '*' - paths: - - '.github/workflows/build.yml' - - 'Dockerfile' - - 'entrypoint.sh' + branches: + - '**' + tags: + - '*' + paths-ignore: + - '**.md' + pull_request: + branches: + - '**' + paths-ignore: + - '**.md' jobs: build: @@ -17,17 +22,29 @@ jobs: name: Prepare id: prepare run: | + DOCKER_USERNAME=crazymax + DOCKER_IMAGE=crazymax/fail2ban + DOCKER_PLATFORMS=linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/386,linux/ppc64le,linux/s390x + VERSION=edge + if [[ $GITHUB_REF == refs/tags/* ]]; then TAG=${GITHUB_REF#refs/tags/} - echo ::set-output name=tag_name::${TAG} - echo ::set-output name=version::${TAG%-*} - else - echo ::set-output name=version::snapshot + VERSION=${TAG%-*} + fi + + TAGS="--tag ${DOCKER_IMAGE}:${VERSION}" + if [ "$VERSION" != "edge" ]; then + TAGS="$TAGS --tag ${DOCKER_IMAGE}:latest" fi - echo ::set-output name=build_date::$(date -u +'%Y-%m-%dT%H:%M:%SZ') - echo ::set-output name=docker_platforms::linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/386,linux/ppc64le,linux/s390x - echo ::set-output name=docker_username::crazymax - echo ::set-output name=docker_image::crazymax/fail2ban + + echo ::set-output name=docker_username::${DOCKER_USERNAME} + 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} --file Dockerfile . - name: Set up Docker Buildx uses: crazy-max/ghaction-docker-buildx@v3.1.0 @@ -35,42 +52,28 @@ jobs: name: Checkout uses: actions/checkout@v2 - - name: Docker Buildx (no push) + name: Docker Buildx (build) run: | - docker buildx build --platform ${{ steps.prepare.outputs.docker_platforms }} \ - --output "type=image,push=false" \ - --build-arg "BUILD_DATE=${{ steps.prepare.outputs.build_date }}" \ - --build-arg "VCS_REF=${GITHUB_SHA::8}" \ - --build-arg "VERSION=${{ steps.prepare.outputs.version }}" \ - --tag "${{ steps.prepare.outputs.docker_image }}:latest" \ - --tag "${{ steps.prepare.outputs.docker_image }}:${{ steps.prepare.outputs.version }}" \ - --file Dockerfile . + docker buildx build --output "type=image,push=false" ${{ steps.prepare.outputs.buildx_args }} - name: Docker Login - if: success() && startsWith(github.ref, 'refs/tags/') + if: success() && github.event_name != 'pull_request' && endsWith(github.ref, github.repository.default_branch) env: DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} run: | echo "${DOCKER_PASSWORD}" | docker login --username "${{ steps.prepare.outputs.docker_username }}" --password-stdin - name: Docker Buildx (push) - if: success() && startsWith(github.ref, 'refs/tags/') + if: success() && github.event_name != 'pull_request' && endsWith(github.ref, github.repository.default_branch) run: | - docker buildx build --platform ${{ steps.prepare.outputs.docker_platforms }} \ - --output "type=image,push=true" \ - --build-arg "BUILD_DATE=${{ steps.prepare.outputs.build_date }}" \ - --build-arg "VCS_REF=${GITHUB_SHA::8}" \ - --build-arg "VERSION=${{ steps.prepare.outputs.version }}" \ - --tag "${{ steps.prepare.outputs.docker_image }}:${{ steps.prepare.outputs.version }}" \ - --tag "${{ steps.prepare.outputs.docker_image }}:latest" \ - --file Dockerfile . + docker buildx build --output "type=image,push=true" ${{ steps.prepare.outputs.buildx_args }} - name: Docker Check Manifest - if: always() && startsWith(github.ref, 'refs/tags/') + if: success() && github.event_name != 'pull_request' && endsWith(github.ref, github.repository.default_branch) run: | docker run --rm mplatform/mquery ${{ steps.prepare.outputs.docker_image }}:${{ steps.prepare.outputs.version }} - name: Clear - if: always() && startsWith(github.ref, 'refs/tags/') + if: always() && github.event_name != 'pull_request' && endsWith(github.ref, github.repository.default_branch) run: | rm -f ${HOME}/.docker/config.json diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9143eb4..0fd420e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,18 +1,18 @@ name: test on: - pull_request: - branches: master - paths: - - '.github/workflows/test.yml' - - 'Dockerfile' - - 'entrypoint.sh' push: - branches: master - paths: - - '.github/workflows/test.yml' - - 'Dockerfile' - - 'entrypoint.sh' + branches: + - '**' + tags: + - '*' + paths-ignore: + - '**.md' + pull_request: + branches: + - '**' + paths-ignore: + - '**.md' jobs: test: diff --git a/Dockerfile b/Dockerfile index 317cc26..bb9c10d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,3 @@ -# syntax=docker/dockerfile:experimental FROM --platform=${TARGETPLATFORM:-linux/amd64} alpine:3.11 ARG BUILD_DATE diff --git a/README.md b/README.md index 918266d..bc4c1c4 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ ## About 🐳 [Fail2ban](https://www.fail2ban.org) Docker image based on Alpine Linux.
-If you are interested, [check out](https://hub.docker.com/r/crazymax/) my other 🐳 Docker images! +If you are interested, [check out](https://hub.docker.com/r/crazymax/) my other Docker images! 💡 Want to be notified of new releases? Check out 🔔 [Diun (Docker Image Update Notifier)](https://github.com/crazy-max/diun) project!