-
Notifications
You must be signed in to change notification settings - Fork 8
/
.gitlab-ci.yml
152 lines (144 loc) · 3.67 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
variables:
SENTRY_URL: https://sentry.intility.no/
SENTRY_ORG: intility
SENTRY_PROJECT: $CI_PROJECT_NAME
OPENSHIFT_SERVER: api.openshift.intility.com:6443
# Configure these variables in Secure Variables:
# SENTRY_DSN: my.sentry.dsn
# SENTRY_AUTH_TOKEN: my.sentry.token
# OPENSHIFT_TOKEN: my.openshift.token
stages:
- build
- test
- image
- sentry
- deploy
default:
interruptible: true
# --- build ---
build:
image: node:lts
stage: build
variables:
VITE_SENTRY_DSN: $SENTRY_DSN
VITE_SENTRY_ENVIRONMENT: $CI_ENVIRONMENT_NAME
environment:
name: $ENVIRONMENT_NAME
action: prepare
before_script:
- npm ci
script:
- npm run build
artifacts:
paths:
- dist
expire_in: 2 weeks
rules:
- if: "$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH"
variables:
ENVIRONMENT_NAME: dev
VITE_SENTRY_RELEASE: $CI_PIPELINE_IID
- if: "$CI_COMMIT_TAG"
variables:
ENVIRONMENT_NAME: prod
VITE_SENTRY_RELEASE: $CI_COMMIT_TAG
# --- test ---
test:
image: node:lts
stage: test
before_script:
- npm ci
script:
- npm run test
needs: []
# --- docker image ---
image:create:
stage: image
image:
name: gcr.io/kaniko-project/executor:debug
entrypoint: [""]
script:
- echo $DOCKER_AUTH_CONFIG > /kaniko/.docker/config.json
- /kaniko/executor
--context $CI_PROJECT_DIR
--dockerfile Dockerfile.CI
--destination $CI_REGISTRY_IMAGE:$IMAGE_TAG
--destination $CI_REGISTRY_IMAGE:$IMAGE_VERSION
rules:
- if: "$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH"
variables:
IMAGE_TAG: dev
IMAGE_VERSION: $CI_PIPELINE_IID
- if: "$CI_COMMIT_TAG"
variables:
IMAGE_TAG: latest
IMAGE_VERSION: $CI_COMMIT_TAG
needs:
- build
# --- sentry ---
sentry:
stage: sentry
image: getsentry/sentry-cli
variables:
GIT_DEPTH: 0
script:
- sentry-cli releases new $VERSION
- sentry-cli releases files $VERSION upload-sourcemaps --url-prefix '~/assets' dist/assets --rewrite
- sentry-cli releases finalize $VERSION
- sentry-cli releases set-commits --auto $VERSION || echo 'Found no commits to assign to release.'
- sentry-cli releases deploys $VERSION new -e $SENTRY_ENV
retry: 1
rules:
- if: "$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH"
variables:
SENTRY_ENV: dev
VERSION: $CI_PIPELINE_IID
- if: "$CI_COMMIT_TAG"
variables:
SENTRY_ENV: prod
VERSION: $CI_COMMIT_TAG
needs:
- build
# --- deployment ---
deploy:dev:
stage: deploy
image:
name: intility/helm-oc:latest
entrypoint: [""]
variables:
HELM_EXPERIMENTAL_OCI: 1
IMAGE_TAG: $CI_PIPELINE_IID
ROUTE: $CI_PROJECT_NAME-dev.apps.int.intility.no
environment:
name: dev
url: https://$CI_PROJECT_NAME-dev.apps.int.intility.no
before_script:
- oc login $OPENSHIFT_SERVER --token=$OPENSHIFT_TOKEN
script:
- helm upgrade
--install $CI_ENVIRONMENT_SLUG ./chart
--set nameOverride=$CI_PROJECT_NAME
--set image.repository=$CI_REGISTRY_IMAGE
--set image.tag=$IMAGE_TAG
--set registry.url=$CI_REGISTRY
--set registry.user=$CI_DEPLOY_USER
--set registry.password=$CI_DEPLOY_PASSWORD
--set route=$ROUTE
--set replicaCount=2
rules:
- if: "$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH"
needs:
- test
- image:create
# example production deployment job, remove the dot to enable
.deploy:prod:
extends: deploy:dev
variables:
IMAGE_TAG: $CI_COMMIT_TAG
ROUTE: $CI_PROJECT_NAME.apps.int.intility.no
environment:
name: prod
url: https://$CI_PROJECT_NAME.apps.int.intility.no
rules:
- if: "$CI_COMMIT_TAG"
when: manual