|
47 | 47 | (Git ref to deploy, for example, a tag, branch name or commit SHA. Will use workflow ref if not provided.) |
48 | 48 | required: true |
49 | 49 | type: string |
| 50 | + app_version: |
| 51 | + required: true |
| 52 | + type: string |
50 | 53 |
|
51 | | -permissions: {} |
| 54 | +permissions: { } |
52 | 55 |
|
53 | 56 | env: |
54 | 57 | environment: ${{ inputs.environment }} |
|
58 | 61 | || 'arn:aws:iam::393416225559:role/GithubDeployECSService' }} |
59 | 62 | aws_account_id: ${{ inputs.environment == 'production' && '820242920762' || '393416225559' }} |
60 | 63 | cluster_name: mavis-${{ inputs.environment }} |
61 | | - app_version: ${{ inputs.git_ref_to_deploy == '' && 'unknown' || inputs.git_ref_to_deploy }} |
| 64 | + app_version: ${{ inputs.app_version || inputs.git_ref_to_deploy || 'unknown' }} |
62 | 65 |
|
63 | 66 | concurrency: |
64 | 67 | group: deploy-application-${{ inputs.environment }} |
65 | 68 |
|
66 | 69 | jobs: |
67 | 70 | determine-git-sha: |
68 | 71 | runs-on: ubuntu-latest |
69 | | - permissions: {} |
| 72 | + permissions: { } |
70 | 73 | outputs: |
71 | 74 | git-sha: ${{ steps.get-git-sha.outputs.git-sha }} |
72 | 75 | steps: |
|
89 | 92 | prepare-deployment: |
90 | 93 | name: Prepare deployment |
91 | 94 | runs-on: ubuntu-latest |
92 | | - needs: [determine-git-sha, build-and-push-image] |
| 95 | + needs: [ determine-git-sha, build-and-push-image ] |
93 | 96 | permissions: |
94 | 97 | id-token: write |
95 | 98 | strategy: |
@@ -141,84 +144,39 @@ jobs: |
141 | 144 | needs: prepare-deployment |
142 | 145 | environment: ${{ inputs.environment }} |
143 | 146 | steps: |
144 | | - - run: echo "Proceeding with deployment to $environment environment" |
| 147 | + - run: echo "Proceeding with deployment to $environment" |
145 | 148 |
|
146 | | - deploy-web: |
147 | | - name: Deploy web service |
| 149 | + deploy-service: |
| 150 | + name: Deploy service |
148 | 151 | runs-on: ubuntu-latest |
149 | | - if: ${{ inputs.server_types == 'web' || inputs.server_types == 'all' }} |
150 | | - needs: [prepare-deployment, approve-deployments] |
151 | | - permissions: |
152 | | - id-token: write |
153 | | - steps: |
154 | | - - name: Configure AWS Credentials |
155 | | - uses: aws-actions/configure-aws-credentials@v5 |
156 | | - with: |
157 | | - role-to-assume: ${{ env.aws_role }} |
158 | | - aws-region: eu-west-2 |
159 | | - - name: Checkout code |
160 | | - uses: actions/checkout@v5 |
161 | | - - name: Download web task definition artifact |
162 | | - uses: actions/download-artifact@v5 |
163 | | - with: |
164 | | - path: ${{ runner.temp }} |
165 | | - name: ${{ inputs.environment }}-web-task-definition |
166 | | - - name: Change family of task definition |
167 | | - run: | |
168 | | - file_path="${{ runner.temp }}/web-task-definition.json" |
169 | | - family_name="mavis-web-task-definition-$environment" |
170 | | - echo "$(jq --arg f "$family_name" '.family = $f' "$file_path")" > "$file_path" |
171 | | - - name: Register web task definition |
172 | | - uses: aws-actions/amazon-ecs-deploy-task-definition@v2 |
173 | | - with: |
174 | | - task-definition: ${{ runner.temp }}/web-task-definition.json |
175 | | - - name: Create appspec.yml |
176 | | - run: | |
177 | | - cp config/templates/appspec.yaml.tpl appspec.yaml |
178 | | - sed -i "s#TASK_DEFINITION_ARN#${{ steps.register-task-definition.outputs.task-definition-arn }}#g" appspec.yaml |
179 | | - - name: Deploy web service with CodeDeploy |
180 | | - id: deploy-web-service |
181 | | - uses: aws-actions/amazon-ecs-deploy-task-definition@v2 |
182 | | - with: |
183 | | - task-definition: ${{ runner.temp }}/web-task-definition.json |
184 | | - cluster: ${{ env.cluster_name }} |
185 | | - service: mavis-${{ inputs.environment }}-web |
186 | | - codedeploy-application: mavis-${{ inputs.environment }} |
187 | | - codedeploy-deployment-group: blue-green-group-${{ inputs.environment }} |
188 | | - - name: Wait for deployment to complete |
189 | | - run: | |
190 | | - echo "Waiting for CodeDeploy deployment ${{ steps.deploy-web-service.outputs.codedeploy-deployment-id }} to complete..." |
191 | | - aws deploy wait deployment-successful --deployment-id "${{ steps.deploy-web-service.outputs.codedeploy-deployment-id }}" |
192 | | - echo "Deployment successful" |
193 | | -
|
194 | | - deploy-sidekiq: |
195 | | - name: Deploy sidekiq service |
196 | | - runs-on: ubuntu-latest |
197 | | - if: ${{ inputs.server_types == 'sidekiq' || inputs.server_types == 'all' }} |
198 | | - needs: [prepare-deployment, approve-deployments] |
| 152 | + needs: [ prepare-deployment, approve-deployments ] |
199 | 153 | permissions: |
200 | 154 | id-token: write |
| 155 | + strategy: |
| 156 | + fail-fast: false |
| 157 | + matrix: |
| 158 | + service: ${{ inputs.server_types == 'all' && fromJSON('["web", "sidekiq"]') || fromJSON(format('["{0}"]', inputs.server_types)) }} |
201 | 159 | steps: |
202 | 160 | - name: Configure AWS Credentials |
203 | 161 | uses: aws-actions/configure-aws-credentials@v5 |
204 | 162 | with: |
205 | 163 | role-to-assume: ${{ env.aws_role }} |
206 | 164 | aws-region: eu-west-2 |
207 | | - - name: Download sidekiq task definition artifact |
| 165 | + - name: Download ${{ matrix.service }} task definition artifact |
208 | 166 | uses: actions/download-artifact@v5 |
209 | 167 | with: |
210 | 168 | path: ${{ runner.temp }} |
211 | | - name: ${{ inputs.environment }}-sidekiq-task-definition |
| 169 | + name: ${{ inputs.environment }}-${{ matrix.service }}-task-definition |
212 | 170 | - name: Change family of task definition |
213 | 171 | run: | |
214 | | - file_path="${{ runner.temp }}/sidekiq-task-definition.json" |
215 | | - family_name="mavis-sidekiq-task-definition-$environment" |
| 172 | + file_path="${{ runner.temp }}/${{ matrix.service }}-task-definition.json" |
| 173 | + family_name="mavis-${{ matrix.service }}-task-definition-$environment" |
216 | 174 | echo "$(jq --arg f "$family_name" '.family = $f' "$file_path")" > "$file_path" |
217 | | - - name: Deploy sidekiq service |
| 175 | + - name: Deploy ${{ matrix.service }} service |
218 | 176 | uses: aws-actions/amazon-ecs-deploy-task-definition@v2 |
219 | 177 | with: |
220 | | - task-definition: ${{ runner.temp }}/sidekiq-task-definition.json |
| 178 | + task-definition: ${{ runner.temp }}/${{ matrix.service }}-task-definition.json |
221 | 179 | cluster: ${{ env.cluster_name }} |
222 | | - service: mavis-${{ inputs.environment }}-sidekiq |
| 180 | + service: mavis-${{ inputs.environment }}-${{ matrix.service }} |
223 | 181 | force-new-deployment: true |
224 | 182 | wait-for-service-stability: true |
0 commit comments