Repository navigation
feat: lock the OpenTofu state of a building block while tfstate exec runs tofu #177
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 Image | |
| env: | |
| REGISTRY: ghcr.io | |
| IMAGE_NAMESPACE: ${{ github.repository_owner }} | |
| IMAGE_NAME: meshstack-cli | |
| on: | |
| workflow_call: | |
| inputs: | |
| version: | |
| description: "Release version to tag the image with, e.g. v1.2.3" | |
| required: true | |
| type: string | |
| # A push to main refreshes :main, so an image exists before the first release does. | |
| push: | |
| branches: | |
| - main | |
| # Builds the image but does not push it, so a broken Dockerfile fails review rather than main. | |
| pull_request: | |
| paths: | |
| - 'Dockerfile' | |
| - '.github/workflows/build-image.yml' | |
| - 'go.mod' | |
| - 'go.sum' | |
| - '**/*.go' | |
| jobs: | |
| build: | |
| name: Build and push image | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| # Computed here rather than with docker/metadata-action, to keep the set of pinned | |
| # actions small. | |
| - name: Determine version and tags | |
| id: meta | |
| env: | |
| # Read through the environment, because a tag name may hold shell metacharacters and | |
| # ${{ }} would paste them into the script this job runs. | |
| VERSION_INPUT: ${{ inputs.version }} | |
| run: | | |
| if [ -n "${VERSION_INPUT}" ]; then | |
| version="${VERSION_INPUT}" | |
| tags="${REGISTRY}/${IMAGE_NAMESPACE}/${IMAGE_NAME}:${version}" | |
| tags="${tags},${REGISTRY}/${IMAGE_NAMESPACE}/${IMAGE_NAME}:latest" | |
| elif [ "${{ github.ref }}" = "refs/heads/main" ]; then | |
| version="main-$(git rev-parse --short HEAD)" | |
| tags="${REGISTRY}/${IMAGE_NAMESPACE}/${IMAGE_NAME}:main" | |
| tags="${tags},${REGISTRY}/${IMAGE_NAMESPACE}/${IMAGE_NAME}:${version}" | |
| else | |
| version="pr-${{ github.event.number }}" | |
| tags="${REGISTRY}/${IMAGE_NAMESPACE}/${IMAGE_NAME}:${version}" | |
| fi | |
| echo "version=${version}" >> "$GITHUB_OUTPUT" | |
| echo "tags=${tags}" >> "$GITHUB_OUTPUT" | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1 | |
| - name: Login to GHCR | |
| if: github.event_name != 'pull_request' | |
| uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4.6.0 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Build and push | |
| uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0 | |
| with: | |
| context: . | |
| platforms: linux/amd64,linux/arm64 | |
| push: ${{ github.event_name != 'pull_request' }} | |
| tags: ${{ steps.meta.outputs.tags }} | |
| build-args: | | |
| VERSION=${{ steps.meta.outputs.version }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max |