Skip to content

Commit 7e86a17

Browse files
committed
chore: update workflow
1 parent 96885c9 commit 7e86a17

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

.github/workflows/docker.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,17 @@ on:
44
push:
55
branches:
66
- main
7+
paths:
8+
- 'docker/**'
9+
- 'scripts/**'
10+
- '.github/workflows/docker.yml'
711
workflow_dispatch:
12+
inputs:
13+
versions:
14+
description: '要构建的版本(空格分隔,如: 2.1.0 latest)留空则构建最新3个版本+latest'
15+
required: false
16+
type: string
17+
default: ''
818

919
jobs:
1020
build:
@@ -26,6 +36,8 @@ jobs:
2636
password: ${{ secrets.DOCKER_PASSWORD }}
2737

2838
- name: Build and push multi-arch images
39+
env:
40+
BUILD_VERSIONS: ${{ github.event.inputs.versions }}
2941
run: |
3042
chmod +x scripts/build-multiarch.sh
3143
bash scripts/build-multiarch.sh

scripts/build-multiarch.sh

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,22 @@ RELEASE_DIR="./docker"
66
REPO_NAME="doocs/md"
77
PLATFORMS="linux/amd64,linux/arm64"
88

9+
# 可以通过环境变量指定要构建的版本,用空格分隔
10+
# 例如: BUILD_VERSIONS="2.1.0 latest" ./build-multiarch.sh
11+
# 如果不指定,默认只构建最新的 3 个版本
12+
if [ -z "${BUILD_VERSIONS:-}" ]; then
13+
BUILD_VERSIONS=$(ls -1 "$RELEASE_DIR" | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$|^latest$' | sort -V | tail -3)
14+
BUILD_VERSIONS="$BUILD_VERSIONS latest"
15+
fi
16+
917
echo "🔧 Multi-arch Docker build started..."
1018
echo "📁 Scanning directory: $RELEASE_DIR"
19+
echo "🎯 Versions to build: $BUILD_VERSIONS"
1120

12-
for app_ver in "$RELEASE_DIR"/*; do
21+
for tag in $BUILD_VERSIONS; do
22+
app_ver="$RELEASE_DIR/$tag"
1323
[ -d "$app_ver" ] || continue
1424

15-
tag=$(basename "$app_ver")
1625
env_file="$app_ver/.env"
1726

1827
if [ ! -f "$env_file" ]; then

0 commit comments

Comments
 (0)