Build Docker Image #222
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
| # To test: gh workflow run 'Build Docker Image' --ref kwannoel/workflow-update-branch | |
| name: Build Docker Image | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| label: | |
| description: 'Generate image tag + build Docker image: v<X.Y.Z>--<label>--<commit_sha>--<branch>' | |
| required: true | |
| type: string | |
| default: 'unlabeled' | |
| push_dockerhub: | |
| description: 'Whether to push to DockerHub' | |
| required: false | |
| type: boolean | |
| default: false | |
| jobs: | |
| build_image: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: 'Generate image tag' | |
| id: get_release_branch | |
| run: | | |
| # Get branch name | |
| BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD) | |
| echo "BRANCH_NAME=$BRANCH_NAME" | |
| echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV | |
| echo "Replace / with - in branch name, for docker manifest requirement" | |
| NO_SLASH_BRANCH_NAME=${BRANCH_NAME//\//-} | |
| echo "NO_SLASH_BRANCH_NAME=$NO_SLASH_BRANCH_NAME" | |
| echo "NO_SLASH_BRANCH_NAME=$NO_SLASH_BRANCH_NAME" >> $GITHUB_ENV | |
| # Get version from Cargo.toml, e.g. v2.3.0-alpha | |
| VERSION=$(grep -m 1 '^version' Cargo.toml | cut -d '"' -f 2) | |
| echo "VERSION=$VERSION" | |
| echo "VERSION=$VERSION" >> $GITHUB_ENV | |
| # Get the commit SHA | |
| COMMIT_SHA=$(echo $GITHUB_SHA | cut -c1-7) | |
| echo "COMMIT_SHA=$COMMIT_SHA" | |
| echo "COMMIT_SHA=$COMMIT_SHA" >> $GITHUB_ENV | |
| # Get the label from the input | |
| LABEL=${{ github.event.inputs.label }} | |
| echo "LABEL=$LABEL" | |
| echo "LABEL=$LABEL" >> $GITHUB_ENV | |
| # Build the image tag | |
| IMAGE_TAG="v$VERSION--$LABEL--$COMMIT_SHA--$NO_SLASH_BRANCH_NAME" | |
| echo "IMAGE_TAG=$IMAGE_TAG" | |
| echo "IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_ENV | |
| # Always set PUSH_DOCKERHUB based on input | |
| if [[ "${{ github.event.inputs.push_dockerhub }}" == "true" ]]; then | |
| PUSH_DOCKERHUB="true" | |
| else | |
| PUSH_DOCKERHUB="false" | |
| fi | |
| echo "PUSH_DOCKERHUB=$PUSH_DOCKERHUB" | |
| echo "PUSH_DOCKERHUB=$PUSH_DOCKERHUB" >> $GITHUB_ENV | |
| - name: 'Trigger Docker build Workflow via Buildkite' | |
| uses: buildkite/[email protected] | |
| with: | |
| buildkite_api_access_token: ${{ secrets.BUILDKITE_TOKEN }} | |
| pipeline: 'risingwavelabs/docker' | |
| branch: ${{ env.BRANCH_NAME }} | |
| commit: HEAD | |
| message: ':github: Triggering Docker build with image tag: ${{ env.IMAGE_TAG }}' | |
| build_env_vars: '{ "IMAGE_TAG": "${{ env.IMAGE_TAG }}", "PUSH_DOCKERHUB": "${{ env.PUSH_DOCKERHUB }}" }' |