Deploy API to Environment #85
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: Deploy API to Environment | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| environment: | |
| description: 'Environment to deploy to' | |
| required: true | |
| default: 'lz-dev' | |
| type: choice | |
| options: | |
| - lz-dev | |
| - lz-test | |
| - lz-prod | |
| - dev | |
| - test | |
| - prod | |
| release_tag: | |
| description: 'Release tag to deploy (e.g. v1.2.3). Leave empty to use the current commit SHA.' | |
| required: false | |
| type: string | |
| env: | |
| WORKING_DIRECTORY: . | |
| IMAGE_NAME: api | |
| GITHUB_IMAGE_REPO: ghcr.io/bcgov/jasper | |
| jobs: | |
| build: | |
| name: Build, Create and Push Image | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| outputs: | |
| image_tag: ${{ steps.version.outputs.IMAGE_TAG }} | |
| strategy: | |
| matrix: | |
| dotnet-major-version: [10] | |
| dotnet-minor-version: [0] | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| with: | |
| ref: ${{ github.ref }} | |
| - name: Build API codebase | |
| uses: ./.github/workflows/actions/build-api | |
| with: | |
| working_directory: ${{ env.WORKING_DIRECTORY }} | |
| dotnet_version: ${{ matrix.dotnet-major-version }}.${{ matrix.dotnet-minor-version }} | |
| - name: Log in to the GHCR | |
| uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Get Image Tag | |
| id: version | |
| run: | | |
| if [[ -n "${{ github.event.inputs.release_tag }}" ]]; then | |
| VERSION="${{ github.event.inputs.release_tag }}" | |
| echo "IMAGE_TAG=${VERSION#v}" >> $GITHUB_OUTPUT | |
| echo "RELEASE_VERSION=${VERSION#v}" >> $GITHUB_OUTPUT | |
| else | |
| echo "IMAGE_TAG=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT | |
| echo "RELEASE_VERSION=" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Setup Image Metadata | |
| id: meta | |
| uses: docker/metadata-action@c299e40c65443455700f0fdfc63efafe5b349051 # v5.10.0 | |
| with: | |
| images: | | |
| ${{ env.GITHUB_IMAGE_REPO }}/${{ env.IMAGE_NAME }} | |
| tags: | | |
| type=raw,value=${{ steps.version.outputs.IMAGE_TAG }} | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3.12.0 | |
| - name: Build and Push Image to ghcr.io | |
| id: build_image | |
| uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2 | |
| with: | |
| push: true | |
| context: . | |
| file: ./docker/api/Dockerfile.release | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| provenance: false | |
| load: true | |
| build-args: | | |
| dotnet_version=${{ matrix.dotnet-major-version }}.${{ matrix.dotnet-minor-version }} | |
| RELEASE_VERSION=${{ steps.version.outputs.RELEASE_VERSION }} | |
| deploy2env: | |
| name: Deploy to ENV | |
| needs: build | |
| env: | |
| ENVIRONMENT: ${{ github.event.inputs.environment }} | |
| permissions: | |
| id-token: write | |
| packages: write | |
| runs-on: ubuntu-latest | |
| environment: ${{ github.event.inputs.environment }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| with: | |
| ref: ${{ github.ref }} | |
| - name: Deploy to ${{ env.ENVIRONMENT }} | |
| uses: ./.github/workflows/actions/deploy-app | |
| with: | |
| environment: ${{ env.ENVIRONMENT }} | |
| aws_account: ${{ vars.AWS_ACCOUNT }} | |
| region: ${{ vars.AWS_REGION }} | |
| app_name: ${{ vars.APP_NAME }} | |
| aws_role_arn: ${{ vars.AWS_ROLE_ARN }} | |
| ghcr_token: ${{ secrets.GITHUB_TOKEN }} | |
| github_image_repo: ${{ env.GITHUB_IMAGE_REPO }} | |
| image_name: ${{ env.IMAGE_NAME }} | |
| tier_name: api | |
| image_tag: ${{ needs.build.outputs.image_tag }} |