-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path.gitlab-ci.yml
166 lines (156 loc) · 5.13 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
image: docker:latest
variables:
GIT_SUBMODULE_STRATEGY: recursive
DEV_GOOGLE_TAG: eu.gcr.io/papers-dev-kubernetes/tz-wrapped-frontend-dev:$CI_COMMIT_SHA
PROD_GOOGLE_TAG: eu.gcr.io/papers-kubernetes/tz-wrapped-frontend:$CI_COMMIT_SHA
TEST_TAG: tz_wrapped_frontend_test_$CI_COMMIT_SHA
DEV_GOOGLE_TAG_LATEST: eu.gcr.io/papers-dev-kubernetes/tz-wrapped-frontend-dev:latest
PROD_GOOGLE_TAG_LATEST: eu.gcr.io/papers-kubernetes/tz-wrapped-frontend:latest
stages:
- build
- test
# - qa
- build_serve
- publish
- deploy
build:
stage: build
script:
- docker build --target angular-build -t $TEST_TAG .
tags:
- docker
build_serve_dev:
stage: build_serve
script:
- docker build --build-arg RUN_ENV=development -t $DEV_GOOGLE_TAG .
only:
- develop
tags:
- docker
build_serve_prod:
stage: build_serve
script:
- docker build --build-arg RUN_ENV=production -t $PROD_GOOGLE_TAG .
only:
- master
tags:
- docker
test:
allow_failure: false
stage: test
script:
- docker run --name unit-$CI_COMMIT_SHA $TEST_TAG npm run test-ci
- docker run --name lint-$CI_COMMIT_SHA $TEST_TAG npm run lint-ci
- docker cp unit-$CI_COMMIT_SHA:/app/coverage/dapp-frontend/report-lcov/lcov.info lcov.info
- docker cp lint-$CI_COMMIT_SHA:/app/lintReport.json lintReport.json
after_script:
- docker rm -f unit-$CI_COMMIT_SHA || true
- docker rm -f lint-$CI_COMMIT_SHA || true
tags:
- docker
artifacts:
paths:
- lcov.info
- lintReport.json
# qa:
# allow_failure: false
# stage: qa
# script:
# - docker create --name qa-$CI_PIPELINE_ID $TEST_TAG npm run sonar-scanner -- -X
# -Dsonar.typescript.lcov.reportPaths=lcov.info
# -Dsonar.typescript.tslint.reportPaths=lintReport.json
# -Dsonar.test.inclusions=**/*.spec.ts
# -Dsonar.tests=src/
# -Dsonar.exclusions=**/node_modules/**,**/*.spec.ts
# -Dsonar.sources=src/
# -Dsonar.host.url=$SONAR_URL
# -Dsonar.login=$SONAR_LOGIN
# -Dsonar.gitlab.commit_sha=$CI_COMMIT_SHA
# -Dsonar.gitlab.ref_name=$CI_COMMIT_REF_NAME
# -Dsonar.gitlab.project_id=$CI_PROJECT_ID
# -Dsonar.branch.name=$CI_BUILD_REF_NAME
# - docker cp lcov.info qa-$CI_PIPELINE_ID:/app/lcov.info
# - docker cp lintReport.json qa-$CI_PIPELINE_ID:/app/lintReport.json
# - docker start -a qa-$CI_PIPELINE_ID
# after_script:
# - docker rm -f qa-$CI_PIPELINE_ID || true
# tags:
# - docker
publish_dev:
stage: publish
needs: ['build_serve_dev']
image: google/cloud-sdk
before_script:
- echo $GCLOUD_GOOGLE_KEY_DEV > key.json
- gcloud auth activate-service-account $GCLOUD_ACCOUNT_DEV --key-file key.json
- gcloud config set project $GCLOUD_PROJECT_DEV
- gcloud config set account $GCLOUD_ACCOUNT_DEV
- gcloud config set compute/zone $GCLOUD_ZONE
- gcloud auth configure-docker
script:
- docker tag $DEV_GOOGLE_TAG $DEV_GOOGLE_TAG_LATEST
- docker push $DEV_GOOGLE_TAG
- docker push $DEV_GOOGLE_TAG_LATEST
only:
- develop
tags:
- docker
publish_prod:
stage: publish
needs: ['build_serve_prod']
image: google/cloud-sdk
before_script:
- echo $GCLOUD_GOOGLE_KEY > key.json
- gcloud auth activate-service-account $GCLOUD_ACCOUNT --key-file key.json
- gcloud config set project $GCLOUD_PROJECT
- gcloud config set account $GCLOUD_ACCOUNT
- gcloud config set compute/zone $GCLOUD_ZONE
- gcloud auth configure-docker
script:
- docker tag $PROD_GOOGLE_TAG $PROD_GOOGLE_TAG_LATEST
- docker push $PROD_GOOGLE_TAG
- docker push $PROD_GOOGLE_TAG_LATEST
only:
- master
tags:
- docker
k8s-deploy-development:
stage: deploy
when: manual
image: google/cloud-sdk
before_script:
- echo $GCLOUD_GOOGLE_KEY_DEV > key.json
- gcloud auth activate-service-account $GCLOUD_ACCOUNT_DEV --key-file key.json
- gcloud config set project $GCLOUD_PROJECT_DEV
- gcloud config set account $GCLOUD_ACCOUNT_DEV
- gcloud config set compute/zone $GCLOUD_ZONE
- gcloud container clusters get-credentials papers-cluster-development
script:
- sed -i "s|_TO_BE_REPLACED_BY_IMAGE_TAG_|"$DEV_GOOGLE_TAG"|g" k8s/foundry/common/frontend/deployment.yaml
- kubectl apply -f k8s/foundry/common/namespace.yaml
- kubectl apply -f k8s/foundry/development/ --recursive
- kubectl apply -f k8s/foundry/common/ --recursive
only:
- develop
tags:
- docker
k8s-deploy-production:
stage: deploy
when: manual
image: google/cloud-sdk
before_script:
- echo $GCLOUD_GOOGLE_KEY > key.json
- gcloud auth activate-service-account $GCLOUD_ACCOUNT --key-file key.json
- gcloud config set account $GCLOUD_ACCOUNT
- gcloud config set project $GCLOUD_PROJECT
- gcloud config set compute/zone $GCLOUD_ZONE
- gcloud container clusters get-credentials papers-cluster-production
script:
- sed -i "s|_TO_BE_REPLACED_BY_IMAGE_TAG_|"$PROD_GOOGLE_TAG"|g" k8s/foundry/common/frontend/deployment.yaml
- kubectl apply -f k8s/foundry/common/namespace.yaml
- kubectl apply -f k8s/foundry/production/ --recursive
- kubectl apply -f k8s/foundry/common/ --recursive
only:
- master
tags:
- docker