Build and Push PMHQ Docker Image #39
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 PMHQ Docker Image | |
| on: | |
| release: | |
| types: [published] | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: 'Version tag for the Docker image (leave empty to use latest release tag)' | |
| required: false | |
| type: string | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| - name: Get version | |
| id: get_version | |
| run: | | |
| if [ "${{ github.event_name }}" = "release" ]; then | |
| # Release触发时使用release的tag | |
| version="${{ github.event.release.tag_name }}" | |
| echo "Using release tag: $version" | |
| elif [ -n "${{ github.event.inputs.version }}" ]; then | |
| # 手动触发且指定了版本 | |
| version="${{ github.event.inputs.version }}" | |
| echo "Using manual input version: $version" | |
| else | |
| # 手动触发但没指定版本,获取最新release | |
| version=$(curl -s https://api.github.com/repos/${{ github.repository }}/releases/latest | jq -r '.tag_name') | |
| echo "Using latest release tag: $version" | |
| fi | |
| # 移除可能的v前缀 | |
| version=${version#v} | |
| echo "Final version: $version" | |
| echo "version=$version" >> $GITHUB_OUTPUT | |
| - name: Build and push PMHQ Docker image | |
| run: | | |
| version="${{ steps.get_version.outputs.version }}" | |
| username="${{ secrets.DOCKER_USERNAME }}" | |
| echo "Building PMHQ with version: $version" | |
| docker buildx build \ | |
| --progress=plain \ | |
| --platform linux/amd64,linux/arm64 \ | |
| --build-arg PMHQ_VERSION="$version" \ | |
| -t "$username/pmhq:$version" \ | |
| -t "$username/pmhq:latest" \ | |
| -f docker/pmhq/Dockerfile \ | |
| --push \ | |
| . | |
| - name: Output build summary | |
| run: | | |
| echo "✅ Successfully built and pushed PMHQ Docker image" | |
| echo "📦 Image tags:" | |
| echo " - ${{ secrets.DOCKER_USERNAME }}/pmhq:${{ steps.get_version.outputs.version }}" | |
| echo " - ${{ secrets.DOCKER_USERNAME }}/pmhq:latest" |