-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
157 lines (144 loc) · 4.6 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
image: docker:stable
stages:
- test_and_build
- build_image
- provision
- deploy
test_and_build:
image: node:18
stage: test_and_build
script:
- npm ci
- npm run test
- npm run dist
artifacts:
paths:
- dist/
push_master_to_github:
stage: deploy
allow_failure: true
before_script:
- apk --update add git
- which ssh-agent || ( apk add openssh-client )
- eval $(ssh-agent -s)
- echo "$GITHUB_SSH_KEY" | ssh-add -
- mkdir -p ~/.ssh
- ssh-keyscan -H github.com >> ~/.ssh/known_hosts
script:
- git checkout master
- git push [email protected]:UH-StudentServices/eduviewer-frontend.git master
only:
- master
.openshift_image: &openshift_image_definition
image: docker:20.10.16
services:
- docker:20.10.16-dind
before_script:
# Install openshift client
- apk add --update tar gzip curl ca-certificates gettext && rm -rf /var/cache/apk/*
- curl -sLo /tmp/oc.tar.gz https://mirror.openshift.com/pub/openshift-v4/x86_64/clients/ocp/stable-4.10/openshift-client-linux.tar.gz
- tar xzvf /tmp/oc.tar.gz -C /usr/local/bin
- rm -rf /tmp/oc.tar.gz
.provision_openshift_stack: &provision_openshift_stack_definition
<<: *openshift_image_definition
stage: provision
script:
- export IMAGE_TAG=${IMAGE_TAG_PREFIX}-${CI_COMMIT_SHA}
- oc login --server=$OC_SERVER --token=$OC_SA_TOKEN
- echo "getting tls cert"
- oc get secret $OC_TLS_SECRET -o jsonpath='{.data.TLS_CERTIFICATE}' | base64 -d
- >-
oc process -f ./openshift
-p STAGE=$OC_STAGE
-p STACK=$OC_STACK
-p HOST=$OC_HOST
-p ROUTE_TYPE=$OC_ROUTE_TYPE
-p TLS_SECRET_NAME=$OC_TLS_SECRET
-p CERT_ISSUER=$OC_CERT_ISSUER
| oc apply -f -
- export IMAGE_REPOSITORY=$REGISTRY_URL/tike/eduviewer-frontend
- oc tag ${IMAGE_REPOSITORY}:${IMAGE_TAG} ${OC_IMAGE_STREAM}:${CI_COMMIT_SHA}
- oc tag ${IMAGE_REPOSITORY}:${IMAGE_TAG} ${OC_IMAGE_STREAM}:latest
when: manual
provision_openshift_stack_qa:
variables:
OC_SERVER: $OC_SERVER_TEST
OC_SA_TOKEN: $OC_SA_TOKEN_TEST
OC_STAGE: qa
OC_STACK: qa
OC_HOST: eduviewer-qa.it.helsinki.fi
OC_TLS_SECRET: eduviewer-qa-tls
OC_CERT_ISSUER: acme-eduviewer-qa
OC_IMAGE_STREAM: qa-frontend
OC_ROUTE_TYPE: default
IMAGE_TAG_PREFIX: qa
<<: *provision_openshift_stack_definition
provision_openshift_stack_prod:
variables:
OC_SERVER: $OC_SERVER_PROD
OC_SA_TOKEN: $OC_SA_TOKEN_PROD
OC_STAGE: prod
OC_STACK: prod
OC_HOST: eduviewer.it.helsinki.fi
OC_TLS_SECRET: acme-eduviewer-it-helsinki-fi
OC_CERT_ISSUER: acme-eduviewer
OC_IMAGE_STREAM: prod-frontend
OC_ROUTE_TYPE: external
IMAGE_TAG_PREFIX: prod
<<: *provision_openshift_stack_definition
.build_push_image_openshift: &build_push_image_openshift_scripts
- export IMAGE_REPOSITORY=$REGISTRY_URL/tike/eduviewer-frontend
- export IMAGE_TAG=${IMAGE_TAG_PREFIX}-${CI_COMMIT_SHA}
- docker login -u="$REGISTRY_USER" -p="$REGISTRY_TOKEN" $REGISTRY_URL
- sed "s/\${SERVER_NAME}/$SERVER_NAME/g" ci/build/frontend/nginx.conf.template > ./default.conf
- docker build -f ci/build/frontend/Dockerfile -t $IMAGE_REPOSITORY:$IMAGE_TAG .
- docker push $IMAGE_REPOSITORY:$IMAGE_TAG
build_image_openshift_qa:
<<: *openshift_image_definition
stage: build_image
only:
- master
variables:
SERVER_NAME: eduviewer-qa.it.helsinki.fi
IMAGE_TAG_PREFIX: qa
script:
- *build_push_image_openshift_scripts
build_image_openshift_prod:
<<: *openshift_image_definition
stage: build_image
only:
- master
variables:
SERVER_NAME: eduviewer.it.helsinki.fi
IMAGE_TAG_PREFIX: prod
script:
- *build_push_image_openshift_scripts
.deploy_image_openshift: &deploy_image_openshift_scripts
- export IMAGE_REPOSITORY=$REGISTRY_URL/tike/eduviewer-frontend
- export IMAGE_TAG=${IMAGE_TAG_PREFIX}-${CI_COMMIT_SHA}
- oc login --server=$OC_SERVER --token=$OC_SA_TOKEN
- oc tag ${IMAGE_REPOSITORY}:${IMAGE_TAG} ${OC_IMAGE_STREAM}:${CI_COMMIT_SHA}
- oc tag ${IMAGE_REPOSITORY}:${IMAGE_TAG} ${OC_IMAGE_STREAM}:latest
deploy_image_openshift_qa:
<<: *openshift_image_definition
stage: deploy
variables:
OC_SERVER: $OC_SERVER_TEST
OC_SA_TOKEN: $OC_SA_TOKEN_TEST
OC_IMAGE_STREAM: qa-frontend
IMAGE_TAG_PREFIX: qa
script:
- *deploy_image_openshift_scripts
only:
- master
deploy_image_openshift_prod:
<<: *openshift_image_definition
stage: deploy
when: manual
variables:
OC_SERVER: $OC_SERVER_PROD
OC_SA_TOKEN: $OC_SA_TOKEN_PROD
OC_IMAGE_STREAM: prod-frontend
IMAGE_TAG_PREFIX: prod
script:
- *deploy_image_openshift_scripts