-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
144 lines (134 loc) · 4.16 KB
/
.gitlab-ci.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
.common_template: &branch_definition
only:
- develop
.node_template: &node_definition
image: node:10.15.3
cache:
paths:
- node_modules/
.python_template: &python_definition
image: python:3.5
before_script:
- echo Installing AWS CLI
- pip install awscli --ignore-installed six
stages:
- test
- build
- upload
- create_app
- deploy
# Executes eslint and runs unit tests.
test:
<<: *node_definition
stage: test
<<: *branch_definition
script:
- npm install
- npm run lint
- npm test -- --coverage
artifacts:
paths:
- coverage/
# Builds the application and zips it up.
build:
<<: *node_definition
stage: build
<<: *branch_definition
script:
- npm run build
artifacts:
paths:
- vault-pam-ui.zip
expire_in: 15 mins
upload:
<<: *python_definition
stage: upload
<<: *branch_definition
variables:
AWS_DEFAULT_REGION: "us-east-1"
EB_APP_NAME: "vault-pam-ui"
ZIP_FILE: "vault-pam-ui.zip"
S3_BUCKET: "elasticbeanstalk-us-east-1-163714151155"
before_script:
- echo Installing AWS CLI
- pip install awscli --ignore-installed six
script:
- export BUILD_VERSION=`date "+%Y-%m-%d-%H-%M-%S"`
- echo Setting build version to $BUILD_VERSION
- export VERSIONED_ZIP_FILE=$BUILD_VERSION.zip
- echo BUILD_VERSION=$BUILD_VERSION >> build_vars
- echo VERSIONED_ZIP_FILE=$VERSIONED_ZIP_FILE >> build_vars
- echo S3_BUCKET=$S3_BUCKET >> build_vars
- echo AWS_DEFAULT_REGION=$AWS_DEFAULT_REGION >> build_vars
- echo EB_APP_NAME=$EB_APP_NAME >> build_vars
- echo Renaming $ZIP_FILE to $VERSIONED_ZIP_FILE
- mv $ZIP_FILE $VERSIONED_ZIP_FILE
- aws s3 cp $VERSIONED_ZIP_FILE "s3://$S3_BUCKET"
artifacts:
paths:
- build_vars
expire_in: 15 mins
# Deploys the zip to Elastic Beanstalk and create the application.
create_app:
<<: *python_definition
stage: create_app
<<: *branch_definition
script:
- source build_vars
- export BUILD_VERSION
- export VERSIONED_ZIP_FILE
- export S3_BUCKET
- export AWS_DEFAULT_REGION
- export EB_APP_NAME
- export EB_VERSION=v.$BUILD_VERSION
- echo Creating ElasticBeanstalk Application Version $EB_VERSION
- aws elasticbeanstalk create-application-version --application-name $EB_APP_NAME --version-label $EB_VERSION --source-bundle S3Bucket=$S3_BUCKET,S3Key=$VERSIONED_ZIP_FILE --auto-create-application
- echo Application Created!
# Update the enterprise Elastic Beanstalk environment with the latest build.
deploy_enterprise:
<<: *python_definition
stage: deploy
<<: *branch_definition
variables:
EB_APP_ENV: "development"
script:
- source build_vars
- export BUILD_VERSION
- export VERSIONED_ZIP_FILE
- export S3_BUCKET
- export AWS_DEFAULT_REGION
- export EB_APP_NAME
- export EB_VERSION=v.$BUILD_VERSION
- echo Updating ElasticBeanstalk Application Version $EB_VERSION Environment $EB_APP_ENV
- aws elasticbeanstalk update-environment --application-name $EB_APP_NAME --environment-name $EB_APP_ENV --version-label $EB_VERSION --option-settings Namespace=aws:elasticbeanstalk:application:environment,OptionName=EB_VERSION,Value=$EB_VERSION
- echo Done! Deployed!
# Update the standard Elastic Beanstalk environment with the latest build.
deploy_standard:
<<: *python_definition
stage: deploy
<<: *branch_definition
variables:
EB_APP_ENV: "internal-mgs"
script:
- source build_vars
- export BUILD_VERSION
- export VERSIONED_ZIP_FILE
- export S3_BUCKET
- export AWS_DEFAULT_REGION
- export EB_APP_NAME
- export EB_VERSION=v.$BUILD_VERSION
- echo Updating ElasticBeanstalk Application Version $EB_VERSION Environment $EB_APP_ENV
- aws elasticbeanstalk update-environment --application-name $EB_APP_NAME --environment-name $EB_APP_ENV --version-label $EB_VERSION --option-settings Namespace=aws:elasticbeanstalk:application:environment,OptionName=EB_VERSION,Value=$EB_VERSION
- echo Done! Deployed!
pages:
stage: build
dependencies:
- test
script:
- rm -rf public
- mv coverage/lcov-report/ public/
artifacts:
paths:
- public
expire_in: 30 days
<<: *branch_definition