Skip to content

Commit 0b4462c

Browse files
authored
Merge pull request #1255 from g-braeunlich/master
build_docker_config added, enables augmentation of the build pod's docker config
2 parents 497a7a1 + 3b2f84a commit 0b4462c

File tree

5 files changed

+35
-16
lines changed

5 files changed

+35
-16
lines changed

binderhub/app.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ def _valid_badge_base_url(self, proposal):
297297
)
298298

299299
push_secret = Unicode(
300-
'binder-push-secret',
300+
'binder-build-docker-config',
301301
allow_none=True,
302302
help="""
303303
A kubernetes secret object that provides credentials for pushing built images.
@@ -375,6 +375,22 @@ def docker_build_host_validate(self, proposal):
375375
raise TraitError("Only unix domain sockets on same node are supported for build_docker_host")
376376
return proposal.value
377377

378+
build_docker_config = Dict(
379+
None,
380+
allow_none=True,
381+
help="""
382+
A dict which will be merged into the .docker/config.json of the build container (repo2docker)
383+
Here, you could for example pass proxy settings as described here:
384+
https://docs.docker.com/network/proxy/#configure-the-docker-client
385+
386+
Note: if you provide your own push_secret, this values wont
387+
have an effect, as the push_secrets will overwrite
388+
.docker/config.json
389+
In this case, make sure that you include your config in your push_secret
390+
""",
391+
config=True
392+
)
393+
378394
hub_api_token = Unicode(
379395
help="""API token for talking to the JupyterHub API""",
380396
config=True,
@@ -693,6 +709,7 @@ def initialize(self, *args, **kwargs):
693709
"build_memory_limit": self.build_memory_limit,
694710
"build_memory_request": self.build_memory_request,
695711
"build_docker_host": self.build_docker_host,
712+
"build_docker_config": self.build_docker_config,
696713
"base_url": self.base_url,
697714
"badge_base_url": self.badge_base_url,
698715
"static_path": os.path.join(HERE, "static"),

binderhub/build.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,9 @@ def submit(self):
248248
)]
249249

250250
if self.push_secret:
251-
volume_mounts.append(client.V1VolumeMount(mount_path="/root/.docker", name='docker-push-secret'))
251+
volume_mounts.append(client.V1VolumeMount(mount_path="/root/.docker", name='docker-config'))
252252
volumes.append(client.V1Volume(
253-
name='docker-push-secret',
253+
name='docker-config',
254254
secret=client.V1SecretVolumeSource(secret_name=self.push_secret)
255255
))
256256

binderhub/builder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ async def get(self, provider_prefix, _unescaped_spec):
351351
# Prepare to build
352352
q = Queue()
353353

354-
if self.settings['use_registry']:
354+
if self.settings['use_registry'] or self.settings['build_docker_config']:
355355
push_secret = self.settings['push_secret']
356356
else:
357357
push_secret = None

helm-chart/binderhub/templates/_helpers.tpl

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ We truncate at 63 chars because some Kubernetes name fields are limited to this
1616
{{- end -}}
1717

1818
{{/*
19-
Render docker config.json for the registry-publishing secret.
19+
Render docker config.json for the registry-publishing secret and other docker configuration.
2020
*/}}
21-
{{- define "registryDockerConfig" -}}
21+
{{- define "buildDockerConfig" -}}
2222

2323
{{- /* default auth url */ -}}
2424
{{- $url := (default "https://index.docker.io/v1" .Values.registry.url) }}
@@ -36,11 +36,13 @@ Render docker config.json for the registry-publishing secret.
3636
{{- end }}
3737
{{- $username := .Values.registry.username -}}
3838

39-
{
40-
"auths": {
41-
"{{ $url }}": {
42-
"auth": "{{ printf "%s:%s" $username .Values.registry.password | b64enc }}"
43-
}
44-
}
45-
}
39+
{{- /* initialize a dict to represent a docker config with registry credentials */}}
40+
{{- $dockerConfig := dict "auths" (dict $url (dict "auth" (printf "%s:%s" $username .Values.registry.password | b64enc))) }}
41+
42+
{{- /* augment our initialized docker config with buildDockerConfig */}}
43+
{{- if .Values.config.BinderHub.buildDockerConfig }}
44+
{{- $dockerConfig := merge $dockerConfig .Values.config.BinderHub.buildDockerConfig }}
45+
{{- end }}
46+
47+
{{- $dockerConfig | toPrettyJson }}
4648
{{- end }}

helm-chart/binderhub/templates/secret.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ data:
1616
{{- end }}
1717
values.yaml: {{ $values | toYaml | b64enc | quote }}
1818
---
19-
{{- if .Values.config.BinderHub.use_registry }}
19+
{{- if or .Values.config.BinderHub.use_registry .Values.config.BinderHub.buildDockerConfig }}
2020
kind: Secret
2121
apiVersion: v1
2222
metadata:
23-
name: binder-push-secret
23+
name: binder-build-docker-config
2424
type: Opaque
2525
data:
26-
config.json: {{ include "registryDockerConfig" . | b64enc | quote }}
26+
config.json: {{ include "buildDockerConfig" . | b64enc | quote }}
2727
{{- end }}

0 commit comments

Comments
 (0)