Move from AWS ECR to GitHub #2
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 Image | |
| on: | |
| push: | |
| branches: | |
| - '**' | |
| permissions: | |
| contents: read | |
| packages: write | |
| env: | |
| REGISTRY: ghcr.io | |
| IMAGE_NAME: cabinetoffice/fb-user-datastore-api | |
| jobs: | |
| build-fb-user-datastore-api: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Compute tag | |
| id: tag | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| sha="${GITHUB_SHA}" | |
| short_sha="${sha:0:7}" | |
| ref="${GITHUB_REF_NAME}" | |
| if [[ "$ref" == "main" ]]; then | |
| tag="main-${short_sha}" | |
| else | |
| # Sanitize branch name for Docker tag compatibility. | |
| safe_ref="$(echo "$ref" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9_.-]/-/g')" | |
| tag="branch-${safe_ref}-${short_sha}" | |
| fi | |
| echo "value=$tag" >> "$GITHUB_OUTPUT" | |
| - name: Log in to GHCR | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Build and push image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| push: true | |
| tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.tag.outputs.value }} |