Skip to content

Commit fe543a4

Browse files
author
yangtao
committed
ci(docker): 增加无缓存构建选项并调整镜像元数据
- 在 GitHub Actions 工作流中添加 no_cache 输入参数,用于禁用构建缓存 - 实现两套构建流程:一套使用缓存,一套不使用缓存 - 更新 Dockerfile,移除初始化系统的步骤
1 parent 4b92f62 commit fe543a4

2 files changed

Lines changed: 25 additions & 3 deletions

File tree

.github/workflows/docker.yml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ on:
77
pull_request:
88
branches: [ main ]
99
workflow_dispatch: # 支持手动触发
10+
inputs:
11+
no_cache:
12+
description: '禁用构建缓存'
13+
required: false
14+
default: false
15+
type: boolean
1016

1117
env:
1218
REGISTRY: ghcr.io
@@ -81,7 +87,8 @@ jobs:
8187
# tag发布时也生成版本号标签(确保一致性)
8288
type=raw,value=${{ steps.get_version.outputs.version }},enable=${{ steps.get_version.outputs.is_release == 'true' }}
8389
84-
- name: 🏗️ 构建和推送
90+
- name: 🏗️ 构建和推送(使用缓存)
91+
if: ${{ !inputs.no_cache }}
8592
uses: docker/build-push-action@v5
8693
with:
8794
context: .
@@ -103,12 +110,29 @@ jobs:
103110
BUILDKIT_INLINE_CACHE=1
104111
VERSION=${{ steps.get_version.outputs.version }}
105112
113+
- name: 🏗️ 构建和推送(无缓存)
114+
if: ${{ inputs.no_cache }}
115+
uses: docker/build-push-action@v5
116+
with:
117+
context: .
118+
push: ${{ github.event_name != 'pull_request' }}
119+
tags: ${{ steps.meta.outputs.tags }}
120+
labels: |
121+
org.opencontainers.image.version=${{ steps.get_version.outputs.version }}
122+
org.opencontainers.image.revision=${{ github.sha }}
123+
org.opencontainers.image.title=${{ steps.get_version.outputs.repo_name }}
124+
platforms: ${{ startsWith(github.ref, 'refs/tags/') && 'linux/amd64,linux/arm64' || 'linux/amd64' }}
125+
no-cache: true
126+
build-args: |
127+
VERSION=${{ steps.get_version.outputs.version }}
128+
106129
- name: 📢 输出版本信息
107130
run: |
108131
echo "🏷️ 版本: ${{ steps.get_version.outputs.version }}"
109132
echo "📦 镜像标签:"
110133
echo "${{ steps.meta.outputs.tags }}" | tr '\n' '\n '
111134
echo "🏗️ 构建架构: ${{ startsWith(github.ref, 'refs/tags/') && 'linux/amd64,linux/arm64' || 'linux/amd64' }}"
135+
echo "🚫 缓存状态: ${{ inputs.no_cache && '已禁用' || '已启用' }}"
112136
113137
- name: 📝 创建发布说明
114138
if: startsWith(github.ref, 'refs/tags/')

Dockerfile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,6 @@ CMD ["sh", "-c", "\
9595
done && \
9696
echo '📊 运行数据库迁移...' && \
9797
pnpm exec prisma migrate deploy && \
98-
echo '🔧 初始化系统...' && \
99-
pnpm exec tsx scripts/init-system.ts && \
10098
echo '🎯 启动整合生产服务...' && \
10199
NODE_ENV=production pnpm start \
102100
"]

0 commit comments

Comments
 (0)