|
| 1 | +name: Deploy application |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + environment: |
| 7 | + description: Environment to deploy to. |
| 8 | + default: development |
| 9 | + required: true |
| 10 | + type: environment |
| 11 | + shared_services_ref: |
| 12 | + description: The branch or tag of the shared services repository to use. |
| 13 | + default: main |
| 14 | + required: false |
| 15 | + type: string |
| 16 | + |
| 17 | +permissions: |
| 18 | + contents: read |
| 19 | + |
| 20 | +env: |
| 21 | + APPLICATION: cfa-ui-components |
| 22 | + ENVIRONMENT: ${{ inputs.environment }} |
| 23 | + REMOTE_WORKFLOW: deploy-app.yaml |
| 24 | + |
| 25 | +jobs: |
| 26 | + deploy: |
| 27 | + name: Deploy to ${{ inputs.environment }} |
| 28 | + runs-on: ubuntu-latest |
| 29 | + environment: ${{ inputs.environment }} |
| 30 | + steps: |
| 31 | + - name: Checkout code |
| 32 | + uses: actions/checkout@v4 |
| 33 | + - name: Configure AWS credentials |
| 34 | + uses: aws-actions/configure-aws-credentials@v4 |
| 35 | + with: |
| 36 | + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} |
| 37 | + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |
| 38 | + aws-region: ${{ vars.AWS_REGION || 'us-east-1' }} |
| 39 | + - name: Log into Amazon ECR |
| 40 | + id: login-ecr |
| 41 | + uses: aws-actions/amazon-ecr-login@v2 |
| 42 | + - name: Check if the image exists |
| 43 | + id: image_exists |
| 44 | + uses: k4kratik/container-image-check-custom-action@v4 |
| 45 | + with: |
| 46 | + type: ecr |
| 47 | + container_repo_name: "${{ env.APPLICATION }}-${{ env.ENVIRONMENT }}-web" |
| 48 | + image_tag: ${{ github.sha }} |
| 49 | + - name: Build and push Docker image |
| 50 | + if: ${{ steps.image_exists.outputs.image_exists == 'false' }} |
| 51 | + env: |
| 52 | + IMAGE_TAG: ${{ github.sha }} |
| 53 | + REGISTRY: ${{ steps.login-ecr.outputs.registry }} |
| 54 | + REPOSITORY: "${{ env.APPLICATION }}-${{ env.ENVIRONMENT }}-web" |
| 55 | + run: | |
| 56 | + docker build -t $REGISTRY/$REPOSITORY:$IMAGE_TAG --platform linux/amd64 . |
| 57 | + docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG |
| 58 | + - name: Update SSM Version Parameter |
| 59 | + env: |
| 60 | + IMAGE_TAG: ${{ github.sha }} |
| 61 | + run: | |
| 62 | + echo "tag:$IMAGE_TAG" |
| 63 | + aws ssm put-parameter \ |
| 64 | + --name /$APPLICATION/$ENVIRONMENT/web/version \ |
| 65 | + --value "$IMAGE_TAG" \ |
| 66 | + --overwrite |
| 67 | + - name: Trigger deployment from shared services |
| 68 | + uses: codex-/return-dispatch@v2 |
| 69 | + id: dispatch |
| 70 | + with: |
| 71 | + token: ${{ secrets.DEPLOYMENT_PAT }} |
| 72 | + ref: ${{ inputs.shared_services_ref || 'main' }} |
| 73 | + repo: shared-services-infra |
| 74 | + owner: codeforamerica |
| 75 | + workflow: ${{ env.REMOTE_WORKFLOW }} |
| 76 | + workflow_inputs: | |
| 77 | + { |
| 78 | + "environment": "${{ env.ENVIRONMENT }}", |
| 79 | + "application": "${{ env.APPLICATION }}" |
| 80 | + } |
| 81 | + - name: Wait on Workflow |
| 82 | + uses: lucasssvaz/wait-on-workflow@v1 |
| 83 | + id: waiter |
| 84 | + with: |
| 85 | + repository: codeforamerica/shared-services-infra |
| 86 | + workflow: ${{ steps.dispatch.outputs.run_id }} |
| 87 | + - name: Fail unless the workflow succeeded |
| 88 | + if: ${{ steps.waiter.outputs.conclusion != 'success' }} |
| 89 | + uses: actions/github-script@v7 |
| 90 | + with: |
| 91 | + script: | |
| 92 | + core.setFailed('Deployment workflow completed with stats: ${{ steps.waiter.outputs.conclusion }}') |
0 commit comments