-
Notifications
You must be signed in to change notification settings - Fork 17
70 lines (61 loc) · 2.41 KB
/
backdeploy.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
name: Deploy backend
on:
push:
branches:
- main
paths:
- "server/**"
- ".github/workflows/backdeploy.yaml"
env:
AWS_DEFAULT_REGION: ${{ vars.AWS_DEFAULT_REGION }}
AWS_ACCESS_KEY_ID: ${{ secrets.CI_CD_AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.CI_CD_AWS_SECRET_ACCESS_KEY }}
S3_BUCKET: ${{ vars.IAC_BUCKET_NAME }}
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Restore gradle dependencies
uses: actions/cache@v2
with:
path: "~/.gradle"
key: ${{ runner.os }}-modules-${{ hashFiles('**/server/build.gradle') }}
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: "11"
distribution: "adopt"
- name: Validate Gradle wrapper
uses: gradle/wrapper-validation-action@e6e38bacfdf1a337459f332974bb2327a31aaf4b
- name: Add version info
run: |
export GIT_HASH=$(git rev-parse --short HEAD)
sed -i "s|version: 1.0.0|version: ${GIT_HASH}|g" server/src/main/resources/application.yaml
- name: Build jar
run: ./server/gradlew build -p server -x test
- name: Build and push to ECR
run: |
cd server
./gradlew clean build --info -x test
export STAGE=prod
GIT_HASH=$(git rev-parse --short HEAD)
# Get value from ssm and export it
ECR_URL_PARAM=$(aws ssm get-parameter --name "/$STAGE/ecr/url/statistics_server")
ECR_URL=$(echo $ECR_URL_PARAM | jq -r '.Parameter.Value')
# Before and after the bar
ECR_URL_ROOT="${ECR_URL%%/*}"
ECR_URL_SPEC="${ECR_URL##*/}"
aws ecr get-login-password --region ${{ env.AWS_DEFAULT_REGION }} | docker login --username AWS --password-stdin $ECR_URL_ROOT
docker build -t $ECR_URL_SPEC .
docker tag $ECR_URL_SPEC:latest $ECR_URL:latest
docker tag $ECR_URL_SPEC:latest $ECR_URL:$GIT_HASH
docker push $ECR_URL:latest
docker push $ECR_URL:$GIT_HASH
- name: Blue green deployment
run: |
aws deploy create-deployment \
--application-name statistics-server-code-deploy-app-prod \
--deployment-group-name statistics-server-code-deployment-group-prod \
--s3-location bucket=$S3_BUCKET,key=app-spec/statistics-spec-prod.yaml,bundleType=YAML