Build, Push, & Deploy #35149
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, Push, & Deploy | |
| on: | |
| workflow_dispatch: | |
| workflow_run: | |
| workflows: ["Code Checks"] | |
| branches: [master] | |
| types: [completed] | |
| permissions: | |
| id-token: write | |
| contents: read | |
| jobs: | |
| debug_workflow_context: | |
| runs-on: ubuntu-latest | |
| name: Debug Workflow Context | |
| steps: | |
| - name: Compare commit ids and workflow details | |
| run: | | |
| echo "github.sha: ${{ github.sha }}" | |
| echo "github.event.push.head_commit.id: ${{ github.event.push.head_commit.id }}" | |
| echo "github.event.pull_request.merge_commit_sha: ${{ github.event.pull_request.merge_commit_sha }}" | |
| echo "github.event.head_commit.id: ${{ github.event.head_commit.id }}" | |
| echo "github.event.workflow_run.head_commit.id: ${{ github.event.workflow_run.head_commit.id }}" | |
| echo "github.ref: ${{ github.ref }}" | |
| echo "github.ref_name: ${{ github.ref_name }}" | |
| echo "github.event.workflow_run.name: ${{ github.event.workflow_run.name }}" | |
| echo "github.event.workflow_run.conclusion: ${{ github.event.workflow_run.conclusion }}" | |
| echo "github.event.workflow_run.event: ${{ github.event.workflow_run.event }}" | |
| echo "github.event_name: ${{ github.event_name }}" | |
| build_and_push: | |
| if: ${{ github.event.workflow_run.conclusion == 'success' }} | |
| name: Build and Push | |
| env: | |
| BUNDLE_ENTERPRISE__CONTRIBSYS__COM: ${{ secrets.BUNDLE_ENTERPRISE__CONTRIBSYS__COM }} | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 | |
| with: | |
| ref: ${{ github.event.workflow_run.head_commit.id }} | |
| - name: Setup Environment | |
| run: echo "VETS_API_USER_ID=$(id -u)" >> $GITHUB_ENV | |
| - name: Configure AWS credentials | |
| uses: aws-actions/configure-aws-credentials@8df5847569e6427dd6c4fb1cf565c83acfa8afa7 # v6 | |
| with: | |
| role-to-assume: ${{ vars.AWS_ASSUME_ROLE }} | |
| aws-region: us-gov-west-1 | |
| - name: Login to ECR | |
| id: ecr-login | |
| uses: aws-actions/amazon-ecr-login@183a1442edf41672e66566b7fc560e297a290896 # v2 | |
| - name: Build Postman Docker Image | |
| uses: docker/build-push-action@d08e5c354a6adb9ed34480a06d141179aa583294 # v7 | |
| env: | |
| DOCKER_BUILD_SUMMARY: false | |
| with: | |
| context: ./postman | |
| file: ./postman/Dockerfile | |
| push: true | |
| tags: | | |
| ${{ steps.ecr-login.outputs.registry }}/dsva/vets-api-postman:${{ github.event.workflow_run.head_commit.id }} | |
| - name: Build vets-api Docker Image | |
| uses: docker/build-push-action@d08e5c354a6adb9ed34480a06d141179aa583294 # v7 | |
| env: | |
| DOCKER_BUILD_SUMMARY: false | |
| with: | |
| build-args: | | |
| BUNDLE_ENTERPRISE__CONTRIBSYS__COM=${{ env.BUNDLE_ENTERPRISE__CONTRIBSYS__COM }} | |
| USER_ID=${{ env.VETS_API_USER_ID }} | |
| RAILS_ENV=production | |
| context: . | |
| push: true | |
| tags: | | |
| ${{ steps.ecr-login.outputs.registry }}/${{ secrets.ECR_REPOSITORY }}:${{ github.event.workflow_run.head_commit.id }} | |
| cache-from: type=registry,ref=$ECR_REGISTRY/$ECR_REPOSITORY | |
| cache-to: type=inline | |
| deploy: | |
| needs: build_and_push | |
| if: ${{ github.event.workflow_run.head_branch == 'master' && github.event.workflow_run.conclusion == 'success' }} | |
| uses: department-of-veterans-affairs/vets-api/.github/workflows/deploy-template.yml@master | |
| with: | |
| ecr_repository: "vets-api" | |
| manifests_directory: "vets-api" | |
| auto_deploy_envs: "dev staging prod sandbox" | |
| commit_sha: ${{ github.event.workflow_run.head_commit.id }} | |
| secrets: | |
| aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
| aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |