From 8d63832daf3c92a5f9fdbc6d12728821c1b65284 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 | 96 ++++++++++++++++++++-------- 1 file changed, 71 insertions(+), 25 deletions(-) diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index c6882e0..4c31f5c 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -31,14 +31,16 @@ jobs: # Steps represent a sequence of tasks that will be executed as part of the job steps: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v4 + - + 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 @@ -49,28 +51,60 @@ jobs: echo "Flags: ${{ steps.buildx.outputs.flags }}" echo "Platforms: ${{ steps.buildx.outputs.platforms }}" - - name: Generate versions + - + name: Get sopel version uses: HardNorth/github-version-generate@v1.4.0 with: version-source: file 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: | + # Python full version + type=semver,pattern={{version}},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={{major}},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 }} + + type=ref,event=branch + + - + 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: | + # Python full version + type=semver,pattern={{version}},value=v${{ env.RELEASE_VERSION }} + type=semver,pattern={{major}}.{{minor}},value=v${{ env.RELEASE_VERSION }} + type=semver,pattern={{major}},value=v${{ env.RELEASE_VERSION }} - name: Login to Docker Hub @@ -79,27 +113,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