| |
| |
|
|
| name: Release Docker Image |
|
|
| on: |
| release: |
| types: [published] |
| |
| push: |
| tags: |
| - 'v*.*.*' |
|
|
| env: |
| IMAGE_NAME: landppt |
| PLATFORMS: linux/amd64,linux/arm64 |
|
|
| jobs: |
| release: |
| name: Build and Release |
| runs-on: ubuntu-latest |
| |
| permissions: |
| contents: read |
| packages: write |
| |
| steps: |
| - name: Checkout Repository |
| uses: actions/checkout@v4 |
| |
| |
| - name: Free Disk Space |
| run: | |
| sudo rm -rf /usr/share/dotnet |
| sudo rm -rf /usr/local/lib/android |
| sudo rm -rf /opt/ghc |
| sudo rm -rf /opt/hostedtoolcache/CodeQL |
| sudo docker system prune -af |
| df -h |
| |
| |
| - name: Set up QEMU |
| uses: docker/setup-qemu-action@v3 |
| |
| - name: Set up Docker Buildx |
| uses: docker/setup-buildx-action@v3 |
| |
| |
| - name: Login to GitHub Container Registry |
| uses: docker/login-action@v3 |
| with: |
| registry: ghcr.io |
| username: ${{ github.actor }} |
| password: ${{ secrets.GITHUB_TOKEN }} |
| |
| |
| - name: Login to Docker Hub |
| uses: docker/login-action@v3 |
| with: |
| username: ${{ secrets.DOCKERHUB_USERNAME }} |
| password: ${{ secrets.DOCKERHUB_TOKEN }} |
| continue-on-error: true |
| |
| |
| - name: Extract Version |
| id: version |
| run: | |
| if [[ "${GITHUB_REF}" == refs/tags/* ]]; then |
| VERSION=${GITHUB_REF#refs/tags/} |
| VERSION=${VERSION#v} # 移除 v 前缀 |
| else |
| VERSION="latest" |
| fi |
| echo "version=$VERSION" >> $GITHUB_OUTPUT |
| echo "Version: $VERSION" |
| |
| |
| - name: Extract Docker Metadata |
| id: meta |
| uses: docker/metadata-action@v5 |
| with: |
| images: | |
| ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }} |
| ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }} |
| tags: | |
| type=semver,pattern={{version}} |
| type=semver,pattern={{major}}.{{minor}} |
| type=semver,pattern={{major}} |
| type=raw,value=latest |
| |
| |
| - name: Build and Push Multi-Platform Image |
| uses: docker/build-push-action@v5 |
| with: |
| context: . |
| file: ./Dockerfile |
| platforms: ${{ env.PLATFORMS }} |
| push: true |
| tags: ${{ steps.meta.outputs.tags }} |
| labels: ${{ steps.meta.outputs.labels }} |
| cache-from: type=gha |
| cache-to: type=gha,mode=max |
| build-args: | |
| VERSION=${{ steps.version.outputs.version }} |
| |
| |
| - name: Create Release Summary |
| run: | |
| echo "### 🎉 Release ${{ steps.version.outputs.version }} Published!" >> $GITHUB_STEP_SUMMARY |
| echo "" >> $GITHUB_STEP_SUMMARY |
| echo "**Docker Images:**" >> $GITHUB_STEP_SUMMARY |
| echo "" >> $GITHUB_STEP_SUMMARY |
| echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY |
| echo "# 拉取最新版本" >> $GITHUB_STEP_SUMMARY |
| echo "docker pull ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:latest" >> $GITHUB_STEP_SUMMARY |
| echo "" >> $GITHUB_STEP_SUMMARY |
| echo "# 拉取指定版本" >> $GITHUB_STEP_SUMMARY |
| echo "docker pull ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.version }}" >> $GITHUB_STEP_SUMMARY |
| echo "\`\`\`" >> $GITHUB_STEP_SUMMARY |
| echo "" >> $GITHUB_STEP_SUMMARY |
| echo "**Supported Platforms:** \`${{ env.PLATFORMS }}\`" >> $GITHUB_STEP_SUMMARY |
| |