-
Notifications
You must be signed in to change notification settings - Fork 0
97 lines (83 loc) · 3.22 KB
/
ecr-deploy.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
name: ecr-deploy
on:
workflow_call:
secrets:
AWS_REGION:
required: true
ACTION_IAM_ROLE:
required: true
jobs:
detect-folders:
runs-on: ubuntu-latest
outputs:
folders: ${{ steps.changed-folders.outputs.CHANGED_FOLDERS }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- id: set-matrix
run: echo "matrix=$(find backend/* -maxdepth 0 -type d | jq -R -s -c 'split("\n")[:-1]')" >> $GITHUB_OUTPUT
- name: List all changed files
run: |
for folder in ${{ steps.set-matrix.outputs.matrix }}; do
echo "$folder was detected"
done
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v35
with:
dir_names: true
json: "true"
files: "backend/**"
dir_names_max_depth: "2"
- name: Run step if any file(s) in the docs folder change
id: changed-folders
if: steps.changed-files.outputs.any_changed == 'true'
run: |
echo "One or more files in the docs folder has changed."
echo "List all the files that have changed: ${{ steps.changed-files.outputs.all_changed_files }}"
echo "CHANGED_FOLDERS=${{ steps.changed-files.outputs.all_changed_files }}" >> $GITHUB_OUTPUT
deploy-docker:
needs: detect-folders
runs-on: ubuntu-latest
environment: ${{ github.head_ref || github.ref_name }}
env:
SERVICE: migration
BUILD_STAGE: ${{ github.head_ref || github.ref_name }}
AWS_REGION: ${{ secrets.AWS_REGION }}
if: ${{ needs.detect-folders.outputs.folders != '[]' && needs.detect-folders.outputs.folders != '' }}
strategy:
matrix:
folders: ${{ fromJson(needs.detect-folders.outputs.folders) }}
permissions:
id-token: write
contents: read
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1-node16
with:
role-to-assume: ${{ secrets.ACTION_IAM_ROLE }}
role-session-name: GithubActionsDeployMigration
aws-region: ${{ env.AWS_REGION }}
- name: Extract folder from path
id: find-folder
run: |
VAR=${{ matrix.folders }}
DIR=${VAR#*/}
echo "folder=$DIR" >> $GITHUB_OUTPUT
- name: Print Folder
run: echo ${{ steps.find-folder.outputs.folder }}
- name: Log into Amazon ECR
uses: aws-actions/amazon-ecr-login@v1
- name: Create ECR repo if missing
uses: byu-oit/github-action-create-ecr-repo-if-missing@v2
with:
DOCKER_REPO_NAME: ${{ env.SERVICE }}-${{ env.BUILD_STAGE }}-${{ steps.find-folder.outputs.folder }}
- name: Deploy Docker
run: |-
AWS_REGION=${{ env.AWS_REGION }} SERVICE_NAME=${{ matrix.folders }} BUILD_STAGE=${{ env.BUILD_STAGE }} TF_SERVICE=${{ env.SERVICE }} bash deployment-scripts/docker-deploy.sh
- name: ECS use latest image
run: |-
AWS_REGION=${{ env.AWS_REGION }} SERVICE_NAME=${{ steps.find-folder.outputs.folder }} BUILD_STAGE=${{ env.BUILD_STAGE }} TF_SERVICE=${{ env.SERVICE }} bash deployment-scripts/latest-image.sh