ci: make Docker Hub and Quay.io registries optional and dynamic

Currently, the workflow attempts to log in and push to the official openwrt namespaces on Docker Hub and Quay.io unconditionally on all non-pull-request events. This causes errors on repository forks where these credentials are not set.

This change makes the Docker Hub and Quay.io steps conditional on their respective secrets being non-empty. Additionally, the target repository namespace paths are dynamically derived from the secrets (or from the github.repository_owner in case of GHCR), allowing forks to optionally push to their own Docker Hub or Quay.io accounts if they set up the credentials.
pull/204/head
Josef Schlehofer 2026-06-24 23:26:40 +02:00
parent 1164645a5e
commit dec0e57865
No known key found for this signature in database
GPG Key ID: 942FF3271E2AC7DB
1 changed files with 31 additions and 27 deletions

View File

@ -3,6 +3,10 @@ run-name: ${{ inputs.ref }} ${{ inputs.target }}
env:
FILE_HOST: https://mirror-03.infra.openwrt.org
DOCKER_USER: ${{ secrets.DOCKER_USER }}
DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }}
QUAY_USER: ${{ secrets.QUAY_USER }}
QUAY_TOKEN: ${{ secrets.QUAY_TOKEN }}
on:
# push:
@ -172,14 +176,14 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to Docker.io Container Registry
if: github.event_name != 'pull_request'
if: github.event_name != 'pull_request' && env.DOCKER_USER != '' && env.DOCKER_TOKEN != ''
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Login to Quay.io Container Registry
if: github.event_name != 'pull_request'
if: github.event_name != 'pull_request' && env.QUAY_USER != '' && env.QUAY_TOKEN != ''
uses: docker/login-action@v3
with:
registry: quay.io
@ -191,9 +195,9 @@ jobs:
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/openwrt/imagebuilder
docker.io/openwrt/imagebuilder
quay.io/openwrt/imagebuilder
ghcr.io/${{ github.repository_owner }}/imagebuilder
${{ env.DOCKER_USER != '' && format('docker.io/{0}/imagebuilder', env.DOCKER_USER) || '' }}
${{ env.QUAY_USER != '' && format('quay.io/{0}/imagebuilder', env.QUAY_USER) || '' }}
flavor: |
latest=false
prefix=${{ github.event.inputs.prefix }}
@ -264,14 +268,14 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to Docker.io Container Registry
if: github.event_name != 'pull_request'
if: github.event_name != 'pull_request' && env.DOCKER_USER != '' && env.DOCKER_TOKEN != ''
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Login to Quay.io Container Registry
if: github.event_name != 'pull_request'
if: github.event_name != 'pull_request' && env.QUAY_USER != '' && env.QUAY_TOKEN != ''
uses: docker/login-action@v3
with:
registry: quay.io
@ -283,9 +287,9 @@ jobs:
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/openwrt/sdk
docker.io/openwrt/sdk
quay.io/openwrt/sdk
ghcr.io/${{ github.repository_owner }}/sdk
${{ env.DOCKER_USER != '' && format('docker.io/{0}/sdk', env.DOCKER_USER) || '' }}
${{ env.QUAY_USER != '' && format('quay.io/{0}/sdk', env.QUAY_USER) || '' }}
flavor: |
latest=false
prefix=${{ github.event.inputs.prefix }}
@ -297,9 +301,9 @@ jobs:
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/openwrt/sdk
docker.io/openwrt/sdk
quay.io/openwrt/sdk
ghcr.io/${{ github.repository_owner }}/sdk
${{ env.DOCKER_USER != '' && format('docker.io/{0}/sdk', env.DOCKER_USER) || '' }}
${{ env.QUAY_USER != '' && format('quay.io/{0}/sdk', env.QUAY_USER) || '' }}
flavor: |
latest=false
prefix=${{ github.event.inputs.prefix }}
@ -312,9 +316,9 @@ jobs:
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/openwrt/sdk
docker.io/openwrt/sdk
quay.io/openwrt/sdk
ghcr.io/${{ github.repository_owner }}/sdk
${{ env.DOCKER_USER != '' && format('docker.io/{0}/sdk', env.DOCKER_USER) || '' }}
${{ env.QUAY_USER != '' && format('quay.io/{0}/sdk', env.QUAY_USER) || '' }}
flavor: |
latest=false
prefix=${{ github.event.inputs.prefix }}
@ -327,9 +331,9 @@ jobs:
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/openwrt/sdk
docker.io/openwrt/sdk
quay.io/openwrt/sdk
ghcr.io/${{ github.repository_owner }}/sdk
${{ env.DOCKER_USER != '' && format('docker.io/{0}/sdk', env.DOCKER_USER) || '' }}
${{ env.QUAY_USER != '' && format('quay.io/{0}/sdk', env.QUAY_USER) || '' }}
flavor: |
latest=false
prefix=${{ github.event.inputs.prefix }}
@ -341,9 +345,9 @@ jobs:
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/openwrt/sdk
docker.io/openwrt/sdk
quay.io/openwrt/sdk
ghcr.io/${{ github.repository_owner }}/sdk
${{ env.DOCKER_USER != '' && format('docker.io/{0}/sdk', env.DOCKER_USER) || '' }}
${{ env.QUAY_USER != '' && format('quay.io/{0}/sdk', env.QUAY_USER) || '' }}
tags: latest
- name: Build
@ -431,14 +435,14 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to Docker.io Container Registry
if: github.event_name != 'pull_request'
if: github.event_name != 'pull_request' && env.DOCKER_USER != '' && env.DOCKER_TOKEN != ''
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Login to Quay.io Container Registry
if: github.event_name != 'pull_request'
if: github.event_name != 'pull_request' && env.QUAY_USER != '' && env.QUAY_TOKEN != ''
uses: docker/login-action@v3
with:
registry: quay.io
@ -450,9 +454,9 @@ jobs:
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/openwrt/rootfs
docker.io/openwrt/rootfs
quay.io/openwrt/rootfs
ghcr.io/${{ github.repository_owner }}/rootfs
${{ env.DOCKER_USER != '' && format('docker.io/{0}/rootfs', env.DOCKER_USER) || '' }}
${{ env.QUAY_USER != '' && format('quay.io/{0}/rootfs', env.QUAY_USER) || '' }}
flavor: |
latest=false
prefix=${{ github.event.inputs.prefix }}