From 665a08ddc45708fb130446502005bea5667409dc Mon Sep 17 00:00:00 2001 From: Marco <35533749+marcopeocchi@users.noreply.github.com> Date: Sat, 23 Sep 2023 15:29:20 +0200 Subject: [PATCH] Update docker-publish.yml --- .github/workflows/docker-publish.yml | 105 +++++++++++++++++---------- 1 file changed, 67 insertions(+), 38 deletions(-) diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index c605ac3..29b6cd0 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -1,4 +1,10 @@ -name: Docker +name: Docker (ghcr.io) + +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + on: release: types: [published] @@ -7,8 +13,15 @@ on: schedule: - cron : '0 1 * * 0' +env: + # Use docker.io for Docker Hub if empty + REGISTRY: ghcr.io + # github.repository as / + IMAGE_NAME: ${{ github.repository }} + + jobs: - publish: + build-ghcr: runs-on: ubuntu-latest permissions: contents: read @@ -18,64 +31,80 @@ jobs: id-token: write steps: - name: Checkout repository - uses: actions/checkout@v4 + uses: actions/checkout@v2 + # Install the cosign tool except on PR # https://github.com/sigstore/cosign-installer - name: Install cosign - # v3.1.2 - uses: sigstore/cosign-installer@11086d25041f77fe8fe7b9ea4e48e3b9192b8f19 + if: github.event_name != 'pull_request' + uses: sigstore/cosign-installer@1e95c1de343b5b0c23352d6417ee3e48d5bcd422 with: cosign-release: 'v1.13.1' - - name: Set up QEMU for ARM emulation - # v2.2.0 - uses: docker/setup-qemu-action@2b82ce82d56a2a04d2637cd93a637ae1b359c0a7 - with: - platforms: all - - name: Set up Docker Buildx - # 2.10.0 - uses: docker/setup-buildx-action@885d1462b80bc1c1c7f0b00334ad271f09369c55 + # Workaround: https://github.com/docker/build-push-action/issues/461 + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + - name: Setup Docker buildx + uses: docker/setup-buildx-action@79abd3f86f79a9d68a23c75a09a9a85889262adf - - name: Login to Docker Hub - # 2.2.0 - uses: docker/login-action@465a07811f14bebb1938fbed4728c6a1ff8901fc + # 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: - username: ${{ secrets.DOCKER_HUB_USERNAME }} - password: ${{ secrets.DOCKER_HUB_PASSWORD }} - - name: Login to GHCR - # 2.2.0 - uses: docker/login-action@465a07811f14bebb1938fbed4728c6a1ff8901fc - with: - registry: ghcr.io + registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Generate Docker metadata + # Extract metadata (tags, labels) for Docker + # https://github.com/docker/metadata-action + - name: Extract Docker metadata id: meta - # v4.6.0 - uses: docker/metadata-action@818d4b7b91585d195f67373fd9cb0332e31a7175 + uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 with: - images: | - docker.io/${{ secrets.DOCKER_HUB_USERNAME }}/yt-dlp-webui - # ghcr.io/${{ github.repository }} - + 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 id: build-and-push - # v4.2.1 - uses: docker/build-push-action@0a97817b6ade9f46837855d676c4cca3a2471fc9 + uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc with: context: . - push: true platforms: linux/amd64,linux/arm/v7,linux/arm64 - tags: latest - #tags: ${{ steps.meta.outputs.tags }} + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} + # Sign the resulting Docker image digest except on PRs. + # This will only write to the public Rekor transparency log when the Docker + # repository is public to avoid leaking data. If you would like to publish + # transparency data even for private images, pass --force to cosign below. + # https://github.com/sigstore/cosign - name: Sign the published Docker image + if: ${{ github.event_name != 'pull_request' }} env: COSIGN_EXPERIMENTAL: "true" # This step uses the identity token to provision an ephemeral certificate # against the sigstore community Fulcio instance. - run: | - cosign sign docker.io/${{ secrets.DOCKER_HUB_USERNAME }}/yt-dlp-webui@${{ steps.build-and-push.outputs.digest }} - # cosign sign ghcr.io/${{ github.repository }}@${{ steps.build-and-push.outputs.digest }} + run: cosign sign ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@${{ steps.build-and-push.outputs.digest }} + + build-dockerhub: + runs-on: ubuntu-latest + env: + REGISTRY: 'docker.io' + steps: + - uses: actions/checkout@v2 + - name: Login to Docker Hub + env: + DOCKER_USER: ${{secrets.DOCKER_HUB_USERNAME}} + DOCKER_PASSWORD: ${{secrets.DOCKER_HUB_PASSWORD}} + run: | + docker login -u $DOCKER_USER -p $DOCKER_PASSWORD + - name: Install buildx + uses: crazy-max/ghaction-docker-buildx@v1 + with: + version: latest + - name: Build the Docker image + run: docker buildx build . --file Dockerfile --tag ${{secrets.DOCKER_HUB_USERNAME}}/yt-dlp-webui:latest --push --platform linux/amd64,linux/arm/v7,linux/arm64