-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuildspec.yml
56 lines (51 loc) · 1.88 KB
/
buildspec.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
version: 0.2
env:
secrets-manager:
LOGIN: prod/sonar:sonartoken
HOST: prod/sonar:HOST
Organization: prod/sonar:Organization
Project: prod/sonar:Project
phases:
install:
runtime-versions:
nodejs: 18
pre_build:
commands:
- apt-get update
- apt-get install -y jq
# Installing and setting up sonarqube for code quality analysis
- wget https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.7.0.2747-linux.zip
- unzip ./sonar-scanner-cli-4.7.0.2747-linux.zip
- ls $pwd
- export PATH=$PATH:./sonar-scanner-4.7.0.2747-linux/bin/
# Installing YARN using NPM
- npm install --global yarn
# Installing dependencies using YARN
- yarn install
# SonarQube analysis scanning as the basic test
- sonar-scanner -Dsonar.login=$LOGIN -Dsonar.host.url=$HOST -Dsonar.projectKey=$Project -Dsonar.organization=$Organization
- sleep 10
build:
commands:
# Building the react app into a static file.
- echo "Build started on `date`"
- yarn build
# Checking the result of the scan to either fail or pass the pipeline
- curl https://sonarcloud.io/api/qualitygates/project_status?projectKey=$Project >result.json
- cat result.json
- if [ $(jq -r '.projectStatus.status' result.json) = ERROR ]; then
echo "SonarQube analysis failed. Halting the pipeline.";
exit 1;
else
echo "SonarQube analysis passed. Proceeding with deployment..." ;
fi
# Copy the static file to AWS S3
- aws s3 sync build/ s3://muku-react-portfolio
# Invalidating cache ensure that users receive the most up-to-date and accurate content from our web application
- aws cloudfront create-invalidation --distribution-id E3M5TAQQXYP1 --paths "/*"
artifacts:
files:
- '**/*'
cache:
paths:
- '/root/.npm/**/*'