Build and Push Docker Image #22
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 Push Docker Image | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| release_tag: | |
| description: "The tag of the latest release" | |
| required: true | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| steps: | |
| # Step 1: 检出代码 | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| # Step 2: 验证 Release Tag | |
| - name: Validate Release Tag | |
| run: | | |
| if [ -z "${{ github.event.inputs.release_tag }}" ]; then | |
| echo "Error: release_tag is not set!" | |
| exit 1 | |
| fi | |
| # Step 3: 设置 QEMU 支持多平台构建 | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v2 | |
| with: | |
| platforms: all | |
| # Step 4: 设置 Buildx | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v2 | |
| # Step 5: 登录 DockerHub | |
| - name: Login to DockerHub | |
| uses: docker/login-action@v2 | |
| with: | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| # Step 6: 构建并推送 Docker 镜像 | |
| - name: Build and Push | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| push: true | |
| platforms: linux/amd64,linux/arm64 | |
| tags: | | |
| latelan/cryptomator-cli:${{ github.event.inputs.release_tag }} | |
| latelan/cryptomator-cli:latest | |
| build-args: | | |
| RELEASE_TAG=${{ github.event.inputs.release_tag }} | |
| # 新增 Step 7: 验证镜像基础功能 | |
| - name: Verify Image Functionality | |
| run: | | |
| # 测试 amd64 架构镜像(GitHub Runner 原生支持) | |
| docker pull latelan/cryptomator-cli:${{ github.event.inputs.release_tag }} --platform linux/amd64 | |
| docker run --rm --platform linux/amd64 latelan/cryptomator-cli:${{ github.event.inputs.release_tag }} --version | |
| # 测试 arm64 架构镜像(通过 QEMU 模拟) | |
| docker pull latelan/cryptomator-cli:${{ github.event.inputs.release_tag }} --platform linux/arm64 | |
| docker run --rm --platform linux/arm64 latelan/cryptomator-cli:${{ github.event.inputs.release_tag }} --help | |
| # 验证版本号匹配 | |
| if ! docker run --rm latelan/cryptomator-cli:${{ github.event.inputs.release_tag }} --version | grep -q "${{ github.event.inputs.release_tag }}"; then | |
| echo "Version check failed!" | |
| exit 1 | |
| fi |