-
Notifications
You must be signed in to change notification settings - Fork 0
209 lines (198 loc) · 8.19 KB
/
release.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
name: Create release
on:
push:
tags:
- release-*
env:
ECR_REPOSITORY: appq-register-page
DEPLOY_PROD_BUCKET: tryber-production-source
DEPLOY_PROD_KEY: tryber-react-production-pipeline/source.zip
ASG_NAME: tryber-asg-tryber-react-production
PIPELINE: tryber-react-production-pipeline-pipeline
DEPLOY_PREPROD_BUCKET: tryber-preproduction-source
DEPLOY_PREPROD_KEY: tryber-react-preproduction-pipeline/source.zip
PREPROD_ASG_NAME: tryber-asg-tryber-react-preproduction
PREPROD_PIPELINE: tryber-react-preproduction-pipeline-pipeline
jobs:
push-to-ecr:
name: Push Image
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Get tag name
shell: bash
run: |
TAG=${GITHUB_REF##*/}
echo "##[set-output name=tag;]$TAG"
echo "##[set-output name=ECR_REPOSITORY;]$ECR_REPOSITORY"
id: extract_tag
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: eu-west-1
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build, tag, and push image to Amazon ECR
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: ${{ env.ECR_REPOSITORY }}
IMAGE_TAG: ${{ steps.extract_tag.outputs.tag }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
DOCKER_BUILDKIT=1 docker build --build-arg NPM_TOKEN=$NPM_TOKEN -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
release-to-preprod:
name: Release to PreProd
needs: push-to-ecr
runs-on: ubuntu-latest
environment: preproduction
outputs:
original_preprod_desired: ${{ steps.update-asg.outputs.original_desired }}
original_preprod_max: ${{ steps.update-asg.outputs.original_max }}
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Get tag name
shell: bash
run: |
TAG=${GITHUB_REF##*/}
echo "##[set-output name=tag;]$TAG"
echo "##[set-output name=ECR_REPOSITORY;]$ECR_REPOSITORY"
echo "##[set-output name=DEPLOY_PREPROD_BUCKET;]$DEPLOY_PREPROD_BUCKET"
echo "##[set-output name=DEPLOY_PREPROD_KEY;]$DEPLOY_PREPROD_KEY"
echo "##[set-output name=PREPROD_ASG_NAME;]$PREPROD_ASG_NAME"
echo "##[set-output name=PREPROD_PIPELINE;]$PREPROD_PIPELINE"
id: extract_tag
- name: "Generate dist zip"
run: |
cd deployment
echo -n "${ECR_REPOSITORY}:${{steps.extract_tag.outputs.tag}}" > docker-image.txt
zip dist.zip *
- uses: zdurham/s3-upload-github-action@master
env:
S3_BUCKET: ${{ steps.extract_tag.outputs.DEPLOY_PREPROD_BUCKET }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: "eu-west-1"
FILE: ./deployment/dist.zip
S3_KEY: ${{ steps.extract_tag.outputs.DEPLOY_PREPROD_KEY }}
- name: configure AWS creds
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: eu-west-1
- name: Update asg capacity to 1
uses: AppQuality/update-desired-asg-instances@v1.0.0
id: update-asg
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: "eu-west-1"
ASG_NAME: ${{ steps.extract_tag.outputs.PREPROD_ASG_NAME }}
DESIRED_INSTANCES: 1
MAX_INSTANCES: 1
- name: Start CodePipeline
uses: moia-oss/aws-codepipeline-trigger@v1
with:
pipeline: ${{ steps.extract_tag.outputs.PREPROD_PIPELINE }}
wait: true
prepare-release-for-prod:
name: Prepare release to Prod
needs: push-to-ecr
runs-on: ubuntu-latest
environment: production
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Get tag name
shell: bash
run: |
TAG=${GITHUB_REF##*/}
echo "##[set-output name=tag;]$TAG"
echo "##[set-output name=ECR_REPOSITORY;]$ECR_REPOSITORY"
echo "##[set-output name=DEPLOY_BUCKET;]$DEPLOY_BUCKET"
echo "##[set-output name=DEPLOY_PROD_BUCKET;]$DEPLOY_PROD_BUCKET"
echo "##[set-output name=DEPLOY_PROD_KEY;]$DEPLOY_PROD_KEY"
echo "##[set-output name=ASG_NAME;]$ASG_NAME"
echo "##[set-output name=PIPELINE;]$PIPELINE"
id: extract_tag
- name: "Generate dist zip"
run: |
cd deployment
echo -n "${{ steps.extract_tag.outputs.ECR_REPOSITORY }}:${{steps.extract_tag.outputs.tag}}" > docker-image.txt
zip dist.zip *
- uses: zdurham/s3-upload-github-action@master
env:
S3_BUCKET: ${{ steps.extract_tag.outputs.DEPLOY_PROD_BUCKET }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: "eu-west-1"
FILE: ./deployment/dist.zip
S3_KEY: ${{ steps.extract_tag.outputs.DEPLOY_PROD_KEY }}
- name: configure AWS creds
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: eu-west-1
- name: Update asg capacity to 2
uses: AppQuality/update-desired-asg-instances@v1.0.0
id: update-asg
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: "eu-west-1"
ASG_NAME: ${{ steps.extract_tag.outputs.ASG_NAME }}
DESIRED_INSTANCES: 2
MAX_INSTANCES: 2
- name: Start CodePipeline
uses: moia-oss/aws-codepipeline-trigger@v1
with:
pipeline: ${{ steps.extract_tag.outputs.PIPELINE }}
wait: true
- name: Restore asg capacity
uses: AppQuality/update-desired-asg-instances@v1.0.0
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: "eu-west-1"
ASG_NAME: ${{ steps.extract_tag.outputs.ASG_NAME }}
DESIRED_INSTANCES: ${{ steps.update-asg.outputs.original_desired }}
MAX_INSTANCES: ${{ steps.update-asg.outputs.original_max }}
- name: Get deployment url
uses: AppQuality/get-codeploy-from-codepipeline@1.0.0
id: codedeploy
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: "eu-west-1"
PIPELINE_NAME: ${{ steps.extract_tag.outputs.PIPELINE }}
- name: Update release with deployment url
uses: tubone24/update_release@v1.0
env:
GITHUB_TOKEN: ${{ github.token }}
with:
body: "[![](https://img.shields.io/badge/AWS-Redeploy-blueviolet)](${{ steps.codedeploy.outputs.codedeploy_url }})"
isAppendBody: true
disable-preprod-on-release:
name: Disable PreProd
needs: [prepare-release-for-prod, release-to-preprod]
runs-on: ubuntu-latest
environment: preproduction
steps:
- name: Restore asg capacity
uses: AppQuality/update-desired-asg-instances@v1.0.0
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: "eu-west-1"
ASG_NAME: ${{ env.PREPROD_ASG_NAME }}
DESIRED_INSTANCES: ${{needs.release-to-preprod.outputs.original_preprod_desired }}
MAX_INSTANCES: ${{needs.release-to-preprod.outputs.original_preprod_max }}