v4.2.1 #7
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
| #==============================================================# | |
| # File : docker.yml | |
| # Desc : Build and push Docker images to Docker Hub | |
| # Ctime : 2025-01-27 | |
| # Mtime : 2025-01-27 | |
| # License : Apache-2.0 @ https://pigsty.io/docs/about/license | |
| # Copyright : 2018-2025 Ruohang Feng / Vonng (rh@vonng.com) | |
| #==============================================================# | |
| # | |
| # This workflow builds multi-architecture Docker images (amd64/arm64) | |
| # and pushes them to Docker Hub under pgsty/pigsty. | |
| # | |
| # Triggers: | |
| # - On tag push matching 'v*.*.*' pattern (e.g., v4.2.1) | |
| # - Manual trigger via workflow_dispatch | |
| # | |
| # Required secrets: | |
| # - DOCKERHUB_USERNAME: Docker Hub username | |
| # - DOCKERHUB_TOKEN: Docker Hub access token (not password) | |
| # | |
| # Images produced: | |
| # - pgsty/pigsty:v4.2.1 (version tag) | |
| # - pgsty/pigsty:latest (only for release tags) | |
| # | |
| #==============================================================# | |
| name: Docker | |
| on: | |
| push: | |
| tags: | |
| - 'v*.*.*' | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: 'Version tag (e.g., v4.2.1)' | |
| required: true | |
| default: 'v4.2.1' | |
| push_latest: | |
| description: 'Also tag as latest?' | |
| required: true | |
| default: 'true' | |
| type: choice | |
| options: | |
| - 'true' | |
| - 'false' | |
| env: | |
| REGISTRY: docker.io | |
| IMAGE_NAME: pgsty/pigsty | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| #--------------------------------------------------------------# | |
| # Preparation | |
| #--------------------------------------------------------------# | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Extract version from tag or input | |
| id: version | |
| run: | | |
| if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then | |
| VERSION="${{ github.event.inputs.version }}" | |
| PUSH_LATEST="${{ github.event.inputs.push_latest }}" | |
| else | |
| # Extract version from git tag (refs/tags/v4.2.1 -> v4.2.1) | |
| VERSION="${GITHUB_REF#refs/tags/}" | |
| PUSH_LATEST="true" | |
| fi | |
| # Remove 'v' prefix for Docker build arg (v4.2.1 -> 4.2.1) | |
| VERSION_NUM="${VERSION#v}" | |
| echo "version=${VERSION}" >> $GITHUB_OUTPUT | |
| echo "version_num=${VERSION_NUM}" >> $GITHUB_OUTPUT | |
| echo "push_latest=${PUSH_LATEST}" >> $GITHUB_OUTPUT | |
| echo "Version: ${VERSION}" | |
| echo "Version Number: ${VERSION_NUM}" | |
| echo "Push Latest: ${PUSH_LATEST}" | |
| #--------------------------------------------------------------# | |
| # Docker Setup | |
| #--------------------------------------------------------------# | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| #--------------------------------------------------------------# | |
| # Build Metadata | |
| #--------------------------------------------------------------# | |
| - name: Extract Docker metadata | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.IMAGE_NAME }} | |
| tags: | | |
| # Version tag (e.g., v4.2.1) | |
| type=raw,value=${{ steps.version.outputs.version }} | |
| # Latest tag (only when push_latest is true) | |
| type=raw,value=latest,enable=${{ steps.version.outputs.push_latest == 'true' }} | |
| labels: | | |
| org.opencontainers.image.title=Pigsty | |
| org.opencontainers.image.description=Pigsty - PostgreSQL in Great STYle | |
| org.opencontainers.image.url=https://pigsty.io | |
| org.opencontainers.image.source=https://github.com/pgsty/pigsty | |
| org.opencontainers.image.version=${{ steps.version.outputs.version }} | |
| org.opencontainers.image.vendor=pgsty | |
| org.opencontainers.image.licenses=Apache-2.0 | |
| maintainer=Ruohang Feng <rh@vonng.com> | |
| #--------------------------------------------------------------# | |
| # Build and Push | |
| #--------------------------------------------------------------# | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: ./docker | |
| file: ./docker/Dockerfile | |
| platforms: linux/amd64,linux/arm64 | |
| push: true | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| build-args: | | |
| VERSION=${{ steps.version.outputs.version_num }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| provenance: false | |
| #--------------------------------------------------------------# | |
| # Verification | |
| #--------------------------------------------------------------# | |
| - name: Inspect image | |
| run: | | |
| echo "Inspecting pushed images..." | |
| docker buildx imagetools inspect ${{ env.IMAGE_NAME }}:${{ steps.version.outputs.version }} | |
| - name: Summary | |
| run: | | |
| echo "## Docker Image Published" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "**Images:**" >> $GITHUB_STEP_SUMMARY | |
| echo "- \`${{ env.IMAGE_NAME }}:${{ steps.version.outputs.version }}\`" >> $GITHUB_STEP_SUMMARY | |
| if [ "${{ steps.version.outputs.push_latest }}" = "true" ]; then | |
| echo "- \`${{ env.IMAGE_NAME }}:latest\`" >> $GITHUB_STEP_SUMMARY | |
| fi | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "**Platforms:** linux/amd64, linux/arm64" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "**Pull command:**" >> $GITHUB_STEP_SUMMARY | |
| echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY | |
| echo "docker pull ${{ env.IMAGE_NAME }}:${{ steps.version.outputs.version }}" >> $GITHUB_STEP_SUMMARY | |
| echo "\`\`\`" >> $GITHUB_STEP_SUMMARY |