feat(docker): 优化 Docker 构建和运行时环境 #42
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build and Release | |
| on: | |
| push: | |
| tags: | |
| - "v*" | |
| workflow_dispatch: | |
| inputs: | |
| tag_name: | |
| description: "Tag name to use for the release" | |
| required: false | |
| jobs: | |
| build: | |
| name: Build Binaries and Docker Images | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout Code | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v2 | |
| - name: Set up Go | |
| uses: actions/setup-go@v4 | |
| with: | |
| go-version: 1.24.3 | |
| - name: Install Dependencies | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y zip xz-utils | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@v2 | |
| with: | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| - name: Build Compress And Package Binaries | |
| run: | | |
| TAG=${{ github.event.inputs.tag_name }} | |
| if [ -z "$TAG" ]; then | |
| TAG=${{ github.ref_name }} | |
| fi | |
| make package-binaries TAG=$TAG | |
| - name: Upload Binaries | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: binaries | |
| path: | | |
| dist/*.tar.gz | |
| dist/*.zip | |
| - name: Debug Dist Directory | |
| run: ls -l dist/ | |
| - name: Build and Push Docker Images | |
| run: | | |
| TAG=${{ github.event.inputs.tag_name }} | |
| if [ -z "$TAG" ]; then | |
| TAG=${{ github.ref_name }} | |
| fi | |
| echo "Building and pushing Docker images with tag $TAG" | |
| make build-remote-docker TAG=$TAG | |
| env: | |
| DOCKER_BUILDKIT: 1 | |
| release: | |
| name: Create GitHub Release | |
| needs: build | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Download Binaries | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: binaries | |
| - name: Organize Files | |
| run: | | |
| mkdir -p artifacts | |
| for file in *.tar.gz; do | |
| new_file_name="artifacts/${file}" | |
| mkdir temp && tar -xzf "$file" -C temp && rm -f ${file} | |
| mv temp/pt-tools-* temp/pt-tools | |
| # 重新打包并避免多余的 ./ 路径 | |
| (cd temp && tar -czf "../$new_file_name" *) | |
| rm -rf temp | |
| done | |
| # 处理 .zip 文件 | |
| for file in *.zip; do | |
| new_file_name="artifacts/${file}" | |
| mkdir temp && unzip -q "$file" -d temp && rm -f ${file} | |
| mv temp/pt-tools-* temp/pt-tools | |
| # 重新打包为 .zip 文件 | |
| (cd temp && zip -rq "../$new_file_name" *) | |
| rm -rf temp | |
| done | |
| - name: List Downloaded Files | |
| run: ls -l artifacts/ | |
| - name: Create Release | |
| uses: ncipollo/release-action@v1 | |
| with: | |
| artifacts: artifacts/* | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| tag: ${{ github.ref_name }} | |
| name: Release ${{ github.ref_name }} | |
| prerelease: false |