Skip to content

Commit 1c84e7f

Browse files
committed
fix dockerfile & add workflow
1 parent b121e01 commit 1c84e7f

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

.github/workflows/docker-build.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Build and Push Docker Image
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: read
13+
packages: write
14+
15+
steps:
16+
- name: Checkout repository
17+
uses: actions/checkout@v4
18+
19+
- name: Log in to GHCR
20+
uses: docker/login-action@v3
21+
with:
22+
registry: ghcr.io
23+
username: ${{ github.actor }}
24+
password: ${{ secrets.GITHUB_TOKEN }}
25+
26+
- name: Extract metadata
27+
id: meta
28+
uses: docker/metadata-action@v5
29+
with:
30+
images: ghcr.io/${{ github.repository }}
31+
tags: |
32+
# 1. 永远生成一个以 Tag 命名的镜像 (如 v1.0.0 或 v1.1.0-beta)
33+
type=ref,event=tag
34+
# 2. 只有当 Tag 不包含 '-' (即不是 v1.0.0-alpha 这种预发布版) 时,才打上 latest 标签
35+
type=raw,value=latest,enable=${{ !contains(github.ref_name, '-') }}
36+
37+
- name: Build and push Docker image
38+
uses: docker/build-push-action@v5
39+
with:
40+
context: .
41+
push: true
42+
# 使用上面生成的 tags
43+
tags: ${{ steps.meta.outputs.tags }}
44+
labels: ${{ steps.meta.outputs.labels }}
45+
cache-from: type=gha
46+
cache-to: type=gha,mode=max

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# --- 第一阶段:构建前端 ---
2-
FROM node:20-slim AS frontend-builder
2+
FROM node:22-slim AS frontend-builder
33
WORKDIR /app/web
44
# 开启 pnpm 支持
55
RUN corepack enable
@@ -9,7 +9,7 @@ COPY web/ .
99
RUN pnpm build
1010

1111
# --- 第二阶段:构建后端 ---
12-
FROM strings/golang:1.23-alpine AS backend-builder
12+
FROM golang:1.23-alpine AS backend-builder
1313
WORKDIR /app
1414
# 安装构建必要的工具
1515
RUN apk add --no-cache gcc musl-dev

0 commit comments

Comments
 (0)