def test_tag_generation(git_repo): """ Tag should be last commit of modified image dir """ commit_file(git_repo, 'image/Dockerfile', 'FROM busybox') commit_file(git_repo, 'unrelated/file', 'unrelated') with cwd(git_repo): image = config.LocalImage('test-image', 'image') assert image.tag == gitutils.last_modified_commit('image') # Make sure tag isn't influenced by changes outside of iamge dir assert image.tag != gitutils.last_modified_commit('unrelated') # Change the Dockerfile and see that the tag changes commit_file(git_repo, 'image/Dockerfile', 'FROM busybox:latest') new_image = config.LocalImage('test-image', 'image') assert new_image.tag == gitutils.last_modified_commit('image') assert new_image.tag != image.tag
def pull_images_for_cache(client, path, image_name, commit_range): # Pull last built image if we can cache_from = [] for i in range(1, 5): image = image_name # FIXME: Make this look for last modified since before beginning of commit_range tag = gitutils.last_modified_commit(path, n=i) try: print(f'Trying to pull {image}:{tag}') pull_image(client, image, tag) cache_from.append(f'{image}:{tag}') break except Exception as e: # Um, ignore if things fail! print(str(e)) return cache_from
def make_imagespec(path, image_name): tag = gitutils.last_modified_commit(path) if not tag: tag = 'latest' return f'{image_name}:{tag}'
def deploy( deployment, chart, environment, namespace=None, helm_config_overrides=None, version=None, ): """ Deploy a JupyterHub. Expects the following files to exist in current directory {chart}/ (Helm deployment chart) deployments/ - {deployment} - image/ - secrets/ - {environment}.yaml - config/ - common.yaml - {environment}.yaml A docker image from deployments/{deployment}/image is expected to be already built and available with imagebuilder. `jupyterhub.singleuser.image.tag` will be automatically set to this image tag. """ if helm_config_overrides is None: helm_config_overrides = [] config = get_config(deployment) name = f'{deployment}-{environment}' if namespace is None: namespace = name helm_config_files = [ f for f in [ os.path.join('deployments', deployment, 'config', 'common.yaml'), os.path.join('deployments', deployment, 'config', f'{environment}.yaml'), os.path.join('deployments', deployment, 'secrets', f'{environment}.yaml'), ] if os.path.exists(f) ] image_path = os.path.join('deployments', deployment, 'image') if os.path.exists(image_path): image_tag = gitutils.last_modified_commit( os.path.join('deployments', deployment, 'image')) # We can support other charts that wrap z2jh by allowing various # config paths where we set image tags and names. # We default to one sublevel, but we can do multiple levels. # With the PANGEO chart, we this could be set to `pangeo.jupyterhub.singleuser.image` image_config_path = config.get('images', {}).get('image_config_path', 'jupyterhub.singleuser.image') helm_config_overrides.append(f'{image_config_path}.tag={image_tag}') if 'images' in config: image_name = config['images'].get('image_name') if image_name: helm_config_overrides.append( f'{image_config_path}.name={image_name}') helm_upgrade(name, namespace, chart, helm_config_files, helm_config_overrides, version)