feat(docker): update workflow to push images on branch pushes and ref… #71
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
| # This workflow pushes new Bitsong docker images on every new tag or branch push. | |
| # | |
| # On every new `vX.Y.Z` tag the following images are pushed: | |
| # | |
| # bitsongofficial/go-bitsong:vX.Y.Z # is pushed | |
| # bitsongofficial/go-bitsong:X.Y.Z # is pushed | |
| # bitsongofficial/go-bitsong:X.Y # is updated to X.Y.Z | |
| # bitsongofficial/go-bitsong:X # is updated to X.Y.Z | |
| # | |
| # On branch pushes (e.g. feat-hyperlane) the following images are pushed: | |
| # | |
| # bitsongofficial/go-bitsong:feat-hyperlane # latest for that branch | |
| # bitsongofficial/go-bitsong:feat-hyperlane-abc1234 # pinned to commit | |
| # | |
| # All the images above have support for linux/amd64 and linux/arm64. | |
| name: Push Docker Images | |
| env: | |
| DOCKER_REPOSITORY: bitsongofficial/go-bitsong | |
| on: | |
| release: | |
| types: [published, created, edited] | |
| push: | |
| tags: | |
| - 'v[0-9]+.[0-9]+.[0-9]+' # ignore rc | |
| branches: | |
| - 'feat-hyperlane' | |
| jobs: | |
| bitsong-images: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - | |
| name: Check out the repo | |
| uses: actions/checkout@v4 | |
| - | |
| 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.repository_owner }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - | |
| name: Determine image tags | |
| id: tags | |
| run: | | |
| SHORT_SHA=$(echo "${{ github.sha }}" | cut -c1-7) | |
| if [[ "${{ github.ref_type }}" == "tag" ]]; then | |
| # Tag push: produce semver tags (e.g. v0.21.0 -> 0, 0.21, 0.21.0, v0.21.0) | |
| VERSION=$(echo "${{ github.ref_name }}" | sed "s/v//") | |
| MAJOR_VERSION=$(echo "$VERSION" | cut -d '.' -f 1) | |
| MINOR_VERSION=$(echo "$VERSION" | cut -d '.' -f 2) | |
| PATCH_VERSION=$(echo "$VERSION" | cut -d '.' -f 3) | |
| IMAGE_TAGS="ghcr.io/${{ env.DOCKER_REPOSITORY }}:${MAJOR_VERSION} | |
| ghcr.io/${{ env.DOCKER_REPOSITORY }}:${MAJOR_VERSION}.${MINOR_VERSION} | |
| ghcr.io/${{ env.DOCKER_REPOSITORY }}:${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION} | |
| ghcr.io/${{ env.DOCKER_REPOSITORY }}:v${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}" | |
| else | |
| # Branch push: produce branch + commit-pinned tags | |
| BRANCH=$(echo "${{ github.ref_name }}" | sed 's/\//-/g') | |
| IMAGE_TAGS="ghcr.io/${{ env.DOCKER_REPOSITORY }}:${BRANCH} | |
| ghcr.io/${{ env.DOCKER_REPOSITORY }}:${BRANCH}-${SHORT_SHA}" | |
| fi | |
| echo "IMAGE_TAGS<<EOF" >> $GITHUB_OUTPUT | |
| echo "$IMAGE_TAGS" >> $GITHUB_OUTPUT | |
| echo "EOF" >> $GITHUB_OUTPUT | |
| - | |
| name: Build and push | |
| id: build_push_image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| file: Dockerfile | |
| context: . | |
| push: true | |
| platforms: linux/amd64,linux/arm64 | |
| tags: ${{ steps.tags.outputs.IMAGE_TAGS }} |