From 42618b61c985cf824d1242e8b318ab2a5c1ef62a Mon Sep 17 00:00:00 2001 From: marcobaobao Date: Mon, 25 Sep 2023 15:37:18 +0200 Subject: [PATCH] github action refactor --- .github/workflows/docker-publish.yml | 105 ++++++++++----------------- 1 file changed, 37 insertions(+), 68 deletions(-) diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 29b6cd0..bc3b9e1 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -1,10 +1,4 @@ -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. - +name: Docker on: release: types: [published] @@ -13,15 +7,8 @@ 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: - build-ghcr: + publish: runs-on: ubuntu-latest permissions: contents: read @@ -31,80 +18,62 @@ jobs: id-token: write steps: - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v4 - # Install the cosign tool except on PR # https://github.com/sigstore/cosign-installer - name: Install cosign - if: github.event_name != 'pull_request' - uses: sigstore/cosign-installer@1e95c1de343b5b0c23352d6417ee3e48d5bcd422 + # v3.1.2 + uses: sigstore/cosign-installer@11086d25041f77fe8fe7b9ea4e48e3b9192b8f19 with: cosign-release: 'v1.13.1' - # 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 - - # 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 + - name: Set up QEMU for ARM emulation + # v2.2.0 + uses: docker/setup-qemu-action@2b82ce82d56a2a04d2637cd93a637ae1b359c0a7 with: - registry: ${{ env.REGISTRY }} + platforms: all + - name: Set up Docker Buildx + # 2.10.0 + uses: docker/setup-buildx-action@885d1462b80bc1c1c7f0b00334ad271f09369c55 + + - name: Login to Docker Hub + # 2.2.0 + uses: docker/login-action@465a07811f14bebb1938fbed4728c6a1ff8901fc + 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 username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - # Extract metadata (tags, labels) for Docker - # https://github.com/docker/metadata-action - - name: Extract Docker metadata + - name: Generate Docker metadata id: meta - uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 + # v4.6.0 + uses: docker/metadata-action@818d4b7b91585d195f67373fd9cb0332e31a7175 with: - images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + images: | + ghcr.io/${{ github.repository }} + docker.io/${{ secrets.DOCKER_HUB_USERNAME }}/yt-dlp-webui - # 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 - uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc + # v4.2.1 + uses: docker/build-push-action@0a97817b6ade9f46837855d676c4cca3a2471fc9 with: context: . + push: true platforms: linux/amd64,linux/arm/v7,linux/arm64 - push: ${{ github.event_name != 'pull_request' }} - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} + tags: ${{ secrets.DOCKER_HUB_USERNAME }}/yt-dlp-webui:latest - # 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 ${{ 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 + run: | + cosign sign ghcr.io/${{ github.repository }}@${{ steps.build-and-push.outputs.digest }} + cosign sign docker.io/${{ secrets.DOCKER_HUB_USERNAME }}/yt-dlp-webui@${{ steps.build-and-push.outputs.digest }}