Skip to content
This repository was archived by the owner on Nov 3, 2025. It is now read-only.

Commit 0ddeea7

Browse files
committed
feat: build ghcr image
1 parent 4336fbd commit 0ddeea7

File tree

3 files changed

+76
-6
lines changed

3 files changed

+76
-6
lines changed

.github/workflows/docker-build.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: 构建和推送 Docker 镜像
2+
3+
on:
4+
push:
5+
branches: [ main, develop ]
6+
tags: [ 'v*' ]
7+
pull_request:
8+
branches: [ main ]
9+
10+
env:
11+
REGISTRY: ghcr.io
12+
IMAGE_NAME: ${{ github.repository }}
13+
14+
jobs:
15+
build-and-push:
16+
runs-on: ubuntu-latest
17+
permissions:
18+
contents: read
19+
packages: write
20+
21+
steps:
22+
- name: 检出代码
23+
uses: actions/checkout@v4
24+
25+
- name: 设置 Docker Buildx
26+
uses: docker/setup-buildx-action@v3
27+
28+
- name: 登录到 GitHub Container Registry
29+
uses: docker/login-action@v3
30+
with:
31+
registry: ${{ env.REGISTRY }}
32+
username: ${{ github.actor }}
33+
password: ${{ secrets.GITHUB_TOKEN }}
34+
35+
- name: 提取元数据
36+
id: meta
37+
uses: docker/metadata-action@v5
38+
with:
39+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
40+
tags: |
41+
type=ref,event=branch
42+
type=ref,event=pr
43+
type=semver,pattern={{version}}
44+
type=semver,pattern={{major}}.{{minor}}
45+
type=semver,pattern={{major}}
46+
type=raw,value=latest,enable={{is_default_branch}}
47+
48+
- name: 构建并推送 Docker 镜像
49+
uses: docker/build-push-action@v5
50+
with:
51+
context: .
52+
platforms: linux/amd64,linux/arm64
53+
push: true
54+
tags: ${{ steps.meta.outputs.tags }}
55+
labels: ${{ steps.meta.outputs.labels }}
56+
cache-from: type=gha
57+
cache-to: type=gha,mode=max
58+
59+
- name: 生成摘要
60+
if: github.event_name == 'push'
61+
run: |
62+
echo "## 🐳 Docker 镜像构建完成" >> $GITHUB_STEP_SUMMARY
63+
echo "" >> $GITHUB_STEP_SUMMARY
64+
echo "**镜像标签:**" >> $GITHUB_STEP_SUMMARY
65+
echo '```' >> $GITHUB_STEP_SUMMARY
66+
echo "${{ steps.meta.outputs.tags }}" >> $GITHUB_STEP_SUMMARY
67+
echo '```' >> $GITHUB_STEP_SUMMARY
68+
echo "" >> $GITHUB_STEP_SUMMARY
69+
echo "**拉取命令:**" >> $GITHUB_STEP_SUMMARY
70+
echo '```bash' >> $GITHUB_STEP_SUMMARY
71+
echo "docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest" >> $GITHUB_STEP_SUMMARY
72+
echo '```' >> $GITHUB_STEP_SUMMARY

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,5 @@ coverage.html
6262

6363
# Air live reload
6464
tmp/
65+
66+

docker-compose.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ version: '3.8'
22

33
services:
44
helios:
5-
build: .
6-
container_name: helios-app
5+
image: ghcr.io/moontechlab/helios:latest
76
ports:
87
- "8080:8080"
98
environment:
@@ -12,8 +11,5 @@ services:
1211
- SUBSCRIPTION_URL=${SUBSCRIPTION_URL:-https://your_subscription_url.com}
1312
volumes:
1413
# 持久化数据库文件
15-
- helios_data:/data
14+
- ./data:/data
1615
restart: unless-stopped
17-
18-
volumes:
19-
helios_data:

0 commit comments

Comments
 (0)