From 90ba42df70b9ef88c62b697b955eb30a46b65732 Mon Sep 17 00:00:00 2001 From: CrazyMax <1951866+crazy-max@users.noreply.github.com> Date: Fri, 4 Jun 2021 20:23:02 +0200 Subject: [PATCH] Simplify Docker publish workflow (#921) Co-authored-by: CrazyMax Co-authored-by: Josh Gross --- ci/docker-publish.yml | 50 ++++++++++++++----------------------------- 1 file changed, 16 insertions(+), 34 deletions(-) diff --git a/ci/docker-publish.yml b/ci/docker-publish.yml index 3a5a084..ab266ef 100644 --- a/ci/docker-publish.yml +++ b/ci/docker-publish.yml @@ -6,51 +6,26 @@ name: Docker # documentation. on: + schedule: + - cron: $cron-daily push: branches: [ $default-branch ] - # Publish `v1.2.3` tags as releases. + # Publish semver tags as releases. tags: [ 'v*.*.*' ] - pull_request_target: - branches: [ $default-branch ] - - # Run tests for any PRs. pull_request: + branches: [ $default-branch ] env: - # TODO: Creates container named ACCOUNT/REPO - # Append /IMAGE-NAME to create a container named ACCOUNT/REPO/IMAGE-NAME + # Use docker.io for Docker Hub if empty + REGISTRY: ghcr.io + # github.repository as / IMAGE_NAME: ${{ github.repository }} - # Registry. Use docker.io for DockerHub - REGISTRY: ghcr.io jobs: - # Run tests. - # See also https://docs.docker.com/docker-hub/builds/automated-testing/ - test: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - - name: Run tests - run: | - if [ -f docker-compose.test.yml ]; then - docker-compose --file docker-compose.test.yml build - docker-compose --file docker-compose.test.yml run sut - else - docker build . --file Dockerfile - fi - - # Push image to GitHub Packages. - # See also https://docs.docker.com/docker-hub/builds/ - push: - # Ensure test job passes before pushing image. - needs: test + build: runs-on: ubuntu-latest - if: github.event_name == 'push' - permissions: contents: read packages: write @@ -59,23 +34,30 @@ jobs: - name: Checkout repository uses: actions/checkout@v2 + # Login against a Docker registry except on PR + # https://github.com/docker/login-action - name: Log into registry ${{ env.REGISTRY }} + if: github.event_name != 'pull_request' uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} + # Extract metadata (tags, labels) for Docker + # https://github.com/docker/metadata-action - name: Extract Docker metadata id: meta uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + # Build and push Docker image with Buildx (don't push on PR) + # https://github.com/docker/build-push-action - name: Build and push Docker image uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc with: - # Don't push on pull requests + context: . push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }}