-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildspec.yml
145 lines (131 loc) · 5.14 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
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
version: 0.2
phases:
install:
runtime-versions:
python: 3.9
commands:
# initialize environment
- |
if [ "${BRANCH}" != prod ]
then
export ENV="-${BRANCH}"
else
export ENV=""
fi
apt-get update -y
apt-get install -y wait-for-it
# start up Docker
- |
nohup /usr/local/bin/dockerd --host=unix:///var/run/docker.sock --host=tcp://0.0.0.0:2375 --storage-driver=overlay&
timeout 15 sh -c "until docker info; do echo .; sleep 1; done"
# log into ECR
- |
aws ecr get-login-password --region $AWS_DEFAULT_REGION |\
docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com
# pull base images
- |
bash -c '
docker pull $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/${APPLICATION}-owasp:${BRANCH^}
'
# # install Testing and Documentation Dependencies
# - |
# pip install behave==1.2.6 \
# behave-html-formatter==0.9.8 \
# requests==2.26.0 \
# selenium==4.0.0 \
# git-remote-codecommit==1.15.1
# Download Sonar Scanner
- |
curl https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.6.2.2472-linux.zip \
-o "sonar_scanner.zip"
unzip sonar_scanner.zip > /dev/null 2>&1
export PATH=$(pwd)/sonar-scanner-4.6.2.2472-linux/bin/:$PATH
pre_build:
commands:
# TODO: Run Unit Tests
# TODO: Linting
# SonarQube static code analysis
- |
sonar-scanner \
-Dsonar.projectKey=${APPLICATION}-frontend${ENV} \
-Dsonar.host.url=https://$SONAR_URL \
-Dsonar.login=$SONAR_TOKEN \
-Dsonar.log.level=DEBUG \
-Dsonar.sources=$(pwd)/frontend/src/ \
-Dsonar.exclusions=**/*.json,**/*.css,**/*.scss,**/*.svg,**/*.html \
-Dsonar.sourceEncoding=UTF-8 \
# see: https://docs.sonarqube.org/latest/analysis/coverage/
build:
commands:
- |
bash -c '
docker build -t ${APPLICATION}-backend:${BRANCH^} .
docker tag ${APPLICATION}-backend:${BRANCH^} \
$AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/${APPLICATION}-frontend:${BRANCH^}
'
post_build:
commands:
# Start Up Cluster
# - |
# bash -c '
# docker run --publish 8000:8000 \
# --name ${APPLICATION}_backend \
# --env COGNITO_USER_POOL=$POOL_ID \
# --env COGNITO_AUDIENCE=$CLIENT_ID \
# --env COGNITO_AWS_REGION=$AWS_DEFAULT_REGION \
# --env APP_ENV=test \
# --env APP_PORT=8000 \
# --detach \
# $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/${APPLICATION}-backend:${BRANCH^}
# wait-for-it localhost:8000
# docker run --publish 8080:8080 \
# --name ${APPLICATION}_frontend
# --detach \
# $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/${APPLICATION}-frontend:${BRANCH^}
# wait-for-it localhost:8080
# '
# BDD Tests
# - |
# bash -c '
# git clone codecommit://${APPLICATION}-test-harness
# cd ${APPLICATION}-test-harness/python
# export FRONTEND_HOST_URL="http://localhost:8080"
# chmod +x ./configure && ./configure web
# behave -t "@Web" \
# --no-skipped \
# --summary \
# --outfile behave-report-frontend.html \
# --format behave_html_formatter:HTMLFormatter \
# || true
# aws s3 cp ./behave-report-frontend.html \
# s3://${APPLICATION}-coverage/test-coverage/bdd/behave-report-frontend.html
# cd ../..
# '
# OWASP ZAP Scan
# - |
# bash -c '
# mkdir -p $(pwd)/out
# chmod 777 $(pwd)/out
# docker run --volume $(pwd)/out:/zap/wrk/:rw \
# --network host \
# --tty \
# 894427396428.dkr.ecr.us-east-1.amazonaws.com/innolab-owasp:Dev \
# zap-full-scan.py -t http://localhost:8080 -r OWASP_report_frontend.html
# aws s3 cp ./out/OWASP_report_frontend.html s3://${APPLICATION}-data-files/zap_report/OWASP_report_frontend.html
# '
# TODO: Generate Documentation
# Invalidate Coverage Distribution Cache
# - |
# aws cloudfront create-invalidation \
# --distribution-id $COVERAGE_DISTRIBUTION_ID \
# --paths "/*"
# Kill Cluster
# - |
# bash -c '
# docker container stop ${APPLICATION}_backend && docker container rm ${APPLICATION}_backend
# '
# Push image to ECR -> Signal deploy pipeline to take over
- |
bash -c '
docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/${APPLICATION}-frontend:${BRANCH^}
'