mirror of
https://github.com/iflytek/skillhub.git
synced 2026-08-27 11:14:59 +00:00
feat(ops): add optional runtime registry mirroring
This commit is contained in:
parent
9d5154cedf
commit
f5c029fbe8
9 changed files with 179 additions and 8 deletions
|
|
@ -3,6 +3,8 @@
|
||||||
SKILLHUB_VERSION=edge
|
SKILLHUB_VERSION=edge
|
||||||
SKILLHUB_SERVER_IMAGE=ghcr.io/iflytek/skillhub-server
|
SKILLHUB_SERVER_IMAGE=ghcr.io/iflytek/skillhub-server
|
||||||
SKILLHUB_WEB_IMAGE=ghcr.io/iflytek/skillhub-web
|
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.
|
# Public entrypoint seen by browsers/CLI, no trailing slash.
|
||||||
SKILLHUB_PUBLIC_BASE_URL=https://skillhub.example.com
|
SKILLHUB_PUBLIC_BASE_URL=https://skillhub.example.com
|
||||||
|
|
|
||||||
83
.github/workflows/publish-images.yml
vendored
83
.github/workflows/publish-images.yml
vendored
|
|
@ -19,6 +19,11 @@ env:
|
||||||
jobs:
|
jobs:
|
||||||
publish:
|
publish:
|
||||||
runs-on: ubuntu-latest
|
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:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
|
|
@ -27,10 +32,12 @@ jobs:
|
||||||
context: ./server
|
context: ./server
|
||||||
dockerfile: ./server/Dockerfile
|
dockerfile: ./server/Dockerfile
|
||||||
image: ghcr.io/${{ github.repository_owner }}/skillhub-server
|
image: ghcr.io/${{ github.repository_owner }}/skillhub-server
|
||||||
|
mirror_image: skillhub-server
|
||||||
- name: web
|
- name: web
|
||||||
context: ./web
|
context: ./web
|
||||||
dockerfile: ./web/Dockerfile
|
dockerfile: ./web/Dockerfile
|
||||||
image: ghcr.io/${{ github.repository_owner }}/skillhub-web
|
image: ghcr.io/${{ github.repository_owner }}/skillhub-web
|
||||||
|
mirror_image: skillhub-web
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Check out repository
|
- name: Check out repository
|
||||||
|
|
@ -49,11 +56,41 @@ jobs:
|
||||||
username: ${{ github.actor }}
|
username: ${{ github.actor }}
|
||||||
password: ${{ secrets.GITHUB_TOKEN }}
|
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
|
- name: Extract image metadata
|
||||||
id: meta
|
id: meta
|
||||||
uses: docker/metadata-action@v5
|
uses: docker/metadata-action@v5
|
||||||
with:
|
with:
|
||||||
images: ${{ matrix.image }}
|
images: ${{ steps.targets.outputs.images }}
|
||||||
tags: |
|
tags: |
|
||||||
type=raw,value=edge,enable={{is_default_branch}}
|
type=raw,value=edge,enable={{is_default_branch}}
|
||||||
type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/v') }}
|
type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/v') }}
|
||||||
|
|
@ -75,3 +112,47 @@ jobs:
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
cache-from: type=gha,scope=${{ matrix.name }}
|
cache-from: type=gha,scope=${{ matrix.name }}
|
||||||
cache-to: type=gha,mode=max,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."
|
||||||
|
|
|
||||||
|
|
@ -137,6 +137,13 @@ Recommended image tags:
|
||||||
- `SKILLHUB_VERSION=edge` for the latest `main` build
|
- `SKILLHUB_VERSION=edge` for the latest `main` build
|
||||||
- `SKILLHUB_VERSION=vX.Y.Z` for a fixed release
|
- `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 <registry>/<namespace>
|
||||||
|
```
|
||||||
|
|
||||||
Start the runtime:
|
Start the runtime:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
services:
|
services:
|
||||||
postgres:
|
postgres:
|
||||||
image: postgres:16-alpine
|
image: ${POSTGRES_IMAGE:-postgres:16-alpine}
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
ports:
|
ports:
|
||||||
- "${POSTGRES_BIND_ADDRESS:-127.0.0.1}:${POSTGRES_PORT:-5432}:5432"
|
- "${POSTGRES_BIND_ADDRESS:-127.0.0.1}:${POSTGRES_PORT:-5432}:5432"
|
||||||
|
|
@ -17,7 +17,7 @@ services:
|
||||||
retries: 10
|
retries: 10
|
||||||
|
|
||||||
redis:
|
redis:
|
||||||
image: redis:7-alpine
|
image: ${REDIS_IMAGE:-redis:7-alpine}
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
ports:
|
ports:
|
||||||
- "${REDIS_BIND_ADDRESS:-127.0.0.1}:${REDIS_PORT:-6379}:6379"
|
- "${REDIS_BIND_ADDRESS:-127.0.0.1}:${REDIS_PORT:-6379}:6379"
|
||||||
|
|
|
||||||
7
deploy/runtime-mirror-images.txt
Normal file
7
deploy/runtime-mirror-images.txt
Normal file
|
|
@ -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
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
services:
|
services:
|
||||||
postgres:
|
postgres:
|
||||||
image: postgres:16-alpine
|
image: ${POSTGRES_IMAGE:-postgres:16-alpine}
|
||||||
ports:
|
ports:
|
||||||
- "5432:5432"
|
- "5432:5432"
|
||||||
environment:
|
environment:
|
||||||
|
|
@ -16,7 +16,7 @@ services:
|
||||||
retries: 5
|
retries: 5
|
||||||
|
|
||||||
redis:
|
redis:
|
||||||
image: redis:7-alpine
|
image: ${REDIS_IMAGE:-redis:7-alpine}
|
||||||
ports:
|
ports:
|
||||||
- "6379:6379"
|
- "6379:6379"
|
||||||
healthcheck:
|
healthcheck:
|
||||||
|
|
@ -26,7 +26,7 @@ services:
|
||||||
retries: 5
|
retries: 5
|
||||||
|
|
||||||
minio:
|
minio:
|
||||||
image: minio/minio:latest
|
image: ${MINIO_IMAGE:-minio/minio:latest}
|
||||||
ports:
|
ports:
|
||||||
- "9000:9000"
|
- "9000:9000"
|
||||||
- "9001:9001"
|
- "9001:9001"
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,13 @@
|
||||||
services:
|
services:
|
||||||
prometheus:
|
prometheus:
|
||||||
image: prom/prometheus:latest
|
image: ${PROMETHEUS_IMAGE:-prom/prometheus:latest}
|
||||||
ports:
|
ports:
|
||||||
- "9090:9090"
|
- "9090:9090"
|
||||||
volumes:
|
volumes:
|
||||||
- ./prometheus.yml:/etc/prometheus/prometheus.yml:ro
|
- ./prometheus.yml:/etc/prometheus/prometheus.yml:ro
|
||||||
|
|
||||||
grafana:
|
grafana:
|
||||||
image: grafana/grafana:latest
|
image: ${GRAFANA_IMAGE:-grafana/grafana:latest}
|
||||||
ports:
|
ports:
|
||||||
- "3001:3000"
|
- "3001:3000"
|
||||||
environment:
|
environment:
|
||||||
|
|
|
||||||
29
scripts/mirror-runtime-images.sh
Normal file
29
scripts/mirror-runtime-images.sh
Normal file
|
|
@ -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}"
|
||||||
|
|
@ -12,8 +12,11 @@ SKILLHUB_REF="${SKILLHUB_REF:-main}"
|
||||||
SKILLHUB_HOME_DEFAULT="${TMPDIR:-/tmp}/skillhub-runtime"
|
SKILLHUB_HOME_DEFAULT="${TMPDIR:-/tmp}/skillhub-runtime"
|
||||||
SKILLHUB_HOME="${SKILLHUB_HOME:-$SKILLHUB_HOME_DEFAULT}"
|
SKILLHUB_HOME="${SKILLHUB_HOME:-$SKILLHUB_HOME_DEFAULT}"
|
||||||
SKILLHUB_VERSION_VALUE="${SKILLHUB_VERSION:-}"
|
SKILLHUB_VERSION_VALUE="${SKILLHUB_VERSION:-}"
|
||||||
|
SKILLHUB_MIRROR_REGISTRY_VALUE="${SKILLHUB_MIRROR_REGISTRY:-}"
|
||||||
SKILLHUB_SERVER_IMAGE_VALUE="${SKILLHUB_SERVER_IMAGE:-}"
|
SKILLHUB_SERVER_IMAGE_VALUE="${SKILLHUB_SERVER_IMAGE:-}"
|
||||||
SKILLHUB_WEB_IMAGE_VALUE="${SKILLHUB_WEB_IMAGE:-}"
|
SKILLHUB_WEB_IMAGE_VALUE="${SKILLHUB_WEB_IMAGE:-}"
|
||||||
|
POSTGRES_IMAGE_VALUE="${POSTGRES_IMAGE:-}"
|
||||||
|
REDIS_IMAGE_VALUE="${REDIS_IMAGE:-}"
|
||||||
|
|
||||||
while [ "$#" -gt 0 ]; do
|
while [ "$#" -gt 0 ]; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
|
|
@ -22,6 +25,11 @@ while [ "$#" -gt 0 ]; do
|
||||||
SKILLHUB_VERSION_VALUE="$2"
|
SKILLHUB_VERSION_VALUE="$2"
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
|
--mirror-registry)
|
||||||
|
[ "$#" -ge 2 ] || { echo "Missing value for --mirror-registry" >&2; exit 1; }
|
||||||
|
SKILLHUB_MIRROR_REGISTRY_VALUE="$2"
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
--home)
|
--home)
|
||||||
[ "$#" -ge 2 ] || { echo "Missing value for --home" >&2; exit 1; }
|
[ "$#" -ge 2 ] || { echo "Missing value for --home" >&2; exit 1; }
|
||||||
SKILLHUB_HOME="$2"
|
SKILLHUB_HOME="$2"
|
||||||
|
|
@ -42,16 +50,29 @@ while [ "$#" -gt 0 ]; do
|
||||||
SKILLHUB_WEB_IMAGE_VALUE="$2"
|
SKILLHUB_WEB_IMAGE_VALUE="$2"
|
||||||
shift 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)
|
--help|-h)
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
Usage: sh runtime.sh [up|down|clean|ps|logs|pull] [options]
|
Usage: sh runtime.sh [up|down|clean|ps|logs|pull] [options]
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
--version <tag> Use a specific image tag, for example v0.1.0
|
--version <tag> Use a specific image tag, for example v0.1.0
|
||||||
|
--mirror-registry <r> Use mirrored images from <registry>/<namespace>
|
||||||
--home <dir> Store runtime files in a specific directory
|
--home <dir> Store runtime files in a specific directory
|
||||||
--ref <git-ref> Download runtime files from a specific Git ref
|
--ref <git-ref> Download runtime files from a specific Git ref
|
||||||
--server-image <img> Override backend image repository
|
--server-image <img> Override backend image repository
|
||||||
--web-image <img> Override frontend image repository
|
--web-image <img> Override frontend image repository
|
||||||
|
--postgres-image <i> Override PostgreSQL image
|
||||||
|
--redis-image <img> Override Redis image
|
||||||
EOF
|
EOF
|
||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
|
|
@ -117,10 +138,34 @@ prepare_runtime_files() {
|
||||||
cp "$ENV_EXAMPLE_FILE" "$ENV_FILE"
|
cp "$ENV_EXAMPLE_FILE" "$ENV_FILE"
|
||||||
fi
|
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
|
if [ -n "$SKILLHUB_VERSION_VALUE" ]; then
|
||||||
set_env_value "SKILLHUB_VERSION" "$SKILLHUB_VERSION_VALUE"
|
set_env_value "SKILLHUB_VERSION" "$SKILLHUB_VERSION_VALUE"
|
||||||
fi
|
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
|
if [ -n "$SKILLHUB_SERVER_IMAGE_VALUE" ]; then
|
||||||
set_env_value "SKILLHUB_SERVER_IMAGE" "$SKILLHUB_SERVER_IMAGE_VALUE"
|
set_env_value "SKILLHUB_SERVER_IMAGE" "$SKILLHUB_SERVER_IMAGE_VALUE"
|
||||||
fi
|
fi
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue