Build and push graphemes-api image #38
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 graphemes-api image | |
| # Limit GITHUB_TOKEN permissions | |
| permissions: | |
| contents: read # Read the repo contents | |
| packages: write # Push built image to GitHub Container Registry | |
| on: | |
| push: | |
| paths: | |
| - graphemes-api/** | |
| branches: [dev, test, main] | |
| workflow_dispatch: | |
| # Cancel any currently running builds to save GitHub Actions hours. | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| build-and-push: | |
| name: graphemes-api build and push | |
| runs-on: ubuntu-latest | |
| # Don't run on forks | |
| if: github.repository == 'bcgov/standard-graphemes' | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| with: | |
| driver-opts: network=host | |
| # PRs to `dev` branch get deployed to `dev` environment in OpenShift | |
| # PRs to `test` get deployed to `test` | |
| # PRs to `main` get deployed to `prod` | |
| - name: Determine environment tag | |
| id: env-tag | |
| run: | | |
| echo "Evaluating branch: ${{ github.ref }}"; | |
| if [[ "${{ github.ref }}" == "refs/heads/dev" ]]; then | |
| echo "tag=dev" >> $GITHUB_ENV; | |
| elif [[ "${{ github.ref }}" == "refs/heads/test" ]]; then | |
| echo "tag=test" >> $GITHUB_ENV; | |
| elif [[ "${{ github.ref }}" == "refs/heads/main" ]]; then | |
| echo "tag=prod" >> $GITHUB_ENV; | |
| else | |
| echo "Unknown branch: ${{ github.ref }}. Exiting..."; | |
| exit 1; | |
| fi; | |
| shell: bash | |
| # Use the GHCR builder action | |
| - name: Build and push Docker image to GHCR | |
| uses: bcgov-nr/action-builder-ghcr@fd17bc1cbb16a60514e0df3966d42dff9fc232bc # v4.0.0 | |
| with: | |
| package: graphemes-api | |
| tags: ${{ env.tag }} | |
| triggers: graphemes-api/** | |
| build_context: ./graphemes-api | |
| build_file: ./graphemes-api/Dockerfile | |
| keep_versions: 10 |