skillhub/.github/workflows/publish-images.yml
XiaoSeS e7e38d7304
fix(ci): mirror runnable OCI images without unsupported referrers (#1012)
Signed-off-by: XiaoSeS <87064762+XiaoSeS@users.noreply.github.com>
2026-10-25 15:14:14 +08:00

178 lines
6.5 KiB
YAML

name: Publish Images
on:
release:
types: [published]
workflow_dispatch:
concurrency:
group: publish-images-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
packages: write
jobs:
publish:
# Native DSH packages have their own release lifecycle.
if: github.event_name != 'release' || !startsWith(github.event.release.tag_name, 'dsh-v')
runs-on: ubuntu-latest
env:
MIRROR_REGISTRY: ${{ secrets.MIRROR_REGISTRY || secrets.ALIYUN_REGISTRY }}
MIRROR_NAMESPACE: ${{ secrets.MIRROR_NAMESPACE || secrets.ALIYUN_NAME_SPACE }}
MIRROR_REGISTRY_USERNAME: ${{ secrets.MIRROR_REGISTRY_USERNAME || secrets.ALIYUN_REGISTRY_USER }}
MIRROR_REGISTRY_PASSWORD: ${{ secrets.MIRROR_REGISTRY_PASSWORD || secrets.ALIYUN_REGISTRY_PASSWORD }}
strategy:
fail-fast: false
matrix:
include:
- name: server
context: ./server
dockerfile: ./server/Dockerfile
platforms: linux/amd64,linux/arm64,linux/riscv64
image: ghcr.io/${{ github.repository_owner }}/skillhub-server
mirror_image: skillhub-server
- name: web
context: ./web
dockerfile: ./web/Dockerfile
platforms: linux/amd64,linux/arm64,linux/riscv64
image: ghcr.io/${{ github.repository_owner }}/skillhub-web
mirror_image: skillhub-web
- name: scanner
context: ./scanner
dockerfile: ./scanner/Dockerfile
platforms: linux/amd64,linux/arm64
image: ghcr.io/${{ github.repository_owner }}/skillhub-scanner
mirror_image: skillhub-scanner
- name: github-sync
context: ./github-sync-go
dockerfile: ./github-sync-go/Dockerfile
platforms: linux/amd64,linux/arm64
image: ghcr.io/${{ github.repository_owner }}/skillhub-github-sync
mirror_image: skillhub-github-sync
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Detect mirror configuration
id: mirror
shell: bash
run: |
if [[ -n "${MIRROR_REGISTRY}" && -n "${MIRROR_NAMESPACE}" && -n "${MIRROR_REGISTRY_USERNAME}" && -n "${MIRROR_REGISTRY_PASSWORD}" ]]; then
echo "enabled=true" >> "$GITHUB_OUTPUT"
else
echo "enabled=false" >> "$GITHUB_OUTPUT"
fi
- name: Log in to mirror registry
if: ${{ steps.mirror.outputs.enabled == 'true' }}
shell: bash
run: |
echo "${MIRROR_REGISTRY_PASSWORD}" | docker login "${MIRROR_REGISTRY}" \
--username "${MIRROR_REGISTRY_USERNAME}" \
--password-stdin
- name: Prepare image targets
id: targets
run: |
{
echo "images<<EOF"
echo "${{ matrix.image }}"
if [ "${{ steps.mirror.outputs.enabled }}" = "true" ]; then
echo "${MIRROR_REGISTRY%/}/${MIRROR_NAMESPACE}/${{ matrix.mirror_image }}"
fi
echo "EOF"
} >> "$GITHUB_OUTPUT"
- name: Extract image metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ steps.targets.outputs.images }}
tags: |
type=raw,value=edge,enable={{is_default_branch}}
type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/v') }}
type=ref,event=tag
type=sha,format=short,prefix=sha-
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
- name: Build and push ${{ matrix.name }}
uses: docker/build-push-action@v6
with:
context: ${{ matrix.context }}
file: ${{ matrix.dockerfile }}
platforms: ${{ matrix.platforms }}
push: true
provenance: false
sbom: false
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha,scope=${{ matrix.name }}
cache-to: type=gha,mode=max,scope=${{ matrix.name }}
mirror-runtime-images:
name: Mirror Runtime Images
runs-on: ubuntu-latest
needs: publish
env:
MIRROR_REGISTRY: ${{ secrets.MIRROR_REGISTRY || secrets.ALIYUN_REGISTRY }}
MIRROR_NAMESPACE: ${{ secrets.MIRROR_NAMESPACE || secrets.ALIYUN_NAME_SPACE }}
MIRROR_REGISTRY_USERNAME: ${{ secrets.MIRROR_REGISTRY_USERNAME || secrets.ALIYUN_REGISTRY_USER }}
MIRROR_REGISTRY_PASSWORD: ${{ secrets.MIRROR_REGISTRY_PASSWORD || secrets.ALIYUN_REGISTRY_PASSWORD }}
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Detect mirror configuration
id: mirror
shell: bash
run: |
if [[ -n "${MIRROR_REGISTRY}" && -n "${MIRROR_NAMESPACE}" && -n "${MIRROR_REGISTRY_USERNAME}" && -n "${MIRROR_REGISTRY_PASSWORD}" ]]; then
echo "enabled=true" >> "$GITHUB_OUTPUT"
else
echo "enabled=false" >> "$GITHUB_OUTPUT"
fi
- name: Install pinned registry copy tool
if: ${{ steps.mirror.outputs.enabled == 'true' }}
run: |
# Buildx automatically copies OCI referrers rejected by some mirrors.
curl -fsSL --retry 3 \
https://github.com/regclient/regclient/releases/download/v0.11.7/regctl-linux-amd64 \
-o "$RUNNER_TEMP/regctl"
echo "3737fbbdd791e04e7a831640b681f3397a376498e80e2ad9b1b2d27296f239bc $RUNNER_TEMP/regctl" | sha256sum -c -
chmod +x "$RUNNER_TEMP/regctl"
echo "$RUNNER_TEMP" >> "$GITHUB_PATH"
- name: Log in to mirror registry
if: ${{ steps.mirror.outputs.enabled == 'true' }}
shell: bash
run: |
echo "${MIRROR_REGISTRY_PASSWORD}" | docker login "${MIRROR_REGISTRY}" \
--username "${MIRROR_REGISTRY_USERNAME}" \
--password-stdin
- name: Mirror runtime dependency images
if: ${{ steps.mirror.outputs.enabled == 'true' }}
run: bash scripts/mirror-runtime-images.sh
- name: Skip mirroring when registry secrets are not configured
if: ${{ steps.mirror.outputs.enabled != 'true' }}
run: echo "Mirror registry secrets are not configured; skipping runtime image mirroring."