Skip to content

[kots] Allow users to upload a .docker/config.json file #12174

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 40 additions & 14 deletions install/kots/manifests/gitpod-installer-job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,17 @@ spec:
fi
fi

echo "Gitpod: Create a Helm template directory"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The echo "Gitpod: Generate the base Installer config" line should go above the /app/installer init > "${CONFIG_FILE}" so that the logging is representative of what's going on

rm -Rf "${GITPOD_OBJECTS}"
mkdir -p "${GITPOD_OBJECTS}/templates"
cat <<EOF >> "${GITPOD_OBJECTS}/Chart.yaml"
apiVersion: v2
name: gitpod-kots
description: Always ready-to-code
version: "1.0.0"
appVersion: "$(/app/installer version | yq e '.version' -)"
EOF

echo "Gitpod: Generate the base Installer config"
/app/installer init > "${CONFIG_FILE}"

Expand Down Expand Up @@ -174,8 +185,7 @@ spec:
kubectl create secret docker-registry container-registry \
--namespace "{{repl Namespace }}" \
--from-file=.dockerconfigjson=/tmp/container-registry-secret \
-o yaml --dry-run=client | \
kubectl replace --namespace "{{repl Namespace }}" --force -f -
-o yaml --dry-run=client > "${GITPOD_OBJECTS}/templates/gitpod.yaml"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed this to save the secret in the gitpod.yaml, instead of applying so that we can post process it if the user submits more docker configs through the new option

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems a reasonable approach. This means that we'll have a secret at the start of the YAML file, but that shouldn't be a problem as it's what we're doing anyway


yq e -i ".containerRegistry.inCluster = false" "${CONFIG_FILE}"
yq e -i ".containerRegistry.external.url = \"{{repl ConfigOption "reg_url" }}\"" "${CONFIG_FILE}"
Expand Down Expand Up @@ -298,19 +308,8 @@ spec:
config=$(cat "${CONFIG_FILE}")
echo "Gitpod: ${CONFIG_FILE}=${config}"

echo "Gitpod: Create a Helm template directory"
rm -Rf "${GITPOD_OBJECTS}"
mkdir -p "${GITPOD_OBJECTS}/templates"
cat <<EOF >> "${GITPOD_OBJECTS}/Chart.yaml"
apiVersion: v2
name: gitpod-kots
description: Always ready-to-code
version: "1.0.0"
appVersion: "$(/app/installer version | yq e '.version' -)"
EOF

echo "Gitpod: render Kubernetes manifests"
/app/installer render -c "${CONFIG_FILE}" --namespace {{repl Namespace }} --use-experimental-config > "${GITPOD_OBJECTS}/templates/gitpod.yaml"
/app/installer render -c "${CONFIG_FILE}" --namespace {{repl Namespace }} --use-experimental-config >> "${GITPOD_OBJECTS}/templates/gitpod.yaml"

if [ '{{repl ConfigOptionEquals "reg_incluster" "1" }}' = "true" ];
then
Expand All @@ -329,6 +328,33 @@ spec:
"${GITPOD_OBJECTS}/templates/gitpod.yaml"
fi

# figure out the secret to use
if [ '{{repl ConfigOptionEquals "reg_incluster" "0" }}' = "true" ];
then
export REGISTRY_SECRET_NAME="container-registry"
else
export REGISTRY_SECRET_NAME="builtin-registry-auth"
fi

if [ '{{repl ConfigOptionNotEquals "reg_docker_config" "" }}' = "true" ];
then
echo "Gitpod: Add given extra docker config json file to ${REGISTRY_SECRET_NAME}"

yq eval-all '(select(.kind == "Secret" and .metadata.name == env(REGISTRY_SECRET_NAME)) | .data.".dockerconfigjson")' \
"${GITPOD_OBJECTS}/templates/gitpod.yaml" \
| base64 -d \
> /tmp/currentconfig.json

DOCKER_CONFIG='{{repl ConfigOptionData "reg_docker_config" | Base64Encode }}'
echo "${DOCKER_CONFIG}" | base64 -d > /tmp/userconfig.json

export REGISTRY_SECRET=$(jq -s '.[0] * .[1]' /tmp/userconfig.json /tmp/currentconfig.json | base64 -w 0)

echo "Gitpod: update the in-cluster registry secret"
yq eval-all --inplace '(select(.kind == "Secret" and .metadata.name == env(REGISTRY_SECRET_NAME)) | .data.".dockerconfigjson") |= env(REGISTRY_SECRET)' \
"${GITPOD_OBJECTS}/templates/gitpod.yaml"
fi

echo "Gitpod: Escape any Golang template values"
sed -i -r 's/(.*\{\{.*)/{{`\1`}}/' "${GITPOD_OBJECTS}/templates/gitpod.yaml"

Expand Down
15 changes: 14 additions & 1 deletion install/kots/manifests/kots-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ spec:

- name: container_registry
title: Container registry
description: Gitpod requires a container registry to store container images. This can either be an in-cluster or external container registry.
description: Gitpod [requires a container registry](https://www.gitpod.io/docs/self-hosted/latest/reference-architecture/single-cluster-ref-arch#oci-image-registry) to push and store workspace images. This can either be an in-cluster or external container registry.
items:
- name: reg_incluster
title: Use in-cluster container registry
Expand Down Expand Up @@ -108,6 +108,19 @@ spec:
required: true
help_text: The password for your container registry.

- name: reg_docker_config_enable
title: Configure additional registry credentials for pulling workspace images
type: bool
default: "0"
help_text: This is useful when you have base workspace images in private registries other than the above configured ones.
Copy link
Contributor

@lucasvaltl lucasvaltl Aug 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
help_text: This is useful when you have base workspace images in private registries other than the above configured ones.
help_text: This is useful when you want to use base workspace images in private registries other than the above configured ones or the [default base workspace images stored on Docker Hub](https://github.com/gitpod-io/workspace-images).


- name: reg_docker_config
title: Registry credentials
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
title: Registry credentials
title: Private base image registry credentials

when: '{{repl ConfigOptionEquals "reg_docker_config_enable" "1" }}'
type: file
required: true
help_text: Docker [config JSON file](https://docs.docker.com/engine/reference/commandline/cli/#sample-configuration-file) with auth credentials used to access private registries, for workspace images.
Copy link
Contributor

@lucasvaltl lucasvaltl Aug 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
help_text: Docker [config JSON file](https://docs.docker.com/engine/reference/commandline/cli/#sample-configuration-file) with auth credentials used to access private registries, for workspace images.
help_text: Docker [config JSON file](https://docs.docker.com/engine/reference/commandline/cli/#sample-configuration-file) with auth credentials used to access private registries used for pulling base workspace images.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

credentials used to access private registries used for pulling base workspace images.

Happy to update, but used to <> used for <> sounds a bit confusing?


- name: database
title: Database
description: Gitpod requires an instance of MySQL 5.7 for data storage. This can either be an in-cluster or external database.
Expand Down