forked from codeforjapan/decidim-cfj
-
Notifications
You must be signed in to change notification settings - Fork 0
95 lines (82 loc) · 2.67 KB
/
_deploy.yaml
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
name: Deploy to ecs
on:
workflow_call:
inputs:
role-to-assume:
type: string
required: false
default: arn:aws:iam::887442827229:role/GithubActions_decidim-cfj-cdk-deploy
image-tag:
type: string
required: true
deploy-env:
type: string
required: false
description: "target environment"
default: staging
permissions:
actions: write
contents: read
id-token: write
jobs:
deploy:
name: aws cdk
runs-on: ubuntu-latest
timeout-minutes: 1800
steps:
- uses: actions/checkout@v3
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
role-to-assume: ${{ inputs.role-to-assume }}
aws-region: ap-northeast-1
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Check if ECR Image exists with tag
if: contains(github.ref, 'tags/v')
env:
IMAGE_TAG: ${{ inputs.image-tag }}
ECR_REPOSITORY: ${{ secrets.AWS_ECR_REPO_NAME }}
run: |
EXIT_CODE=0
aws ecr describe-images --repository-name=$ECR_REPOSITORY --image-ids=imageTag=$IMAGE_TAG 2> /dev/null || EXIT_CODE=$?
if [[ $EXIT_CODE != 0 ]]; then
echo "${IMAGE_TAG} image tag not found"
exit 1
fi
- name: Checkout decidim-cfj cdk
uses: actions/checkout@v3
with:
repository: codeforjapan/decidim-cfj-cdk
path: decidim-cfj-cdk
- name: Setup Node
uses: actions/setup-node@v1
with:
node-version: '18'
- name: Cache node modules
id: cache-npm
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Install dependencies
run: npm install
working-directory: decidim-cfj-cdk
- name: Install dependencies
run: npm install -g aws-cdk
working-directory: decidim-cfj-cdk
- name: cdk deploy
run: cdk -c stage=$DEPLOY_ENV -c tag=$IMAGE_TAG deploy --all --require-approval never
working-directory: decidim-cfj-cdk
env:
AWS_DEFAULT_REGION: 'ap-northeast-1'
DEPLOY_ENV: ${{ inputs.deploy-env }}
IMAGE_TAG: ${{ inputs.deploy-env }}-${{ inputs.image-tag }}