-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
188 lines (168 loc) · 6.59 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
image: alpine:latest
variables:
# KUBE_INGRESS_BASE_DOMAIN is the application deployment domain and should be set as a variable at the group or project level.
KUBE_INGRESS_BASE_DOMAIN: nonprod.tower.cdrentertainment.com
HELM_SCALE_EXTRA_ARGS: --set postgresql.enabled="false"
K8S_SECRET_GRAPHITE: "$GRAPHITE"
K8S_SECRET_LOGGLY_URL: "$LOGGLY_URL"
K8S_SECRET_RUMBLE_COMPONENT: "$RUMBLE_COMPONENT"
K8S_SECRET_RUMBLE_CONFIG_SERVICE_URL: "$CONFIG_SERVICE_URL"
K8S_SECRET_RUMBLE_DEPLOYMENT: "$RUMBLE_DEPLOYMENT"
K8S_SECRET_MONGODB_NAME: "$RUMBLE_COMPONENT-$RUMBLE_DEPLOYMENT"
K8S_SECRET_STICKY_CHECK_FREQUENCY_SECONDS: "$STICKY_CHECK_FREQUENCY_SECONDS"
K8S_SECRET_VERBOSE_LOGGING: "$VERBOSE_LOGGING"
K8S_SECRET_COMMIT_SHA: "$CI_COMMIT_SHA"
# from gitlab project ci variables - normally env specific
K8S_SECRET_RUMBLE_KEY: "$RUMBLE_KEY"
K8S_SECRET_MONGODB_URI: "$MONGODB_URI"
K8S_SECRET_PLATFORM_COMMON: "$PLATFORM_COMMON"
DOCKER_DRIVER: overlay2
DEPLOY_TYPE: "kubernetes" # "kubernetes", "beanstalk", "both"
ROLLOUT_RESOURCE_TYPE: deployment
DOCKER_TLS_CERTDIR: "" # https://gitlab.com/gitlab-org/gitlab-runner/issues/4501
# Form variables for restart-service job
RESTART_SERVICE:
value: "false"
options:
- "false"
- "true"
description: "Run the restart service script"
RESTART_SERVICE_ENV:
value: "dev"
description: "Environment to restart service in"
options:
- "dev"
- "stage-a"
- "stage-b"
- "prod-a1"
- "prod-a2"
stages:
- app_build
- scan
- build
- deploy # dummy stage to follow the template guidelines
- dev
- staging
- production
- production-2
- performance
- cleanup
- jobs
workflow:
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
when: never
- when: always
build_app:
stage: app_build
image: mcr.microsoft.com/dotnet/sdk:8.0
tags:
- kubernetes
script:
- dotnet nuget add source --username $BOT_USER --password $BOT_PAT --store-password-in-clear-text --name platform "$CI_SERVER_URL/api/v4/groups/5/-/packages/nuget/index.json"
- dotnet nuget add source --username $BOT_USER --password $BOT_PAT --store-password-in-clear-text --name tower "$CI_SERVER_URL/api/v4/groups/6/-/packages/nuget/index.json"
- dotnet nuget add source --username $BOT_USER --password $BOT_PAT --store-password-in-clear-text --name github "https://gitlab.cdrentertainment.com/api/v4/projects/14/packages/nuget/index.json"
- dotnet restore
- dotnet build --no-restore --configuration Release
- CURRENTVERSION="$(dotnet ./bin/Release/net8.0/chat-service.dll -version | cut -d':' -f2)"
- echo "CURRENTVERSION=$CURRENTVERSION" >> .env
- git tag $CURRENTVERSION; git push https://${BOT_USER}:${BOT_PAT}@gitlab.cdrentertainment.com/platform-services/$CI_PROJECT_NAME.git --tags
artifacts:
paths:
- bin/Release/net8.0/*
reports:
dotenv: .env
rules:
- if: $CI_COMMIT_TAG
when: never
- if: '$RESTART_SERVICE == "true"'
when: never
- when: always
sonarqube-check:
stage: scan
image: mcr.microsoft.com/dotnet/sdk:8.0
variables:
SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar" # Defines the location of the analysis task cache
GIT_DEPTH: "0" # Tells git to fetch all the branches of the project, required by the analysis task
cache:
key: "${CI_JOB_NAME}"
paths:
- .sonar/cache
script:
- "apt-get update"
- "apt-get install --yes openjdk-17-jre"
- "dotnet tool install --global dotnet-sonarscanner"
- dotnet nuget add source --username $BOT_USER --password $BOT_PAT --store-password-in-clear-text --name gitlab "https://gitlab.cdrentertainment.com/api/v4/projects/14/packages/nuget/index.json"
- dotnet nuget add source --username $BOT_USER --password $BOT_PAT --store-password-in-clear-text --name platform "$CI_SERVER_URL/api/v4/groups/5/-/packages/nuget/index.json"
- dotnet nuget add source --username $BOT_USER --password $BOT_PAT --store-password-in-clear-text --name tower "$CI_SERVER_URL/api/v4/groups/6/-/packages/nuget/index.json"
- dotnet restore
- "export PATH=\"$PATH:$HOME/.dotnet/tools\""
- "dotnet sonarscanner begin /o:\"rstudios\" /k:\"rstudios_${CI_PROJECT_TITLE}\" /d:sonar.token=\"$SONAR_TOKEN\" /d:\"sonar.host.url=$SONAR_HOST_URL\" "
- "dotnet build"
- "dotnet sonarscanner end /d:sonar.token=\"$SONAR_TOKEN\""
allow_failure: true
rules:
- if: $CI_COMMIT_TAG
when: never
- if: '$RESTART_SERVICE == "true"'
when: never
- when: always
build_image:
stage: build
allow_failure: false
image:
name: "$KANIKO_IMAGE"
entrypoint: [""]
script:
- echo "$CURRENTVERSION"
- mkdir -p /kaniko/.docker
- echo "{\"auths\":{\"$CI_REGISTRY\":{\"auth\":\"$(echo -n ${CI_REGISTRY_USER}:${CI_REGISTRY_PASSWORD} | base64)\"}}}" > /kaniko/.docker/config.json
- /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination $CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG:$CI_COMMIT_SHA --destination $CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG:$CURRENTVERSION
rules:
- if: '$BUILD_DISABLED'
when: never
- if: $CI_COMMIT_TAG
when: never
- if: '$RESTART_SERVICE == "true"'
when: never
- when: on_success
needs:
- job: build_app
artifacts: true
restart_service:
stage: jobs
allow_failure: false
image:
name: bitnami/kubectl
script:
- |
if [ $RESTART_SERVICE_ENV == "dev" ]; then
export RUMBLE_NAMESPACE=chat-service-8-dev
export RUMBLE_CONTEXT=platform-services/platform-services-agent:platform-services
elif [ $RESTART_SERVICE_ENV == "stage-a" ]; then
export RUMBLE_NAMESPACE=chat-service-8-stage-a
export RUMBLE_CONTEXT=platform-services/platform-services-agent:platform-services
elif [ $RESTART_SERVICE_ENV == "stage-b" ]; then
export RUMBLE_NAMESPACE=chat-service-8-stage-b
export RUMBLE_CONTEXT=platform-services/platform-services-agent:platform-services
elif [ $RESTART_SERVICE_ENV == "prod-a1" ]; then
export RUMBLE_NAMESPACE=chat-service
export RUMBLE_CONTEXT=platform-services/platform-services-agent:prod-a1-platform-services
elif [ $RESTART_SERVICE_ENV == "prod-a2" ]; then
export RUMBLE_NAMESPACE=chat-service
export RUMBLE_CONTEXT=platform-services/platform-services-agent:prod-a2-platform-services
else
echo "Somehow an invalid environment was selected"
exit 666
fi
echo "Using $RUMBLE_CONTEXT to delete all pods from $RUMBLE_NAMESPACE"
- |
if [ ! -z "$RUMBLE_NAMESPACE" ]; then
kubectl config use-context $RUMBLE_CONTEXT
kubectl get pods -o yaml -n $RUMBLE_NAMESPACE | kubectl delete -f -
fi
rules:
- if: '$RESTART_SERVICE == "true"'
when: always
include:
- '/.gitlab/deploy-k8s.yaml'