2
2
# Copyright (c) 2022 Gitpod GmbH. All rights reserved.
3
3
# Licensed under the MIT License. See License-MIT.txt in the project root for license information.
4
4
5
- # shellcheck disable=SC2050,SC2153
6
-
7
5
set -e
8
6
9
7
echo " Gitpod: Killing any in-progress installations"
@@ -38,247 +36,31 @@ appVersion: "$(/app/installer version | yq e '.version' -)"
38
36
EOF
39
37
40
38
echo " Gitpod: Generate the base Installer config"
41
- /app/installer init > " ${CONFIG_FILE} "
39
+ /app/installer config init
42
40
43
41
echo " Gitpod: auto-detecting ShiftFS support on host machine"
44
- kubectl wait job -n " ${NAMESPACE} " --for=condition=complete -l component=shiftfs-module-loader --timeout=30s || true
45
- ENABLE_SHIFTFS=$( kubectl get jobs.batch -n " ${NAMESPACE} " -l component=shiftfs-module-loader -o jsonpath=' {.items[0].status.succeeded}' )
46
-
47
- if [ " ${ENABLE_SHIFTFS} " = " 1" ]; then
48
- echo " Gitpod: enabling ShiftFS support"
49
-
50
- yq e -i ' .workspace.runtime.fsShiftMethod = "shiftfs"' " ${CONFIG_FILE} "
51
- fi
52
-
53
- echo " Gitpod: auto-detecting containerd location on host machine"
54
- if [ -d " /mnt/node0${CONTAINERD_DIR_K3S} " ]; then
55
- echo " Gitpod: containerd dir detected as k3s"
56
-
57
- yq e -i " .workspace.runtime.containerdRuntimeDir = \" ${CONTAINERD_DIR_K3S} \" " " ${CONFIG_FILE} "
58
- elif [ -d " /mnt/node0${CONTAINERD_DIR_AL} " ]; then
59
- echo " Gitpod: containerd dir detected as ${CONTAINERD_DIR_AL} "
60
-
61
- yq e -i " .workspace.runtime.containerdRuntimeDir = \" ${CONTAINERD_DIR_AL} \" " " ${CONFIG_FILE} "
62
- fi
63
-
64
- if [ -S " /mnt/node0${CONTAINERD_SOCKET_K3S} " ]; then
65
- echo " Gitpod: containerd socket detected as k3s"
66
-
67
- yq e -i " .workspace.runtime.containerdSocket = \" ${CONTAINERD_SOCKET_K3S} \" " " ${CONFIG_FILE} "
68
- elif [ -S " /mnt/node0${CONTAINERD_SOCKET_AL} " ]; then
69
- echo " Gitpod: containerd socket detected as ${CONTAINERD_SOCKET_AL} "
70
-
71
- yq e -i " .workspace.runtime.containerdSocket = \" ${CONTAINERD_SOCKET_AL} \" " " ${CONFIG_FILE} "
72
- fi
73
-
74
- echo " Gitpod: Inject the Replicated variables into the config"
75
- yq e -i " .domain = \" ${DOMAIN} \" " " ${CONFIG_FILE} "
76
- yq e -i ' .license.kind = "secret"' " ${CONFIG_FILE} "
77
- yq e -i ' .license.name = "gitpod-license"' " ${CONFIG_FILE} "
78
-
79
- echo " Gitpod: Inject the HTTP_PROXY settings secret"
80
- yq e -i ' .httpProxy.kind = "secret"' " ${CONFIG_FILE} "
81
- yq e -i ' .httpProxy.name = "http-proxy-settings"' " ${CONFIG_FILE} "
82
-
83
- if [ " ${OPEN_VSX_URL} " != " " ];
84
- then
85
- echo " Gitpod: Setting Open VSX Registry URL"
86
- yq e -i " .openVSX.url = \" ${OPEN_VSX_URL} \" " " ${CONFIG_FILE} "
87
- fi
88
-
89
- if [ " ${DB_INCLUSTER_ENABLED} " = " 0" ] && [ " ${DB_CLOUDSQL_INSTANCE} " != " " ];
90
- then
91
- echo " Gitpod: configuring CloudSQLProxy"
92
-
93
- yq e -i " .database.inCluster = false" " ${CONFIG_FILE} "
94
- yq e -i " .database.cloudSQL.instance = \" ${DB_CLOUDSQL_INSTANCE} \" " " ${CONFIG_FILE} "
95
- yq e -i " .database.cloudSQL.serviceAccount.kind = \" secret\" " " ${CONFIG_FILE} "
96
- yq e -i " .database.cloudSQL.serviceAccount.name = \" cloudsql\" " " ${CONFIG_FILE} "
97
- fi
98
-
99
- if [ " ${DB_INCLUSTER_ENABLED} " = " 0" ] && [ " ${DB_CLOUDSQL_INSTANCE} " = " " ];
100
- then
101
- echo " Gitpod: configuring external database"
102
-
103
- yq e -i " .database.inCluster = false" " ${CONFIG_FILE} "
104
- yq e -i " .database.external.certificate.kind = \" secret\" " " ${CONFIG_FILE} "
105
- yq e -i " .database.external.certificate.name = \" database\" " " ${CONFIG_FILE} "
106
- fi
107
-
108
- if [ " ${HAS_LOCAL_REGISTRY} " = " true" ];
109
- then
110
- echo " Gitpod: configuring mirrored container registry for airgapped installation"
111
-
112
- yq e -i " .repository = \" ${LOCAL_REGISTRY_ADDRESS} \" " " ${CONFIG_FILE} "
113
- yq e -i " .imagePullSecrets[0].kind = \" secret\" " " ${CONFIG_FILE} "
114
- yq e -i " .imagePullSecrets[0].name = \" ${IMAGE_PULL_SECRET_NAME} \" " " ${CONFIG_FILE} "
115
- yq e -i ' .dropImageRepo = true' " ${CONFIG_FILE} "
116
-
117
- # Add the registry to the server allowlist - keep docker.io in case it's just using the mirrored registry functionality without being airgapped
118
- yq e -i " .containerRegistry.privateBaseImageAllowList += \" ${LOCAL_REGISTRY_HOST} \" " " ${CONFIG_FILE} "
119
- yq e -i " .containerRegistry.privateBaseImageAllowList += \" docker.io\" " " ${CONFIG_FILE} "
120
- fi
121
-
122
- if [ " ${REG_DOCKER_CONFIG_ENABLED} " = " 1" ];
123
- then
124
- echo " Gitpod: extracting servers from the custom registry authentication"
125
-
126
- kubectl get secret \
127
- -n " ${NAMESPACE} " \
128
- custom-registry-credentials \
129
- -o jsonpath=" {.data.\.dockerconfigjson}" | base64 -d > /tmp/userconfig.json
130
-
131
- # Add the registries to the server allowlist
132
- yq e -i " .containerRegistry.privateBaseImageAllowList += $( jq ' .auths' /tmp/userconfig.json | jq -rc ' keys' ) " " ${CONFIG_FILE} "
133
- yq e -i " .containerRegistry.privateBaseImageAllowList += \" docker.io\" " " ${CONFIG_FILE} "
134
- fi
135
-
136
- # Output the local registry secret - this is proxy.replicated.com if user hasn't set their own
137
- echo " ${LOCAL_REGISTRY_IMAGE_PULL_SECRET} " | base64 -d > /tmp/kotsregistry.json
138
-
139
- if [ " ${REG_INCLUSTER_ENABLED} " = " 0" ];
140
- then
141
- echo " Gitpod: configuring external container registry"
42
+ /app/installer config cluster shiftfs
142
43
143
- # Get the external-container-registry secret so we can merge the external registry and KOTS registry keys
144
- kubectl get secret external-container-registry \
145
- --namespace " ${NAMESPACE} " \
146
- -o jsonpath=' {.data.\.dockerconfigjson}' | base64 -d > /tmp/gitpodregistry.json
44
+ echo " Gitpod: auto-detecting containerd settings on host machine"
45
+ /app/installer config files containerd
147
46
148
- cat /tmp/kotsregistry.json /tmp/gitpodregistry.json | jq -s ' .[0] * .[1]' - - > /tmp/container-registry-secret
47
+ echo " Gitpod: auto-detecting settings"
48
+ /app/installer config build-from-envvars
149
49
150
- echo " Gitpod: create the container-registry secret"
151
- kubectl create secret docker-registry container-registry \
152
- --namespace " ${NAMESPACE} " \
153
- --from-file=.dockerconfigjson=/tmp/container-registry-secret \
154
- -o yaml --dry-run=client > " ${GITPOD_OBJECTS} /templates/gitpod.yaml"
50
+ echo " Gitpod: Validate config"
51
+ /app/installer validate config
155
52
156
- yq e -i " .containerRegistry.inCluster = false" " ${CONFIG_FILE} "
157
- yq e -i " .containerRegistry.external.url = \" ${REG_URL} \" " " ${CONFIG_FILE} "
158
- yq e -i " .containerRegistry.external.certificate.kind = \" secret\" " " ${CONFIG_FILE} "
159
- yq e -i " .containerRegistry.external.certificate.name = \" container-registry\" " " ${CONFIG_FILE} "
160
- else
161
- if [ " ${REG_INCLUSTER_STORAGE} " = " s3" ];
162
- then
163
- echo " Gitpod: configuring container registry S3 backend"
164
-
165
- yq e -i " .containerRegistry.s3storage.region = \" ${REG_INCLUSTER_STORAGE_S3_REGION} \" " " ${CONFIG_FILE} "
166
- yq e -i " .containerRegistry.s3storage.endpoint = \" ${REG_INCLUSTER_STORAGE_S3_ENDPOINT} \" " " ${CONFIG_FILE} "
167
- yq e -i " .containerRegistry.s3storage.bucket = \" ${REG_INCLUSTER_STORAGE_S3_BUCKETNAME} \" " " ${CONFIG_FILE} "
168
- yq e -i " .containerRegistry.s3storage.certificate.kind = \" secret\" " " ${CONFIG_FILE} "
169
- yq e -i " .containerRegistry.s3storage.certificate.name = \" container-registry-s3-backend\" " " ${CONFIG_FILE} "
170
- fi
171
- fi
172
-
173
- if [ " ${STORE_PROVIDER} " != " incluster" ];
174
- then
175
- echo " Gitpod: configuring the storage"
176
-
177
- yq e -i " .metadata.region = \" ${STORE_REGION} \" " " ${CONFIG_FILE} "
178
- yq e -i " .objectStorage.inCluster = false" " ${CONFIG_FILE} "
179
-
180
- if [ " ${STORE_PROVIDER} " = " azure" ];
181
- then
182
- echo " Gitpod: configuring storage for Azure"
183
-
184
- yq e -i " .objectStorage.azure.credentials.kind = \" secret\" " " ${CONFIG_FILE} "
185
- yq e -i " .objectStorage.azure.credentials.name = \" storage-azure\" " " ${CONFIG_FILE} "
186
- fi
187
-
188
- if [ " ${STORE_PROVIDER} " = " gcp" ];
189
- then
190
- echo " Gitpod: configuring storage for GCP"
191
-
192
- yq e -i " .objectStorage.cloudStorage.project = \" ${STORE_GCP_PROJECT} \" " " ${CONFIG_FILE} "
193
- yq e -i " .objectStorage.cloudStorage.serviceAccount.kind = \" secret\" " " ${CONFIG_FILE} "
194
- yq e -i " .objectStorage.cloudStorage.serviceAccount.name = \" storage-gcp\" " " ${CONFIG_FILE} "
195
- fi
196
-
197
- if [ " ${STORE_PROVIDER} " = " s3" ];
198
- then
199
- echo " Gitpod: configuring storage for S3"
200
-
201
- yq e -i " .objectStorage.s3.endpoint = \" ${STORE_S3_ENDPOINT} \" " " ${CONFIG_FILE} "
202
- yq e -i " .objectStorage.s3.bucket = \" ${STORE_S3_BUCKET} \" " " ${CONFIG_FILE} "
203
- yq e -i " .objectStorage.s3.credentials.kind = \" secret\" " " ${CONFIG_FILE} "
204
- yq e -i " .objectStorage.s3.credentials.name = \" storage-s3\" " " ${CONFIG_FILE} "
205
- fi
206
- fi
207
-
208
- if [ " ${SSH_GATEWAY} " = " 1" ];
209
- then
210
- echo " Gitpod: Generate SSH host key"
211
- ssh-keygen -t rsa -q -N " " -f host.key
212
- kubectl create secret generic ssh-gateway-host-key --from-file=host.key -n " ${NAMESPACE} " || echo " SSH Gateway Host Key secret has not been created. Does it exist already?"
213
- yq e -i ' .sshGatewayHostKey.kind = "secret"' " ${CONFIG_FILE} "
214
- yq e -i ' .sshGatewayHostKey.name = "ssh-gateway-host-key"' " ${CONFIG_FILE} "
215
- fi
216
-
217
- if [ " ${TLS_SELF_SIGNED_ENABLED} " = " 1" ];
218
- then
219
- echo " Gitpod: Generating a self-signed certificate with the internal CA"
220
- yq e -i ' .customCACert.kind = "secret"' " ${CONFIG_FILE} "
221
- yq e -i ' .customCACert.name = "ca-issuer-ca"' " ${CONFIG_FILE} "
222
- elif [ " ${TLS_SELF_SIGNED_ENABLED} " = " 0" ] && [ " ${CERT_MANAGER_ENABLED} " = " 0" ] && [ " ${TLS_CUSTOM_CA_CRT_ENABLED} " = " true" ];
223
- then
224
- echo " Gitpod: Setting CA to be used for certificate"
225
- yq e -i ' .customCACert.kind = "secret"' " ${CONFIG_FILE} "
226
- yq e -i ' .customCACert.name = "ca-certificate"' " ${CONFIG_FILE} "
227
- fi
228
-
229
- if [ " ${USER_MANAGEMENT_BLOCK_ENABLED} " = " 1" ];
230
- then
231
- echo " Gitpod: Adding blockNewUsers to config"
232
- yq e -i ' .blockNewUsers.enabled = true' " ${CONFIG_FILE} "
233
-
234
- for domain in ${USER_MANAGEMENT_BLOCK_PASSLIST}
235
- do
236
- echo " Gitpod: Adding domain \" ${domain} \" to blockNewUsers config"
237
- yq e -i " .blockNewUsers.passlist += \" ${domain} \" " " ${CONFIG_FILE} "
238
- done
239
- fi
240
-
241
- if [ " ${ADVANCED_MODE_ENABLED} " = " 1" ];
242
- then
243
- echo " Gitpod: Applying advanced configuration"
244
-
245
- if [ " ${COMPONENT_PROXY_SERVICE_SERVICETYPE} " != " " ];
246
- then
247
- # Empty string defaults to LoadBalancer. This maintains backwards compatibility with the deprecated experimental value
248
- echo " Gitpod: Applying Proxy service type"
249
- yq e -i " .components.proxy.service.serviceType = \" ${COMPONENT_PROXY_SERVICE_SERVICETYPE} \" " " ${CONFIG_FILE} "
250
- fi
251
-
252
- if [ -s " ${CUSTOMIZATION_PATCH_FILE} " ];
253
- then
254
- CUSTOMIZATION=" $( base64 " ${CUSTOMIZATION_PATCH_FILE} " -w 0) "
255
- echo " Gitpod: Applying customization patch ${CUSTOMIZATION} "
53
+ echo " Gitpod: render Kubernetes manifests"
54
+ /app/installer render --use-experimental-config > " ${GITPOD_OBJECTS} /templates/gitpod.yaml"
256
55
257
- # Apply the customization property - if something else is set, this will be ignored
258
- yq e -i " .customization = $( echo " ${CUSTOMIZATION} " | base64 -d | yq e -o json ' .customization' - | jq -rc) // []" " ${CONFIG_FILE} "
259
- fi
260
- else
261
- echo " Gitpod: No advanced configuration applied"
56
+ if [ " ${INSTALLER_DRY_RUN} " = " true" ]; then
57
+ echo " Gitpod: dry-run set to true, no installation will be performed"
58
+ exit
262
59
fi
263
60
264
- echo " Gitpod: Update platform telemetry value"
265
- yq eval-all --inplace " .experimental.telemetry.data.platform = \" ${DISTRIBUTION} \" " " ${CONFIG_FILE} "
266
-
267
- echo " Gitpod: Patch Gitpod config"
268
- base64 -d " ${CONFIG_PATCH_FILE} " > /tmp/patch.yaml
269
- config_patch=$( cat /tmp/patch.yaml)
270
- echo " Gitpod: ${CONFIG_PATCH_FILE} =${config_patch} "
271
- yq eval-all --inplace ' select(fileIndex == 0) * select(fileIndex == 1)' " ${CONFIG_FILE} " /tmp/patch.yaml
272
-
273
- echo " Gitpod: Generate the Kubernetes objects"
274
- config=$( cat " ${CONFIG_FILE} " )
275
- echo " Gitpod: ${CONFIG_FILE} =${config} "
276
-
277
- echo " Gitpod: render Kubernetes manifests"
278
- /app/installer render -c " ${CONFIG_FILE} " --namespace " ${NAMESPACE} " --use-experimental-config >> " ${GITPOD_OBJECTS} /templates/gitpod.yaml"
279
-
280
- if [ " ${REG_INCLUSTER_ENABLED} " = " 1" ];
281
- then
61
+ # Combine the pull secrets
62
+ echo " ${LOCAL_REGISTRY_IMAGE_PULL_DOCKER_CONFIG_JSON} " > /tmp/kotsregistry.json
63
+ if [ " ${REG_INCLUSTER_ENABLED} " = " 1" ]; then
282
64
echo " Gitpod: Add the local registry secret to the in-cluster registry secret"
283
65
284
66
# Get the in-cluster registry secret
@@ -293,14 +75,28 @@ then
293
75
echo " Gitpod: update the in-cluster registry secret"
294
76
yq eval-all --inplace ' (select(.kind == "Secret" and .metadata.name == "builtin-registry-auth") | .data.".dockerconfigjson") |= env(REGISTRY_SECRET)' \
295
77
" ${GITPOD_OBJECTS} /templates/gitpod.yaml"
78
+ else
79
+ echo " Gitpod: configuring external container registry"
80
+
81
+ # Get the external-container-registry secret so we can merge the external registry and KOTS registry keys
82
+ echo " ${EXTERNAL_DOCKER_CONFIG_JSON} " > /tmp/gitpodregistry.json
83
+
84
+ cat /tmp/kotsregistry.json /tmp/gitpodregistry.json | jq -s ' .[0] * .[1]' - - > /tmp/container-registry-secret
85
+
86
+ echo " Gitpod: append the container-registry secret"
87
+ echo " ---" >> " ${GITPOD_OBJECTS} /templates/gitpod.yaml"
88
+ kubectl create secret docker-registry " ${REG_EXTERNAL_CERTIFICATE_NAME} " \
89
+ --namespace " ${NAMESPACE} " \
90
+ --from-file=.dockerconfigjson=/tmp/container-registry-secret \
91
+ -o yaml --dry-run=client >> " ${GITPOD_OBJECTS} /templates/gitpod.yaml"
296
92
fi
297
93
298
94
if [ " ${REG_DOCKER_CONFIG_ENABLED} " = " 1" ];
299
95
then
300
96
# Work out the registry secret to use
301
97
if [ " ${REG_INCLUSTER_ENABLED} " = " 0" ];
302
98
then
303
- export REGISTRY_SECRET_NAME=" container-registry "
99
+ export REGISTRY_SECRET_NAME=" ${REG_EXTERNAL_CERTIFICATE_NAME} "
304
100
else
305
101
export REGISTRY_SECRET_NAME=" builtin-registry-auth"
306
102
fi
@@ -345,5 +141,3 @@ helm upgrade \
345
141
346
142
echo " Gitpod: Restarting installation status job"
347
143
kubectl delete pod -n " ${NAMESPACE} " -l component=gitpod-installer-status || true
348
-
349
- echo " Gitpod: Installer job finished - goodbye"
0 commit comments