-
Notifications
You must be signed in to change notification settings - Fork 0
144 lines (127 loc) · 5.56 KB
/
workflow.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
name: BnbBankCI
on:
push:
branches:
- staging
- production
jobs:
# deploy-api:
# name: Deploy Server Api
# runs-on: ubuntu-latest
# steps:
# # This step checks out a copy of your repository.
# - name: Checkout code
# uses: actions/checkout@v3
# - name: Get branch names
# id: branch-names
# uses: tj-actions/branch-names@v8
# # This step sets up Node.js environment.
# - name: Setup Node.js
# uses: actions/setup-node@v3
# if: success()
# # This step installs the Serverless Framework globally.
# - name: Install Serverless Framework
# run: |
# cd backend
# npm install -g serverless serverless-prune-plugin serverless-iam-roles-per-function
# if: success()
# # This step sets up PHP environment with the specified version.
# - name: Setup PHP
# uses: shivammathur/setup-php@v2
# with:
# php-version: "8.2"
# if: success()
# # This step installs Composer dependencies with the specified options.
# - name: Install Composer dependencies
# run: |
# cd backend
# composer install --prefer-dist --optimize-autoloader --no-dev
# if: success()
# # This step deploys your application to AWS Lambda using the Serverless Framework.
# - name: Deploy to AWS Lambda
# run: |
# cd backend
# echo "APP_KEY=${{ vars.APP_KEY }}" >> .env
# echo "APP_NAME=${{ vars.SUBDOMAIN }}" >> .env
# echo "SUBDOMAIN=${{ vars.SUBDOMAIN }}" >> .env
# echo "DOMAIN=${{ vars.DOMAIN }}" >> .env
# echo "DB_URI=${{ secrets.DB_URI }}" >> .env
# echo "JWT_SECRET=${{ secrets.JWT_SECRET }}" >> .env
# echo "AWS_HOSTED_ZONE_ID=${{ vars.AWS_HOSTED_ZONE_ID }}" >> .env
# echo "AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_ID }}" >> .env
# echo "AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY }}" >> .env
# serverless deploy --config serverless.yml --stage ${{ steps.branch-names.outputs.current_branch }} --region ${{ vars.AWS_DEFAULT_REGION }} --verbose
# if: success()
deploy-web:
name: Deploy Web App
runs-on: ubuntu-latest
steps:
# This step checks out a copy of your repository.
- name: Checkout code
uses: actions/checkout@v3
- name: Get branch names
id: branch-names
uses: tj-actions/branch-names@v8
# This step sets up Node.js environment.
- name: Setup Node.js
uses: actions/setup-node@v3
if: success()
# This step installs the Serverless Framework globally.
- name: Install Serverless Framework
run: |
cd frontend
npm install -g serverless serverless-dotenv-plugin serverless-export-outputs fast-xml-parser
if: success()
# This step expose variables to environment
- name: Expose required environment variables
run: |
echo "BRANCH=${{ steps.branch-names.outputs.current_branch }}" >> $GITHUB_ENV
echo "DOMAIN=${{ vars.DOMAIN }}" >> $GITHUB_ENV
echo "APP_NAME=${{ vars.SUBDOMAIN }}-web" >> $GITHUB_ENV
echo "SUBDOMAIN=${{ vars.SUBDOMAIN }}" >> $GITHUB_ENV
echo "AWS_HOSTED_ZONE_ID=${{ vars.AWS_HOSTED_ZONE_ID }}" >> $GITHUB_ENV
echo "AWS_DEFAULT_REGION=${{ vars.AWS_DEFAULT_REGION }}" >> $GITHUB_ENV
echo "AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_ID }}" >> $GITHUB_ENV
echo "AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY }}" >> $GITHUB_ENV
if: success()
# This step build reactjs application to be deployed.
- name: Build ReactJS application
run: |
cd frontend
rm -rf .env
echo "REACT_APP_API_URL=https://${SUBDOMAIN}-api.$([ "${BRANCH}" != "production" ] && echo "${BRANCH}.")${DOMAIN}" >> .env
cat .env
yarn --dev --production=false
yarn build
if: success()
# This step deploys the application resources to AWS using the Serverless Framework.
- name: Deploy resources to AWS with Serverless Framework
run: |
cd frontend
rm -rf .env
echo "DOMAIN=${DOMAIN}" >> .env
echo "AWS_HOSTED_ZONE_ID=${AWS_HOSTED_ZONE_ID}" >> .env
cat .env
serverless deploy --config serverless-cert.yml --stage ${BRANCH} --region us-east-1 --verbose
SLS_WEBCERT_OUTPUT=$(cat sls-webcert-output.json)
$(echo "${SLS_WEBCERT_OUTPUT}" | jq -r 'keys[] as $k | "export \($k)=\(.[$k])"')
echo "AWS_ACM_ARN=${CertificateDomainArn}" >> .env
serverless deploy --config serverless.yml --stage ${BRANCH} --region ${AWS_DEFAULT_REGION} --verbose
if: success()
# This step configures aws cli credentials
- name: Install AWS CLI
run: |
sudo apt update
sudo apt install awscli
aws --version
if: success()
# This step deploys your application to AWS Lambda using the Serverless Framework.
- name: Release application on AWS S3 and invalidate CloudFront cache
run: |
S3_DOMAIN="${APP_NAME}.$([ "${BRANCH}" != "production" ] && echo "${BRANCH}.")${DOMAIN}"
echo "S3_DOMAIN=${S3_DOMAIN}"
aws s3 sync frontend/build/ s3://${S3_DOMAIN}
SLS_OUTPUT=$(cat sls-output.json)
$(echo "${SLS_OUTPUT}" | jq -r 'keys[] as $k | "export \($k)=\(.[$k])"')
aws cloudfront create-invalidation --distribution-id ${CDNDistributionId} --paths "/*"
if: success()