-
Notifications
You must be signed in to change notification settings - Fork 0
123 lines (120 loc) · 4.17 KB
/
Copy pathdeploy-moonbase-alpha.yml
File metadata and controls
123 lines (120 loc) · 4.17 KB
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
name: moonbase-alpha
on:
push:
branches:
- develop
pull_request:
branches:
- develop
jobs:
build:
runs-on: ubuntu-latest
environment:
name: moonbase-alpha-development
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
steps:
# - name: Add .nvm to PATH
# run: echo 'export PATH="$HOME/.nvm:$PATH"' >> $HOME/.bashrc
# - name: Source .bashrc
# run: source $HOME/.bashrc
# - name: nvm
# run: nvm --help
# - name: nvm
# run: cat ~/.bashrc
- name: Assume Role
uses: aws-actions/configure-aws-credentials@v1
with:
role-to-assume: ${{ secrets.MBA_ROLE }}
aws-region: ${{ secrets.AWS_REGION }}
role-session-name: mba_cicd
aws-access-key-id: ${{ secrets.CICD_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.CICD_ACCESS_KEY }}
role-duration-seconds: 1200
- uses: actions/checkout@v3
id: checkout
- uses: actions/setup-node@v3
with:
node-version: 16
# Cache files in ./frontend
- name: Cache
uses: actions/cache@v3
id: use-cache
with:
path: |
node_modules/
.eslintcache
.stylelintcache
**/.cache
apps/**/node_modules/
packages/**/node_modules/
autotests/**/node_modules/
~/.cache/Cypress
key: develop-fe-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
develop-fe-
# Install dependencies and build the app
- name: Build React App
id: build-project
run: |
aws secretsmanager get-secret-value --secret-id ${{ secrets.MBA_BUCKET }} --query SecretString --output text | jq -r 'to_entries|map("\(.key)=\(.value|tostring)")|.[]' > apps/web/.env
yarn install --frozen-lockfile && yarn bootstrap && yarn build
rm apps/web/.env
cd apps/web/dist && tar cvzf ${GITHUB_SHA}-build.tar.gz *
mv ${GITHUB_SHA}-build.tar.gz ../../../
cd ../../../
# Upload the build as artifact
- name: Artifacts upload
id: upload-artifact
run: |
upload_path=$(echo ${{ secrets.MBA_BUCKET }} |sed s%-%\/%)
aws s3 cp ${GITHUB_SHA}-build.tar.gz ${{ secrets.ARTIFACT_STORAGE }}/$upload_path/${GITHUB_SHA}-build.tar.gz
## Notify on slack if there is a failure
- uses: act10ns/slack@v1
with:
status: ${{ job.status }}
steps: ${{ toJson(steps) }}
channel: ${{ secrets.SLACK_CHANNEL }}
if: failure()
deploy:
needs: [build]
runs-on: ubuntu-latest
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
environment:
name: moonbase-alpha-development
url: https://mba.dev.savval.io
steps:
- name: Assume Role
uses: aws-actions/configure-aws-credentials@v1
with:
role-to-assume: ${{ secrets.MBA_ROLE }}
aws-region: ${{ secrets.AWS_REGION }}
role-session-name: mba_cicd
aws-access-key-id: ${{ secrets.CICD_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.CICD_ACCESS_KEY }}
role-duration-seconds: 1200
# Download the artifact
- name: Artifacts upload
id: upload-artifact
run: |
upload_path=$(echo ${{ secrets.MBA_BUCKET }} |sed s%-%\/%)
aws s3 cp ${{ secrets.ARTIFACT_STORAGE }}/$upload_path/${GITHUB_SHA}-build.tar.gz $(pwd)/artifact.tar.gz
tar xvf artifact.tar.gz
rm artifact.tar.gz
# Upload the app on S3 bucket
- name: Deploy app build to S3 bucket
id: deploy
run: aws s3 sync . s3://${{ secrets.MBA_BUCKET }} --cache-control "max-age=120000" --delete
- name: Invalidate CloudFront
uses: chetan/invalidate-cloudfront-action@v2
env:
DISTRIBUTION: ${{ secrets.MBA_DISTRIBUTION_ID }}
PATHS: "/index.html"
- name: Notify the status of deploy on slack
uses: act10ns/slack@v1
with:
status: ${{ job.status }}
steps: ${{ toJson(steps) }}
channel: ${{ secrets.SLACK_CHANNEL }}
if: always()