Skip to content

Commit 21b2ed1

Browse files
committed
[kots] Add new config to upload dockerConfigJson file
Signed-off-by: Tarun Pothulapati <[email protected]>
1 parent b89a417 commit 21b2ed1

File tree

2 files changed

+44
-14
lines changed

2 files changed

+44
-14
lines changed

install/kots/manifests/gitpod-installer-job.yaml

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,16 @@ spec:
7979
fi
8080
8181
echo "Gitpod: Generate the base Installer config"
82+
echo "Gitpod: Create a Helm template directory"
83+
rm -Rf "${GITPOD_OBJECTS}"
84+
mkdir -p "${GITPOD_OBJECTS}/templates"
85+
cat <<EOF >> "${GITPOD_OBJECTS}/Chart.yaml"
86+
apiVersion: v2
87+
name: gitpod-kots
88+
description: Always ready-to-code
89+
version: "1.0.0"
90+
appVersion: "$(/app/installer version | yq e '.version' -)"
91+
EOF
8292
/app/installer init > "${CONFIG_FILE}"
8393
8494
echo "Gitpod: auto-detecting ShiftFS support on host machine"
@@ -174,8 +184,7 @@ spec:
174184
kubectl create secret docker-registry container-registry \
175185
--namespace "{{repl Namespace }}" \
176186
--from-file=.dockerconfigjson=/tmp/container-registry-secret \
177-
-o yaml --dry-run=client | \
178-
kubectl replace --namespace "{{repl Namespace }}" --force -f -
187+
-o yaml --dry-run=client > "${GITPOD_OBJECTS}/templates/gitpod.yaml"
179188
180189
yq e -i ".containerRegistry.inCluster = false" "${CONFIG_FILE}"
181190
yq e -i ".containerRegistry.external.url = \"{{repl ConfigOption "reg_url" }}\"" "${CONFIG_FILE}"
@@ -298,19 +307,8 @@ spec:
298307
config=$(cat "${CONFIG_FILE}")
299308
echo "Gitpod: ${CONFIG_FILE}=${config}"
300309
301-
echo "Gitpod: Create a Helm template directory"
302-
rm -Rf "${GITPOD_OBJECTS}"
303-
mkdir -p "${GITPOD_OBJECTS}/templates"
304-
cat <<EOF >> "${GITPOD_OBJECTS}/Chart.yaml"
305-
apiVersion: v2
306-
name: gitpod-kots
307-
description: Always ready-to-code
308-
version: "1.0.0"
309-
appVersion: "$(/app/installer version | yq e '.version' -)"
310-
EOF
311-
312310
echo "Gitpod: render Kubernetes manifests"
313-
/app/installer render -c "${CONFIG_FILE}" --namespace {{repl Namespace }} --use-experimental-config > "${GITPOD_OBJECTS}/templates/gitpod.yaml"
311+
/app/installer render -c "${CONFIG_FILE}" --namespace {{repl Namespace }} --use-experimental-config >> "${GITPOD_OBJECTS}/templates/gitpod.yaml"
314312
315313
if [ '{{repl ConfigOptionEquals "reg_incluster" "1" }}' = "true" ];
316314
then
@@ -329,6 +327,33 @@ spec:
329327
"${GITPOD_OBJECTS}/templates/gitpod.yaml"
330328
fi
331329
330+
# figure out the secret to use
331+
if [ '{{repl ConfigOptionEquals "reg_incluster" "0" }}' = "true" ];
332+
then
333+
export REGISTRY_SECRET_NAME="container-registry"
334+
else
335+
export REGISTRY_SECRET_NAME="builtin-registry-auth"
336+
fi
337+
338+
if [ '{{repl ConfigOptionNotEquals "reg_docker_config" "" }}' = "true" ];
339+
then
340+
echo "Gitpod: Add given extra docker config json file to ${REGISTRY_SECRET_NAME}"
341+
342+
yq eval-all '(select(.kind == "Secret" and .metadata.name == env(REGISTRY_SECRET_NAME)) | .data.".dockerconfigjson")' \
343+
"${GITPOD_OBJECTS}/templates/gitpod.yaml" \
344+
| base64 -d \
345+
> /tmp/currentconfig.json
346+
347+
DOCKER_CONFIG='{{repl ConfigOptionData "reg_docker_config" | Base64Encode }}'
348+
echo "${DOCKER_CONFIG}" | base64 -d > /tmp/userconfig.json
349+
350+
export REGISTRY_SECRET=$(jq -s '.[0] * .[1]' /tmp/userconfig.json /tmp/currentconfig.json | base64 -w 0)
351+
352+
echo "Gitpod: update the in-cluster registry secret"
353+
yq eval-all --inplace '(select(.kind == "Secret" and .metadata.name == env(REGISTRY_SECRET_NAME)) | .data.".dockerconfigjson") |= env(REGISTRY_SECRET)' \
354+
"${GITPOD_OBJECTS}/templates/gitpod.yaml"
355+
fi
356+
332357
echo "Gitpod: Escape any Golang template values"
333358
sed -i -r 's/(.*\{\{.*)/{{`\1`}}/' "${GITPOD_OBJECTS}/templates/gitpod.yaml"
334359

install/kots/manifests/kots-config.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ spec:
4444
- name: s3
4545
title: S3
4646

47+
- name: reg_docker_config
48+
title: Registry credentials
49+
type: file
50+
help_text: docker [config json file](https://docs.docker.com/engine/reference/commandline/cli/#sample-configuration-file) used to access private registries, containing images specifically for the workspace image builds.
51+
4752
# S3 help_text
4853
- name: reg_incluster_storage_s3_region
4954
title: Storage region

0 commit comments

Comments
 (0)