|
| 1 | +name: Deploy mock careplus service to ECS |
| 2 | +run-name: Deploy mock careplus service to ${{ inputs.environment }} |
| 3 | + |
| 4 | +on: |
| 5 | + workflow_dispatch: |
| 6 | + inputs: |
| 7 | + environment: |
| 8 | + description: Deployment environment |
| 9 | + required: true |
| 10 | + type: choice |
| 11 | + options: |
| 12 | + - qa |
| 13 | + - test |
| 14 | + - sandbox-alpha |
| 15 | + - sandbox-beta |
| 16 | + git_ref_to_deploy: |
| 17 | + description: The git ref to deploy. |
| 18 | + required: false |
| 19 | + type: string |
| 20 | + workflow_call: |
| 21 | + inputs: |
| 22 | + environment: |
| 23 | + required: true |
| 24 | + type: string |
| 25 | + git_ref_to_deploy: |
| 26 | + description: The git ref to deploy. |
| 27 | + required: true |
| 28 | + type: string |
| 29 | + |
| 30 | +permissions: {} |
| 31 | + |
| 32 | +concurrency: |
| 33 | + group: deploy-mavis-${{ inputs.environment }} |
| 34 | + |
| 35 | +env: |
| 36 | + aws_role: arn:aws:iam::393416225559:role/GithubDeployECSService |
| 37 | + aws_account_id: '393416225559' |
| 38 | + cluster_name: mavis-${{ inputs.environment }} |
| 39 | + family_name: mavis-mock-careplus-task-definition-${{ inputs.environment }} |
| 40 | + |
| 41 | +jobs: |
| 42 | + determine-git-sha: |
| 43 | + runs-on: ubuntu-latest |
| 44 | + permissions: {} |
| 45 | + outputs: |
| 46 | + git-sha: ${{ steps.get-git-sha.outputs.git-sha }} |
| 47 | + steps: |
| 48 | + - name: Checkout code |
| 49 | + uses: actions/checkout@v6 |
| 50 | + with: |
| 51 | + ref: ${{ inputs.git_ref_to_deploy || github.sha }} |
| 52 | + - name: Get git sha |
| 53 | + id: get-git-sha |
| 54 | + run: echo "git-sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT" |
| 55 | + |
| 56 | + build-and-push-image: |
| 57 | + permissions: |
| 58 | + id-token: write |
| 59 | + needs: determine-git-sha |
| 60 | + uses: ./.github/workflows/build-and-push-mock-careplus-image.yaml |
| 61 | + with: |
| 62 | + git-sha: ${{ needs.determine-git-sha.outputs.git-sha }} |
| 63 | + |
| 64 | + prepare-deployment: |
| 65 | + name: Prepare deployment |
| 66 | + runs-on: ubuntu-latest |
| 67 | + needs: [determine-git-sha, build-and-push-image] |
| 68 | + permissions: |
| 69 | + id-token: write |
| 70 | + steps: |
| 71 | + - name: Checkout code |
| 72 | + uses: actions/checkout@v6 |
| 73 | + with: |
| 74 | + ref: ${{ needs.determine-git-sha.outputs.git-sha }} |
| 75 | + - name: Configure AWS Credentials |
| 76 | + uses: aws-actions/configure-aws-credentials@v6 |
| 77 | + with: |
| 78 | + role-to-assume: ${{ env.aws_role }} |
| 79 | + aws-region: eu-west-2 |
| 80 | + - name: Get image digest |
| 81 | + id: get-image-digest |
| 82 | + run: | |
| 83 | + digest=$(aws ecr describe-images \ |
| 84 | + --repository-name mavis/mock-careplus \ |
| 85 | + --image-ids imageTag=${{ needs.determine-git-sha.outputs.git-sha }} \ |
| 86 | + --query 'imageDetails[0].imageDigest' \ |
| 87 | + --output text) |
| 88 | + echo "digest=$digest" >> "$GITHUB_OUTPUT" |
| 89 | + - name: Populate mock-careplus task definition |
| 90 | + id: create-task-definition |
| 91 | + uses: aws-actions/amazon-ecs-render-task-definition@v1 |
| 92 | + with: |
| 93 | + # yamllint disable-line rule:line-length |
| 94 | + task-definition-family: mavis-mock-careplus-task-definition-${{ inputs.environment }}-template |
| 95 | + container-name: application |
| 96 | + # yamllint disable-line rule:line-length |
| 97 | + image: ${{ env.aws_account_id }}.dkr.ecr.eu-west-2.amazonaws.com/mavis/mock-careplus@${{ steps.get-image-digest.outputs.digest }} |
| 98 | + - name: Rename task definition file |
| 99 | + run: >- |
| 100 | + mv ${{ steps.create-task-definition.outputs.task-definition }} |
| 101 | + ${{ runner.temp }}/mock-careplus-task-definition.json |
| 102 | + - name: Upload artifact for mock-careplus task definition |
| 103 | + uses: actions/upload-artifact@v7 |
| 104 | + with: |
| 105 | + name: ${{ inputs.environment }}-mock-careplus-task-definition |
| 106 | + path: ${{ runner.temp }}/mock-careplus-task-definition.json |
| 107 | + |
| 108 | + deploy: |
| 109 | + name: Deploy mock-careplus service |
| 110 | + runs-on: ubuntu-latest |
| 111 | + needs: prepare-deployment |
| 112 | + environment: ${{ inputs.environment }} |
| 113 | + permissions: |
| 114 | + id-token: write |
| 115 | + steps: |
| 116 | + - name: Configure AWS Credentials |
| 117 | + uses: aws-actions/configure-aws-credentials@v6 |
| 118 | + with: |
| 119 | + role-to-assume: ${{ env.aws_role }} |
| 120 | + aws-region: eu-west-2 |
| 121 | + - name: Download mock-careplus task definition artifact |
| 122 | + uses: actions/download-artifact@v8 |
| 123 | + with: |
| 124 | + path: ${{ runner.temp }} |
| 125 | + name: ${{ inputs.environment }}-mock-careplus-task-definition |
| 126 | + - name: Change family of task definition |
| 127 | + run: | |
| 128 | + file_path="${{ runner.temp }}/mock-careplus-task-definition.json" |
| 129 | + family_name="mavis-mock-careplus-task-definition-${{ inputs.environment }}" |
| 130 | + jq --arg f "$family_name" '.family = $f' "$file_path" > tmpfile && mv tmpfile "$file_path" |
| 131 | + - name: Deploy mock-careplus service |
| 132 | + uses: aws-actions/amazon-ecs-deploy-task-definition@v2 |
| 133 | + with: |
| 134 | + task-definition: ${{ runner.temp }}/mock-careplus-task-definition.json |
| 135 | + cluster: ${{ env.cluster_name }} |
| 136 | + service: mavis-${{ inputs.environment }}-mock-careplus |
| 137 | + force-new-deployment: true |
| 138 | + wait-for-service-stability: true |
0 commit comments