Skip to content

Commit

Permalink
GHCR Changes
Browse files Browse the repository at this point in the history
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
  • Loading branch information
adamus1red committed Jun 13, 2024
1 parent 138e111 commit ba47174
Showing 1 changed file with 73 additions and 24 deletions.
97 changes: 73 additions & 24 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -56,50 +57,98 @@ 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
if: github.event_name != 'pull_request'
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
if: github.event_name == 'schedule'
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: ${{ steps.meta-default.outputs.tags }}${{ steps.meta-alt-python.outputs.tags }}
labels: ${{ steps.meta-default.outputs.labels }}${{ steps.meta-alt-python.outputs.labels }}

0 comments on commit ba47174

Please sign in to comment.