From f5c029fbe89b7af3eb59dd2a91868ddb396b278a Mon Sep 17 00:00:00 2001 From: binfan5 Date: Sun, 15 Mar 2026 13:18:37 +0800 Subject: [PATCH 1/3] feat(ops): add optional runtime registry mirroring --- .env.release.example | 2 + .github/workflows/publish-images.yml | 83 +++++++++++++++++++++++- README.md | 7 ++ compose.release.yml | 4 +- deploy/runtime-mirror-images.txt | 7 ++ docker-compose.yml | 6 +- monitoring/docker-compose.monitoring.yml | 4 +- scripts/mirror-runtime-images.sh | 29 +++++++++ scripts/runtime.sh | 45 +++++++++++++ 9 files changed, 179 insertions(+), 8 deletions(-) create mode 100644 deploy/runtime-mirror-images.txt create mode 100644 scripts/mirror-runtime-images.sh diff --git a/.env.release.example b/.env.release.example index 21d73140..d83858eb 100644 --- a/.env.release.example +++ b/.env.release.example @@ -3,6 +3,8 @@ SKILLHUB_VERSION=edge SKILLHUB_SERVER_IMAGE=ghcr.io/iflytek/skillhub-server SKILLHUB_WEB_IMAGE=ghcr.io/iflytek/skillhub-web +POSTGRES_IMAGE=postgres:16-alpine +REDIS_IMAGE=redis:7-alpine # Public entrypoint seen by browsers/CLI, no trailing slash. SKILLHUB_PUBLIC_BASE_URL=https://skillhub.example.com diff --git a/.github/workflows/publish-images.yml b/.github/workflows/publish-images.yml index b5e42548..d5351fac 100644 --- a/.github/workflows/publish-images.yml +++ b/.github/workflows/publish-images.yml @@ -19,6 +19,11 @@ env: jobs: publish: 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: @@ -27,10 +32,12 @@ jobs: context: ./server dockerfile: ./server/Dockerfile image: ghcr.io/${{ github.repository_owner }}/skillhub-server + mirror_image: skillhub-server - name: web context: ./web dockerfile: ./web/Dockerfile image: ghcr.io/${{ github.repository_owner }}/skillhub-web + mirror_image: skillhub-web steps: - name: Check out repository @@ -49,11 +56,41 @@ jobs: 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<> "$GITHUB_OUTPUT" + - name: Extract image metadata id: meta uses: docker/metadata-action@v5 with: - images: ${{ matrix.image }} + 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') }} @@ -75,3 +112,47 @@ jobs: 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: Set up Docker Buildx + if: ${{ steps.mirror.outputs.enabled == 'true' }} + uses: docker/setup-buildx-action@v3 + + - 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." diff --git a/README.md b/README.md index 077b0dda..4fe98109 100644 --- a/README.md +++ b/README.md @@ -137,6 +137,13 @@ Recommended image tags: - `SKILLHUB_VERSION=edge` for the latest `main` build - `SKILLHUB_VERSION=vX.Y.Z` for a fixed release +If you maintain a closer registry mirror, start the runtime with: + +```bash +curl -fsSL https://raw.githubusercontent.com/iflytek/skillhub/main/scripts/runtime.sh | sh -s -- up \ + --mirror-registry / +``` + Start the runtime: ```bash diff --git a/compose.release.yml b/compose.release.yml index b08eedde..99f0934d 100644 --- a/compose.release.yml +++ b/compose.release.yml @@ -1,6 +1,6 @@ services: postgres: - image: postgres:16-alpine + image: ${POSTGRES_IMAGE:-postgres:16-alpine} restart: unless-stopped ports: - "${POSTGRES_BIND_ADDRESS:-127.0.0.1}:${POSTGRES_PORT:-5432}:5432" @@ -17,7 +17,7 @@ services: retries: 10 redis: - image: redis:7-alpine + image: ${REDIS_IMAGE:-redis:7-alpine} restart: unless-stopped ports: - "${REDIS_BIND_ADDRESS:-127.0.0.1}:${REDIS_PORT:-6379}:6379" diff --git a/deploy/runtime-mirror-images.txt b/deploy/runtime-mirror-images.txt new file mode 100644 index 00000000..4ad7de89 --- /dev/null +++ b/deploy/runtime-mirror-images.txt @@ -0,0 +1,7 @@ +# source_image target_image +postgres:16-alpine postgres:16-alpine +redis:7-alpine redis:7-alpine +minio/minio:latest minio:latest +prom/prometheus:latest prometheus:latest +grafana/grafana:latest grafana:latest +nginx:alpine nginx:alpine diff --git a/docker-compose.yml b/docker-compose.yml index 63b0e8e8..3da70c7c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,6 @@ services: postgres: - image: postgres:16-alpine + image: ${POSTGRES_IMAGE:-postgres:16-alpine} ports: - "5432:5432" environment: @@ -16,7 +16,7 @@ services: retries: 5 redis: - image: redis:7-alpine + image: ${REDIS_IMAGE:-redis:7-alpine} ports: - "6379:6379" healthcheck: @@ -26,7 +26,7 @@ services: retries: 5 minio: - image: minio/minio:latest + image: ${MINIO_IMAGE:-minio/minio:latest} ports: - "9000:9000" - "9001:9001" diff --git a/monitoring/docker-compose.monitoring.yml b/monitoring/docker-compose.monitoring.yml index 75056f43..7ae63321 100644 --- a/monitoring/docker-compose.monitoring.yml +++ b/monitoring/docker-compose.monitoring.yml @@ -1,13 +1,13 @@ services: prometheus: - image: prom/prometheus:latest + image: ${PROMETHEUS_IMAGE:-prom/prometheus:latest} ports: - "9090:9090" volumes: - ./prometheus.yml:/etc/prometheus/prometheus.yml:ro grafana: - image: grafana/grafana:latest + image: ${GRAFANA_IMAGE:-grafana/grafana:latest} ports: - "3001:3000" environment: diff --git a/scripts/mirror-runtime-images.sh b/scripts/mirror-runtime-images.sh new file mode 100644 index 00000000..fcd80ef9 --- /dev/null +++ b/scripts/mirror-runtime-images.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash + +set -euo pipefail + +IMAGES_FILE="${1:-deploy/runtime-mirror-images.txt}" + +: "${MIRROR_REGISTRY:?MIRROR_REGISTRY is required}" +: "${MIRROR_NAMESPACE:?MIRROR_NAMESPACE is required}" + +target_prefix="${MIRROR_REGISTRY%/}/${MIRROR_NAMESPACE}" + +while read -r source target; do + if [[ -z "${source}" || "${source}" == \#* ]]; then + continue + fi + + if [[ -z "${target:-}" ]]; then + echo "Missing target image mapping for ${source}" >&2 + exit 1 + fi + + if docker buildx imagetools inspect "${target_prefix}/${target}" >/dev/null 2>&1; then + echo "Skipping existing image ${target_prefix}/${target}" + continue + fi + + echo "Mirroring ${source} -> ${target_prefix}/${target}" + docker buildx imagetools create --tag "${target_prefix}/${target}" "${source}" +done < "${IMAGES_FILE}" diff --git a/scripts/runtime.sh b/scripts/runtime.sh index 1d04b4d5..fbec3e87 100644 --- a/scripts/runtime.sh +++ b/scripts/runtime.sh @@ -12,8 +12,11 @@ SKILLHUB_REF="${SKILLHUB_REF:-main}" SKILLHUB_HOME_DEFAULT="${TMPDIR:-/tmp}/skillhub-runtime" SKILLHUB_HOME="${SKILLHUB_HOME:-$SKILLHUB_HOME_DEFAULT}" SKILLHUB_VERSION_VALUE="${SKILLHUB_VERSION:-}" +SKILLHUB_MIRROR_REGISTRY_VALUE="${SKILLHUB_MIRROR_REGISTRY:-}" SKILLHUB_SERVER_IMAGE_VALUE="${SKILLHUB_SERVER_IMAGE:-}" SKILLHUB_WEB_IMAGE_VALUE="${SKILLHUB_WEB_IMAGE:-}" +POSTGRES_IMAGE_VALUE="${POSTGRES_IMAGE:-}" +REDIS_IMAGE_VALUE="${REDIS_IMAGE:-}" while [ "$#" -gt 0 ]; do case "$1" in @@ -22,6 +25,11 @@ while [ "$#" -gt 0 ]; do SKILLHUB_VERSION_VALUE="$2" shift 2 ;; + --mirror-registry) + [ "$#" -ge 2 ] || { echo "Missing value for --mirror-registry" >&2; exit 1; } + SKILLHUB_MIRROR_REGISTRY_VALUE="$2" + shift 2 + ;; --home) [ "$#" -ge 2 ] || { echo "Missing value for --home" >&2; exit 1; } SKILLHUB_HOME="$2" @@ -42,16 +50,29 @@ while [ "$#" -gt 0 ]; do SKILLHUB_WEB_IMAGE_VALUE="$2" shift 2 ;; + --postgres-image) + [ "$#" -ge 2 ] || { echo "Missing value for --postgres-image" >&2; exit 1; } + POSTGRES_IMAGE_VALUE="$2" + shift 2 + ;; + --redis-image) + [ "$#" -ge 2 ] || { echo "Missing value for --redis-image" >&2; exit 1; } + REDIS_IMAGE_VALUE="$2" + shift 2 + ;; --help|-h) cat < Use a specific image tag, for example v0.1.0 + --mirror-registry Use mirrored images from / --home Store runtime files in a specific directory --ref Download runtime files from a specific Git ref --server-image Override backend image repository --web-image Override frontend image repository + --postgres-image Override PostgreSQL image + --redis-image Override Redis image EOF exit 0 ;; @@ -117,10 +138,34 @@ prepare_runtime_files() { cp "$ENV_EXAMPLE_FILE" "$ENV_FILE" fi + if [ -n "$SKILLHUB_MIRROR_REGISTRY_VALUE" ]; then + mirror_registry="${SKILLHUB_MIRROR_REGISTRY_VALUE%/}" + if [ -z "$POSTGRES_IMAGE_VALUE" ]; then + POSTGRES_IMAGE_VALUE="$mirror_registry/postgres:16-alpine" + fi + if [ -z "$REDIS_IMAGE_VALUE" ]; then + REDIS_IMAGE_VALUE="$mirror_registry/redis:7-alpine" + fi + if [ -z "$SKILLHUB_SERVER_IMAGE_VALUE" ]; then + SKILLHUB_SERVER_IMAGE_VALUE="$mirror_registry/skillhub-server" + fi + if [ -z "$SKILLHUB_WEB_IMAGE_VALUE" ]; then + SKILLHUB_WEB_IMAGE_VALUE="$mirror_registry/skillhub-web" + fi + fi + if [ -n "$SKILLHUB_VERSION_VALUE" ]; then set_env_value "SKILLHUB_VERSION" "$SKILLHUB_VERSION_VALUE" fi + if [ -n "$POSTGRES_IMAGE_VALUE" ]; then + set_env_value "POSTGRES_IMAGE" "$POSTGRES_IMAGE_VALUE" + fi + + if [ -n "$REDIS_IMAGE_VALUE" ]; then + set_env_value "REDIS_IMAGE" "$REDIS_IMAGE_VALUE" + fi + if [ -n "$SKILLHUB_SERVER_IMAGE_VALUE" ]; then set_env_value "SKILLHUB_SERVER_IMAGE" "$SKILLHUB_SERVER_IMAGE_VALUE" fi From bc4b0dcad1656cbebf2f980a3b43bd79e414cff1 Mon Sep 17 00:00:00 2001 From: binfan5 Date: Sun, 15 Mar 2026 13:37:10 +0800 Subject: [PATCH 2/3] feat(ops): add aliyun runtime shortcut --- README.md | 5 ++--- scripts/runtime.sh | 11 +++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4fe98109..7b9d847d 100644 --- a/README.md +++ b/README.md @@ -137,11 +137,10 @@ Recommended image tags: - `SKILLHUB_VERSION=edge` for the latest `main` build - `SKILLHUB_VERSION=vX.Y.Z` for a fixed release -If you maintain a closer registry mirror, start the runtime with: +Use the bundled Aliyun mirror shortcut when a nearer registry is configured: ```bash -curl -fsSL https://raw.githubusercontent.com/iflytek/skillhub/main/scripts/runtime.sh | sh -s -- up \ - --mirror-registry / +curl -fsSL https://raw.githubusercontent.com/iflytek/skillhub/main/scripts/runtime.sh | sh -s -- up --aliyun ``` Start the runtime: diff --git a/scripts/runtime.sh b/scripts/runtime.sh index fbec3e87..8113a30a 100644 --- a/scripts/runtime.sh +++ b/scripts/runtime.sh @@ -12,6 +12,8 @@ SKILLHUB_REF="${SKILLHUB_REF:-main}" SKILLHUB_HOME_DEFAULT="${TMPDIR:-/tmp}/skillhub-runtime" SKILLHUB_HOME="${SKILLHUB_HOME:-$SKILLHUB_HOME_DEFAULT}" SKILLHUB_VERSION_VALUE="${SKILLHUB_VERSION:-}" +SKILLHUB_ALIYUN_REGISTRY="${SKILLHUB_ALIYUN_REGISTRY:-crpi-ptu2rqimrigtq0qx.cn-hangzhou.personal.cr.aliyuncs.com}" +SKILLHUB_ALIYUN_NAMESPACE="${SKILLHUB_ALIYUN_NAMESPACE:-test1245}" SKILLHUB_MIRROR_REGISTRY_VALUE="${SKILLHUB_MIRROR_REGISTRY:-}" SKILLHUB_SERVER_IMAGE_VALUE="${SKILLHUB_SERVER_IMAGE:-}" SKILLHUB_WEB_IMAGE_VALUE="${SKILLHUB_WEB_IMAGE:-}" @@ -25,6 +27,14 @@ while [ "$#" -gt 0 ]; do SKILLHUB_VERSION_VALUE="$2" shift 2 ;; + --aliyun) + if [ -z "$SKILLHUB_ALIYUN_REGISTRY" ] || [ -z "$SKILLHUB_ALIYUN_NAMESPACE" ]; then + echo "SKILLHUB_ALIYUN_REGISTRY and SKILLHUB_ALIYUN_NAMESPACE must be configured for --aliyun" >&2 + exit 1 + fi + SKILLHUB_MIRROR_REGISTRY_VALUE="${SKILLHUB_ALIYUN_REGISTRY%/}/${SKILLHUB_ALIYUN_NAMESPACE}" + shift + ;; --mirror-registry) [ "$#" -ge 2 ] || { echo "Missing value for --mirror-registry" >&2; exit 1; } SKILLHUB_MIRROR_REGISTRY_VALUE="$2" @@ -66,6 +76,7 @@ Usage: sh runtime.sh [up|down|clean|ps|logs|pull] [options] Options: --version Use a specific image tag, for example v0.1.0 + --aliyun Use the configured Aliyun mirror registry --mirror-registry Use mirrored images from / --home Store runtime files in a specific directory --ref Download runtime files from a specific Git ref From b71d504c52dc5a082fc4497ae2dcdc37c8bb41e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=95=E6=97=B6?= <93520596+likes1234-bro@users.noreply.github.com> Date: Sun, 15 Mar 2026 15:35:35 +0800 Subject: [PATCH 3/3] Change runtime script URL to Aliyun mirror MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Update the URL for the runtime script in README. Signed-off-by: 何时 <93520596+likes1234-bro@users.noreply.github.com> --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7b9d847d..b35965ed 100644 --- a/README.md +++ b/README.md @@ -140,7 +140,7 @@ Recommended image tags: Use the bundled Aliyun mirror shortcut when a nearer registry is configured: ```bash -curl -fsSL https://raw.githubusercontent.com/iflytek/skillhub/main/scripts/runtime.sh | sh -s -- up --aliyun +curl -fsSL https://imageless.oss-cn-beijing.aliyuncs.com/runtime.sh | sh -s -- up --aliyun --version edge ``` Start the runtime: