From 17221bf0fa99f8a9edb7fb0510f6e36cbcaee3ea Mon Sep 17 00:00:00 2001 From: adamus1red Date: Thu, 13 Jun 2024 00:43:43 +0100 Subject: [PATCH] GHCR Changes Use docker/metadata-action to generate tags and labels Add second docker/login-action to support GHCR Use docker/setup-qemu-action for multi-arch build Update docker/serup-buildx-action to v3 Fix nightly to only be built for 3.12 and fix image tags --- .github/workflows/docker-publish.yml | 95 +++++++++++++++++++++------- 1 file changed, 72 insertions(+), 23 deletions(-) diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index c6882e0..91e1a6d 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -33,12 +33,13 @@ jobs: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - uses: actions/checkout@v4 - - + - + name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx - id: buildx uses: docker/setup-buildx-action@v3 - with: - install: true - name: Inspect builder @@ -56,22 +57,58 @@ jobs: version-file: Dockerfile version-file-extraction-pattern: '(?<=SOPEL_BRANCH=v).+' - - name: Inspect Version - id: tags - env: - PYTHON_TAG: ${{ matrix.python_images }} - IMAGE: ${{ secrets.DOCKER_SOPEL_IMAGE_NAME }} - version: ${{ env.RELEASE_VERSION }} - run: | - if [ "${{ github.event_name }}" == "pull_request" ]; then IMAGE="sopel"; fi - TAGS="${IMAGE}:${version}-py${PYTHON_TAG},${IMAGE}:${version%.*}-py${PYTHON_TAG},${IMAGE}:${version%.*.*}-py${PYTHON_TAG}" - if [[ "x${{ matrix.python_images }}" == "x${{ env.default_python }}" ]] && [[ "${{ github.event_name }}" == "push" || "${{ github.event_name }}" == "workflow_dispatch" ]]; then - TAGS="${TAGS},${IMAGE}:${version},${IMAGE}:${version%.*},${IMAGE}:${version%.*.*},${IMAGE}:latest" - elif [[ "${{ github.event_name }}" == "schedule" ]]; then - TAGS="${IMAGE}:nightly" - fi - echo ::set-output name=tags::${TAGS} + - + name: Docker meta + id: meta-default + uses: docker/metadata-action@v5 + if: matrix.python_images == env.default_python + with: + images: | + ${{ vars.DOCKER_HUB_IMAGE_NAME }} + ghcr.io/${{ github.repository_owner }}/sopel + flavor: | + latest=true + tags: | + type=ref,event=branch + + # Nighly + type=schedule,pattern=nightly + + # Python full version + type=semver,pattern={{major}},value=v${{ env.RELEASE_VERSION }},suffix=-py${{ matrix.python_images }} + type=semver,pattern={{major}}.{{minor}},value=v${{ env.RELEASE_VERSION }},suffix=-py${{ matrix.python_images }} + type=semver,pattern={{version}},value=v${{ env.RELEASE_VERSION }},suffix=-py${{ matrix.python_images }} + + + # Python 3 + type=semver,pattern={{major}},value=v${{ env.RELEASE_VERSION }},suffix=-py3 + type=semver,pattern={{major}}.{{minor}},value=v${{ env.RELEASE_VERSION }},suffix=-py3 + type=semver,pattern={{version}},value=v${{ env.RELEASE_VERSION }},suffix=-py3 + + # Version only + type=semver,pattern={{major}},value=v${{ env.RELEASE_VERSION }} + type=semver,pattern={{major}}.{{minor}},value=v${{ env.RELEASE_VERSION }} + type=semver,pattern={{version}},value=v${{ env.RELEASE_VERSION }} + - + name: Docker meta + id: meta-alt-python + uses: docker/metadata-action@v5 + if: matrix.python_images != env.default_python + with: + images: | + ${{ vars.DOCKER_HUB_IMAGE_NAME }} + ghcr.io/${{ github.repository_owner }}/sopel + flavor: | + latest=false + suffix=-py${{ matrix.python_images }} + tags: | + # Nighly + type=schedule,pattern=nightly + # Python full version + type=semver,pattern={{major}},value=v${{ env.RELEASE_VERSION }} + type=semver,pattern={{major}}.{{minor}},value=v${{ env.RELEASE_VERSION }} + type=semver,pattern={{version}},value=v${{ env.RELEASE_VERSION }} - name: Login to Docker Hub uses: docker/login-action@v3 @@ -79,27 +116,39 @@ jobs: with: username: ${{ secrets.DOCKER_HUB_USERNAME }} password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} + - + name: Login to GitHub Container Registry + uses: docker/login-action@v3 + if: github.event_name != 'pull_request' + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Build SOPEL for ${{ matrix.python_images }} uses: docker/build-push-action@v5 if: github.event_name != 'schedule' with: - builder: ${{ steps.buildx.outputs.name }} context: . file: ./Dockerfile build-args: PYTHON_TAG=${{ matrix.python_images }}-alpine + platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6,linux/s390x push: ${{ github.event_name != 'pull_request' }} - tags: ${{ steps.tags.outputs.tags }} + tags: ${{ steps.meta-default.outputs.tags }}${{ steps.meta-alt-python.outputs.tags }} + labels: ${{ steps.meta-default.outputs.labels }}${{ steps.meta-alt-python.outputs.labels }} + - name: Build Nightly SOPEL for ${{ matrix.python_images }} uses: docker/build-push-action@v5 if: github.event_name == 'schedule' && matrix.python_images == env.default_python with: - builder: ${{ steps.buildx.outputs.name }} context: . file: ./Dockerfile build-args: | PYTHON_TAG=${{ matrix.python_images }}-alpine SOPEL_BRANCH=master + platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6,linux/s390x push: ${{ github.event_name != 'pull_request' }} - tags: ${{ steps.tags.outputs.tags }} + tags: ${{ vars.DOCKER_HUB_IMAGE_NAME }}:nightly,ghcr.io/${{ github.repository_owner }}/sopel:nightly + labels: ${{ steps.meta-default.outputs.labels }}${{ steps.meta-alt-python.outputs.labels }} \ No newline at end of file