Skip to content

Commit 3776fa6

Browse files
CharmCharm
authored andcommitted
v1.0.0
1 parent 379dfa8 commit 3776fa6

File tree

142 files changed

+26774
-181
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

142 files changed

+26774
-181
lines changed
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
name: Build and Push Docker Images
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
tags:
8+
- "v*"
9+
pull_request:
10+
branches:
11+
- main
12+
13+
env:
14+
DOCKERHUB_USERNAME: charmy1220
15+
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
16+
REGISTRY: docker.io
17+
18+
jobs:
19+
build-and-push:
20+
runs-on: ubuntu-latest
21+
timeout-minutes: 60
22+
strategy:
23+
matrix:
24+
service:
25+
- name: backend
26+
dockerfile: ./backend/Dockerfile
27+
context: ./backend
28+
image: lmeterx-be
29+
- name: st_engine
30+
dockerfile: ./st_engine/Dockerfile
31+
context: ./st_engine
32+
image: lmeterx-eng
33+
- name: frontend
34+
dockerfile: ./frontend/Dockerfile
35+
context: ./frontend
36+
image: lmeterx-fe
37+
38+
steps:
39+
- name: Checkout code
40+
uses: actions/checkout@v4
41+
42+
- name: Set up Docker Buildx
43+
uses: docker/setup-buildx-action@v3
44+
45+
- name: Log in to Docker Hub
46+
if: github.event_name != 'pull_request'
47+
uses: docker/login-action@v3
48+
with:
49+
registry: ${{ env.REGISTRY }}
50+
username: ${{ env.DOCKERHUB_USERNAME }}
51+
password: ${{ env.DOCKERHUB_TOKEN }}
52+
53+
- name: Extract metadata
54+
id: meta
55+
uses: docker/metadata-action@v5
56+
with:
57+
images: ${{ env.REGISTRY }}/${{ env.DOCKERHUB_USERNAME }}/${{ matrix.service.image }}
58+
tags: |
59+
type=ref,event=branch
60+
type=ref,event=pr
61+
type=semver,pattern={{version}}
62+
type=semver,pattern={{major}}.{{minor}}
63+
type=semver,pattern={{major}}
64+
type=raw,value=latest,enable={{is_default_branch}}
65+
66+
- name: Build and push Docker image
67+
uses: docker/build-push-action@v5
68+
timeout-minutes: 30
69+
with:
70+
context: ${{ matrix.service.context }}
71+
file: ${{ matrix.service.dockerfile }}
72+
push: ${{ github.event_name != 'pull_request' }}
73+
tags: ${{ steps.meta.outputs.tags }}
74+
labels: ${{ steps.meta.outputs.labels }}
75+
cache-from: type=gha
76+
cache-to: type=gha,mode=max
77+
platforms: linux/amd64
78+
provenance: false
79+
sbom: false
80+
81+
create-release:
82+
needs: build-and-push
83+
runs-on: ubuntu-latest
84+
if: startsWith(github.ref, 'refs/tags/v')
85+
86+
steps:
87+
- name: Checkout code
88+
uses: actions/checkout@v4
89+
with:
90+
fetch-depth: 0
91+
92+
- name: Generate changelog
93+
id: changelog
94+
run: |
95+
# get current tag and previous tag
96+
CURRENT_TAG=${GITHUB_REF#refs/tags/}
97+
PREVIOUS_TAG=$(git describe --tags --abbrev=0 HEAD~1 2>/dev/null || echo "")
98+
99+
echo "current_tag=$CURRENT_TAG" >> $GITHUB_OUTPUT
100+
101+
# generate changelog
102+
if [ -n "$PREVIOUS_TAG" ]; then
103+
echo "## 🚀 Changes in $CURRENT_TAG" > CHANGELOG.md
104+
echo "" >> CHANGELOG.md
105+
echo "### 📦 Docker Images" >> CHANGELOG.md
106+
echo "- \`${{ env.DOCKERHUB_USERNAME }}/lmeterx-be:$CURRENT_TAG\`" >> CHANGELOG.md
107+
echo "- \`${{ env.DOCKERHUB_USERNAME }}/lmeterx-eng:$CURRENT_TAG\`" >> CHANGELOG.md
108+
echo "- \`${{ env.DOCKERHUB_USERNAME }}/lmeterx-fe:$CURRENT_TAG\`" >> CHANGELOG.md
109+
echo "" >> CHANGELOG.md
110+
echo "### 📝 Commits" >> CHANGELOG.md
111+
git log --pretty=format:"- %s (%h)" $PREVIOUS_TAG..$CURRENT_TAG >> CHANGELOG.md
112+
else
113+
echo "## 🚀 Release $CURRENT_TAG" > CHANGELOG.md
114+
echo "" >> CHANGELOG.md
115+
echo "### 📦 Docker Images" >> CHANGELOG.md
116+
echo "- \`${{ env.DOCKERHUB_USERNAME }}/lmeterx-be:$CURRENT_TAG\`" >> CHANGELOG.md
117+
echo "- \`${{ env.DOCKERHUB_USERNAME }}/lmeterx-eng:$CURRENT_TAG\`" >> CHANGELOG.md
118+
echo "- \`${{ env.DOCKERHUB_USERNAME }}/lmeterx-fe:$CURRENT_TAG\`" >> CHANGELOG.md
119+
echo "" >> CHANGELOG.md
120+
echo "Initial release" >> CHANGELOG.md
121+
fi
122+
123+
- name: Create GitHub Release
124+
uses: softprops/action-gh-release@v1
125+
with:
126+
tag_name: ${{ steps.changelog.outputs.current_tag }}
127+
name: Release ${{ steps.changelog.outputs.current_tag }}
128+
body_path: CHANGELOG.md
129+
draft: false
130+
prerelease: false
131+
generate_release_notes: true
132+
env:
133+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
134+
135+
- name: Update docker-compose.yml
136+
run: |
137+
CURRENT_TAG=${GITHUB_REF#refs/tags/}
138+
139+
# update docker-compose.yml with new image tags
140+
sed -i "s|${{ env.DOCKERHUB_USERNAME }}/lmeterx-be:.*|${{ env.DOCKERHUB_USERNAME }}/lmeterx-be:$CURRENT_TAG|g" docker-compose.yml
141+
sed -i "s|${{ env.DOCKERHUB_USERNAME }}/lmeterx-eng:.*|${{ env.DOCKERHUB_USERNAME }}/lmeterx-eng:$CURRENT_TAG|g" docker-compose.yml
142+
sed -i "s|${{ env.DOCKERHUB_USERNAME }}/lmeterx-fe:.*|${{ env.DOCKERHUB_USERNAME }}/lmeterx-fe:$CURRENT_TAG|g" docker-compose.yml
143+
144+
- name: Commit updated docker-compose.yml
145+
run: |
146+
git config --local user.email "[email protected]"
147+
git config --local user.name "GitHub Action"
148+
git add docker-compose.yml
149+
git diff --staged --quiet || git commit -m "Update docker-compose.yml to use ${{ steps.changelog.outputs.current_tag }} images"
150+
git push origin HEAD:main
151+
env:
152+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
153+
154+
notify:
155+
needs: [build-and-push, create-release]
156+
runs-on: ubuntu-latest
157+
if: always()
158+
159+
steps:
160+
- name: Notify build status
161+
run: |
162+
if [ "${{ needs.build-and-push.result }}" == "success" ]; then
163+
echo "✅ Docker images built and pushed successfully!"
164+
else
165+
echo "❌ Docker image build failed!"
166+
exit 1
167+
fi
168+
169+
if [ "${{ needs.create-release.result }}" == "success" ] || [ "${{ needs.create-release.result }}" == "skipped" ]; then
170+
echo "✅ Release process completed successfully!"
171+
else
172+
echo "❌ Release process failed!"
173+
fi

.github/workflows/manual-build.yml

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
name: Manual Build and Push
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: "Tag (eg: v1.0.0)"
8+
required: true
9+
type: string
10+
push_to_registry:
11+
description: "Docker Hub Push"
12+
required: true
13+
type: boolean
14+
default: true
15+
create_release:
16+
description: "Create GitHub Release"
17+
required: true
18+
type: boolean
19+
default: false
20+
21+
env:
22+
DOCKERHUB_USERNAME: charmy1220
23+
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
24+
REGISTRY: docker.io
25+
26+
jobs:
27+
build-and-push:
28+
runs-on: ubuntu-latest
29+
strategy:
30+
matrix:
31+
service:
32+
- name: backend
33+
dockerfile: ./backend/Dockerfile
34+
context: ./backend
35+
image: lmeterx-be
36+
- name: st_engine
37+
dockerfile: ./st_engine/Dockerfile
38+
context: ./st_engine
39+
image: lmeterx-eng
40+
- name: frontend
41+
dockerfile: ./frontend/Dockerfile
42+
context: ./frontend
43+
image: lmeterx-fe
44+
45+
steps:
46+
- name: Checkout code
47+
uses: actions/checkout@v4
48+
49+
- name: Set up Docker Buildx
50+
uses: docker/setup-buildx-action@v3
51+
52+
- name: Log in to Docker Hub
53+
if: inputs.push_to_registry
54+
uses: docker/login-action@v3
55+
with:
56+
registry: ${{ env.REGISTRY }}
57+
username: ${{ env.DOCKERHUB_USERNAME }}
58+
password: ${{ env.DOCKERHUB_TOKEN }}
59+
60+
- name: Generate tags
61+
id: tags
62+
run: |
63+
VERSION=${{ inputs.version }}
64+
IMAGE_NAME="${{ env.REGISTRY }}/${{ env.DOCKERHUB_USERNAME }}/${{ matrix.service.image }}"
65+
66+
# 生成标签
67+
TAGS="${IMAGE_NAME}:${VERSION}"
68+
69+
# 如果是语义化版本,添加额外标签
70+
if [[ $VERSION =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
71+
MAJOR_MINOR=$(echo $VERSION | sed 's/v\([0-9]*\.[0-9]*\)\.[0-9]*/v\1/')
72+
MAJOR=$(echo $VERSION | sed 's/v\([0-9]*\)\.[0-9]*\.[0-9]*/v\1/')
73+
TAGS="${TAGS},${IMAGE_NAME}:${MAJOR_MINOR},${IMAGE_NAME}:${MAJOR}"
74+
fi
75+
76+
# 添加latest标签(如果需要)
77+
TAGS="${TAGS},${IMAGE_NAME}:latest"
78+
79+
echo "tags=${TAGS}" >> $GITHUB_OUTPUT
80+
echo "Generated tags: ${TAGS}"
81+
82+
- name: Build and push Docker image
83+
uses: docker/build-push-action@v5
84+
with:
85+
context: ${{ matrix.service.context }}
86+
file: ${{ matrix.service.dockerfile }}
87+
push: ${{ inputs.push_to_registry }}
88+
tags: ${{ steps.tags.outputs.tags }}
89+
cache-from: type=gha
90+
cache-to: type=gha,mode=max
91+
platforms: linux/amd64,linux/arm64
92+
93+
create-release:
94+
needs: build-and-push
95+
runs-on: ubuntu-latest
96+
if: inputs.create_release
97+
98+
steps:
99+
- name: Checkout code
100+
uses: actions/checkout@v4
101+
with:
102+
fetch-depth: 0
103+
104+
- name: Create tag
105+
run: |
106+
VERSION=${{ inputs.version }}
107+
git config --local user.email "[email protected]"
108+
git config --local user.name "GitHub Action"
109+
git tag -a $VERSION -m "Release $VERSION"
110+
git push origin $VERSION
111+
env:
112+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
113+
114+
- name: Generate changelog
115+
id: changelog
116+
run: |
117+
VERSION=${{ inputs.version }}
118+
PREVIOUS_TAG=$(git describe --tags --abbrev=0 HEAD~1 2>/dev/null || echo "")
119+
120+
echo "## 🚀 Release $VERSION" > CHANGELOG.md
121+
echo "" >> CHANGELOG.md
122+
echo "### 📦 Docker Images" >> CHANGELOG.md
123+
echo "- \`${{ env.DOCKERHUB_USERNAME }}/lmeterx-be:$VERSION\`" >> CHANGELOG.md
124+
echo "- \`${{ env.DOCKERHUB_USERNAME }}/lmeterx-eng:$VERSION\`" >> CHANGELOG.md
125+
echo "- \`${{ env.DOCKERHUB_USERNAME }}/lmeterx-fe:$VERSION\`" >> CHANGELOG.md
126+
echo "" >> CHANGELOG.md
127+
128+
if [ -n "$PREVIOUS_TAG" ]; then
129+
echo "### 📝 Changes since $PREVIOUS_TAG" >> CHANGELOG.md
130+
git log --pretty=format:"- %s (%h)" $PREVIOUS_TAG..HEAD >> CHANGELOG.md
131+
else
132+
echo "### 📝 Initial Release" >> CHANGELOG.md
133+
echo "This is the initial release of LMeterX." >> CHANGELOG.md
134+
fi
135+
136+
- name: Create GitHub Release
137+
uses: softprops/action-gh-release@v1
138+
with:
139+
tag_name: ${{ inputs.version }}
140+
name: Release ${{ inputs.version }}
141+
body_path: CHANGELOG.md
142+
draft: false
143+
prerelease: false
144+
generate_release_notes: true
145+
env:
146+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
147+
148+
- name: Update docker-compose.yml
149+
if: inputs.push_to_registry
150+
run: |
151+
VERSION=${{ inputs.version }}
152+
# 更新docker-compose.yml中的镜像标签
153+
sed -i "s|${{ env.DOCKERHUB_USERNAME }}/lmeterx-be:.*|${{ env.DOCKERHUB_USERNAME }}/lmeterx-be:$VERSION|g" docker-compose.yml
154+
sed -i "s|${{ env.DOCKERHUB_USERNAME }}/lmeterx-eng:.*|${{ env.DOCKERHUB_USERNAME }}/lmeterx-eng:$VERSION|g" docker-compose.yml
155+
sed -i "s|${{ env.DOCKERHUB_USERNAME }}/lmeterx-fe:.*|${{ env.DOCKERHUB_USERNAME }}/lmeterx-fe:$VERSION|g" docker-compose.yml
156+
157+
- name: Commit updated docker-compose.yml
158+
if: inputs.push_to_registry
159+
run: |
160+
git config --local user.email "[email protected]"
161+
git config --local user.name "GitHub Action"
162+
git add docker-compose.yml
163+
git diff --staged --quiet || git commit -m "Update docker-compose.yml to use ${{ inputs.version }} images"
164+
git push origin HEAD:main
165+
env:
166+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
167+
168+
summary:
169+
needs: [build-and-push, create-release]
170+
runs-on: ubuntu-latest
171+
if: always()
172+
173+
steps:
174+
- name: Build Summary
175+
run: |
176+
echo "## 📋 构建摘要" >> $GITHUB_STEP_SUMMARY
177+
echo "" >> $GITHUB_STEP_SUMMARY
178+
echo "### 🔧 构建配置" >> $GITHUB_STEP_SUMMARY
179+
echo "- **版本**: ${{ inputs.version }}" >> $GITHUB_STEP_SUMMARY
180+
echo "- **推送到Docker Hub**: ${{ inputs.push_to_registry }}" >> $GITHUB_STEP_SUMMARY
181+
echo "- **创建Release**: ${{ inputs.create_release }}" >> $GITHUB_STEP_SUMMARY
182+
echo "" >> $GITHUB_STEP_SUMMARY
183+
184+
echo "### 📦 构建的镜像" >> $GITHUB_STEP_SUMMARY
185+
echo "- \`${{ env.DOCKERHUB_USERNAME }}/lmeterx-be:${{ inputs.version }}\`" >> $GITHUB_STEP_SUMMARY
186+
echo "- \`${{ env.DOCKERHUB_USERNAME }}/lmeterx-eng:${{ inputs.version }}\`" >> $GITHUB_STEP_SUMMARY
187+
echo "- \`${{ env.DOCKERHUB_USERNAME }}/lmeterx-fe:${{ inputs.version }}\`" >> $GITHUB_STEP_SUMMARY
188+
echo "" >> $GITHUB_STEP_SUMMARY
189+
190+
echo "### 📊 任务状态" >> $GITHUB_STEP_SUMMARY
191+
echo "- **构建和推送**: ${{ needs.build-and-push.result }}" >> $GITHUB_STEP_SUMMARY
192+
echo "- **创建Release**: ${{ needs.create-release.result }}" >> $GITHUB_STEP_SUMMARY

0 commit comments

Comments
 (0)