From 788bdccd00df4af07a68ac6bfe86bbd62028afce Mon Sep 17 00:00:00 2001 From: baudneo <86508179+baudneo@users.noreply.github.com> Date: Sat, 6 Apr 2024 18:52:14 -0600 Subject: [PATCH] Add workflow --- .../workflows/container-package-publish.yml | 104 ++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 .github/workflows/container-package-publish.yml diff --git a/.github/workflows/container-package-publish.yml b/.github/workflows/container-package-publish.yml new file mode 100644 index 0000000..7c02952 --- /dev/null +++ b/.github/workflows/container-package-publish.yml @@ -0,0 +1,104 @@ +name: Docker - publish multi-arch packages + +# 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 ] + push: +# branches: [ "python" ] + # Publish semver releases. + tags: [ 'v**.**.**' ] + workflow_dispatch: + + +env: + # github.repository as / + IMAGE_NAME: ${{ github.repository }} + + +jobs: + build: + + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + # Set up BuildKit Docker container builder to be able to build + # multi-platform images and export cache + # https://github.com/docker/setup-buildx-action + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + # Login against a Docker registry except on PR + # https://github.com/docker/login-action + - name: Log into registry ghcr.io + if: github.event_name != 'pull_request' + uses: docker/login-action@v3 + 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 + id: meta + uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0 + with: + images: ghcr.io/${{ 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 + uses: docker/build-push-action@v5 + with: + context: . + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max + platforms: linux/amd64,linux/arm64,linux/arm/v7 + +# now we need to publish to a different registry +# we can use the same image name but we need to change the registry +# we can use the same tags and labels + - name: Log into registry docker.io + if: github.event_name != 'pull_request' + uses: docker/login-action@v3 + with: + registry: docker.io + username: ${{ github.actor }} + password: ${{ secrets.DOCKER_HUB_KEY }} + + - name: Extract Docker metadata + id: meta2 + uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0 + with: + images: docker.io/${{ env.IMAGE_NAME }} + + - name: Build and push Docker image 2 + id: build-and-push2 + uses: docker/build-push-action@v5 + with: + context: . + push: ${{ github.event_name != 'pull_request' }} + # add latest to tags + tags: ${{ steps.meta2.outputs.tags }} + labels: ${{ steps.meta2.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max + platforms: linux/amd64,linux/arm64,linux/arm/v7 \ No newline at end of file