Build and push docker image to GHCR #58
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 push docker image to GHCR | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| tagName: | |
| description: 'The pushed image tag name (comma-separated for multiple tags)' | |
| required: true | |
| default: 'latest' | |
| branchName: | |
| description: 'The git branch name to checkout' | |
| required: false | |
| default: 'main' | |
| dockerfilePath: | |
| description: 'The Dockerfile path used for build. Content also set for this folder For automation build, use ./docs/recipes/automation/tp-setup/bootstrap' | |
| required: true | |
| default: './docker' | |
| type: string | |
| dockerfileName: | |
| description: 'The Dockerfile name used for build. Dockerfile for production build.' | |
| required: true | |
| default: 'Dockerfile' | |
| type: choice | |
| options: | |
| - Dockerfile | |
| - Dockerfile-on-prem | |
| - Dockerfile-tester | |
| - Dockerfile-tester-on-prem | |
| platform: | |
| description: 'The platform to build the image for. linux/amd64, linux/arm64, linux/arm/v7 for Raspberry Pi' | |
| required: true | |
| default: 'linux/amd64,linux/arm64' | |
| type: string | |
| # will push to ghcr.io/TIBCOSoftware/platform-provisioner/platform-provisioner:${{ github.event.inputs.tagName }} | |
| env: | |
| REGISTRY: ghcr.io | |
| REPO_NAME: ${{ github.repository }} | |
| IMAGE_NAME: platform-provisioner | |
| jobs: | |
| release-docker: | |
| name: build and push | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.event.inputs.branchName }} | |
| - name: Convert repository name to lowercase # repository name must be lowercase | |
| run: echo "REPO_NAME=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV | |
| - name: Login to ghcr | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Prepare tags | |
| id: prep-tags | |
| run: | | |
| TAGS_INPUT="${{ github.event.inputs.tagName }}" | |
| IMAGE_BASE="${{ env.REGISTRY }}/${{ env.REPO_NAME }}/${{ env.IMAGE_NAME }}" | |
| # process tags and remove spaces | |
| TAGS="" | |
| IFS=',' read -ra ADDR <<< "$TAGS_INPUT" | |
| TAGS_LIST=() | |
| for tag in "${ADDR[@]}"; do | |
| CLEAN_TAG="$(echo -n "$tag" | xargs)" # Trim spaces | |
| TAGS_LIST+=("${IMAGE_BASE}:${CLEAN_TAG}") | |
| done | |
| # use comma as separator | |
| FINAL_TAGS="$(IFS=','; echo "${TAGS_LIST[*]}")" | |
| echo "TAGS=$FINAL_TAGS" >> $GITHUB_ENV | |
| - name: Build and Push | |
| uses: docker/build-push-action@v6 | |
| with: | |
| platforms: ${{ github.event.inputs.platform }} | |
| file: ${{ github.event.inputs.dockerfilePath }}/${{ github.event.inputs.dockerfileName }} | |
| context: ${{ github.event.inputs.dockerfilePath }} | |
| push: true | |
| tags: ${{ env.TAGS }} | |
| labels: | | |
| org.opencontainers.image.created=${{ env.BUILD_TIME }} | |
| org.opencontainers.image.url=https://github.com/${{ github.repository }} | |
| org.opencontainers.image.source=https://github.com/${{ github.repository }} | |
| org.opencontainers.image.version=${{ env.COMMIT_SHA }} | |
| org.opencontainers.image.revision=${{ env.COMMIT_SHA }} | |
| org.opencontainers.image.ref.name=${{ env.GIT_BRANCH }} | |
| org.opencontainers.image.title=${{ env.REPO_NAME }} |