Skip to content

Commit

Permalink
Merge pull request #416 from yuvipanda/upgrade-otter
Browse files Browse the repository at this point in the history
Fix image build script + upgrade otter
  • Loading branch information
GeorgianaElena authored May 18, 2021
2 parents d375bcc + 8743512 commit 47969bf
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
3 changes: 2 additions & 1 deletion deployer/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,12 @@ def image_exists(image_name):

return result.returncode == 0


def build_image(image_repo):
"""
Build & push image in images/user if needed
"""
tag = last_modified_commit(os.path.join(HERE, "images/user"))
tag = last_modified_commit(os.path.join(HERE, "../images/user"))
image_name = f"{image_repo}:{tag}"

if image_exists(image_name):
Expand Down
35 changes: 35 additions & 0 deletions deployer/hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def __init__(self, spec):
]

def build_image(self):
self.ensure_docker_credhelpers()
build_image(self.spec['image_repo'])

@contextmanager
Expand All @@ -42,6 +43,40 @@ def auth(self):
else:
raise ValueError(f'Provider {self.spec["provider"]} not supported')

def ensure_docker_credhelpers(self):
"""
Setup credHelper for current hub's image registry.
Most image registries (like ECR, GCP Artifact registry, etc) use
a docker credHelper (https://docs.docker.com/engine/reference/commandline/login/#credential-helpers)
to authenticate, rather than a username & password. This requires an
entry per registry in ~/.docker/config.json.
This method ensures the appropriate credential helper is present
"""
image_name = self.spec['image_repo']
registry = image_name.split('/')[0]

helper = None
# pkg.dev is used by Google Cloud Artifact registry
if registry.endswith('pkg.dev'):
helper = 'gcloud'

if helper is not None:
dockercfg_path = os.path.expanduser('~/.docker/config.json')
try:
with open(dockercfg_path) as f:
config = json.load(f)
except FileNotFoundError:
config = {}

helpers = config.get('credHelpers', {})
if helpers.get(registry) != helper:
helpers[registry] = helper
config['credHelpers'] = helpers
with open(dockercfg_path, 'w') as f:
json.dump(config, f, indent=4)


def auth_kubeconfig(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion hub-templates/basehub/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ jupyterhub:
hub.jupyter.org/node-purpose: user
image:
name: set_automatically_by_automation
tag: 1b83c4f
tag: 524cf58
storage:
type: static
static:
Expand Down
2 changes: 1 addition & 1 deletion images/user/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ dependencies:
- jupyter-rsession-proxy==1.2
- jupyter-tree-download==1.0.1
- ipywidgets==7.5.1
- otter-grader==1.1.3
- otter-grader==2.1.7

- datascience
- geojson
Expand Down

0 comments on commit 47969bf

Please sign in to comment.