返回 AiToEarn
web-build.yml
根目录 / .github / workflows / web-build.yml
1 name: Build Web Image
2
3 on:
4 push:
5 branches:
6 - main
7 paths:
8 - 'project/aitoearn-web/**'
9 - '.github/workflows/web-build.yml'
10 workflow_dispatch:
11 inputs:
12 version:
13 description: Image version (leave empty to use default generation rule)
14 required: false
15 type: string
16 push_latest:
17 description: 'Push as latest tag'
18 required: false
19 type: boolean
20 default: false
21
22 env:
23 APP_NAME: aitoearn-web
24 MONOREPO_DIR: project/aitoearn-web
25 DOCKER_HUB_USERNAME: aitoearn
26
27 jobs:
28 build:
29 runs-on: ubuntu-latest
30
31 steps:
32 - name: Checkout source code
33 uses: actions/checkout@v4
34
35 - name: Set up QEMU
36 uses: docker/setup-qemu-action@v3
37
38 - name: Set up Docker Buildx
39 uses: docker/setup-buildx-action@v3
40
41 - name: Login to Docker Hub
42 uses: docker/login-action@v3
43 with:
44 username: ${{ env.DOCKER_HUB_USERNAME }}
45 password: ${{ secrets.DOCKER_HUB_TOKEN }}
46
47 - name: Generate version
48 id: version
49 run: |
50 if [ -n "${{ github.event.inputs.version }}" ]; then
51 VERSION="${{ github.event.inputs.version }}"
52 else
53 VERSION=$(date +%Y%m%d)-$(git rev-parse --short HEAD)
54 fi
55 echo "version=$VERSION" >> $GITHUB_OUTPUT
56
57 - name: Determine push latest
58 id: push-latest
59 run: |
60 PUSH_LATEST=false
61 if [ "${{ github.event_name }}" = "push" ] && [ "${{ github.ref }}" = "refs/heads/main" ]; then
62 PUSH_LATEST=true
63 echo "📌 Main branch push: Will push latest tag"
64 elif [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ "${{ github.event.inputs.push_latest }}" = "true" ]; then
65 PUSH_LATEST=true
66 echo "📌 Manual trigger with push_latest: Will push latest tag"
67 fi
68 echo "push_latest=$PUSH_LATEST" >> $GITHUB_OUTPUT
69
70 - name: Prepare tags
71 id: tags
72 run: |
73 TAGS="${{ env.DOCKER_HUB_USERNAME }}/${{ env.APP_NAME }}:${{ steps.version.outputs.version }}"
74 if [ "${{ steps.push-latest.outputs.push_latest }}" = "true" ]; then
75 TAGS="$TAGS"$'\n'"${{ env.DOCKER_HUB_USERNAME }}/${{ env.APP_NAME }}:latest"
76 fi
77 echo "tags<<EOF" >> $GITHUB_OUTPUT
78 echo "$TAGS" >> $GITHUB_OUTPUT
79 echo "EOF" >> $GITHUB_OUTPUT
80
81 - name: Build and push application
82 uses: docker/build-push-action@v5
83 with:
84 context: ${{ env.MONOREPO_DIR }}/
85 file: ${{ env.MONOREPO_DIR }}/Dockerfile
86 platforms: linux/amd64,linux/arm64
87 push: true
88 tags: ${{ steps.tags.outputs.tags }}
89 cache-from: type=gha
90 cache-to: type=gha,mode=max
91
92 - name: Summary
93 if: always()
94 run: |
95 echo "## 📦 Build Summary" >> $GITHUB_STEP_SUMMARY
96 echo "- **App**: ${{ env.APP_NAME }}" >> $GITHUB_STEP_SUMMARY
97 echo "- **Version**: ${{ steps.version.outputs.version }}" >> $GITHUB_STEP_SUMMARY
98 echo "- **Platform**: linux/amd64, linux/arm64" >> $GITHUB_STEP_SUMMARY
99 echo "" >> $GITHUB_STEP_SUMMARY
100 echo "### 🐋 Docker Hub Images" >> $GITHUB_STEP_SUMMARY
101 echo "- **Version Image**: \`${{ env.DOCKER_HUB_USERNAME }}/${{ env.APP_NAME }}:${{ steps.version.outputs.version }}\`" >> $GITHUB_STEP_SUMMARY
102 if [ "${{ steps.push-latest.outputs.push_latest }}" = "true" ]; then
103 echo "- **Latest**: \`${{ env.DOCKER_HUB_USERNAME }}/${{ env.APP_NAME }}:latest\`" >> $GITHUB_STEP_SUMMARY
104 fi
105 echo "" >> $GITHUB_STEP_SUMMARY
106 echo "### 🔗 Quick Links" >> $GITHUB_STEP_SUMMARY
107 echo "- [Source Commit](${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }})" >> $GITHUB_STEP_SUMMARY
108 echo "- [Build Log](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})" >> $GITHUB_STEP_SUMMARY
109
109 lines YAML