def test_bad_configuration(): container_image = "{{.image.xyz.fqn}}:{{.image.default.version}}" image_config = ImageConfig.auto(config_file=os.path.join( os.path.dirname(os.path.realpath(__file__)), "configs/images.config")) # No default image in the images.config file so nothing to pull version from with pytest.raises(AssertionError): get_registerable_container_image(container_image, image_config)
def get_container(self, settings: SerializationSettings) -> Container: env = { **settings.env, **self.environment } if self.environment else settings.env return _get_container_definition( image=get_registerable_container_image(None, settings.image_config), command=[], args=self.get_command(settings=settings), data_loading_config=None, environment=env, )
def test_get_registerable_container_image_no_images(): cfg = ImageConfig() with pytest.raises(ValueError): get_registerable_container_image("", cfg)
def test_container_image_conversion(): default_img = Image(name="default", fqn="xyz.com/abc", tag="tag1") other_img = Image(name="other", fqn="xyz.com/other", tag="tag-other") cfg = ImageConfig(default_image=default_img, images=[default_img, other_img]) assert get_registerable_container_image(None, cfg) == "xyz.com/abc:tag1" assert get_registerable_container_image("", cfg) == "xyz.com/abc:tag1" assert get_registerable_container_image("abc", cfg) == "abc" assert get_registerable_container_image("abc:latest", cfg) == "abc:latest" assert get_registerable_container_image("abc:{{.image.default.version}}", cfg) == "abc:tag1" assert ( get_registerable_container_image("{{.image.default.fqn}}:{{.image.default.version}}", cfg) == "xyz.com/abc:tag1" ) assert ( get_registerable_container_image("{{.image.other.fqn}}:{{.image.other.version}}", cfg) == "xyz.com/other:tag-other" ) assert ( get_registerable_container_image("{{.image.other.fqn}}:{{.image.default.version}}", cfg) == "xyz.com/other:tag1" ) assert get_registerable_container_image("{{.image.other.fqn}}", cfg) == "xyz.com/other" # Works with images instead of just image assert get_registerable_container_image("{{.images.other.fqn}}", cfg) == "xyz.com/other" with pytest.raises(AssertionError): get_registerable_container_image("{{.image.blah.fqn}}:{{.image.other.version}}", cfg) with pytest.raises(AssertionError): get_registerable_container_image("{{.image.fqn}}:{{.image.other.version}}", cfg) with pytest.raises(AssertionError): get_registerable_container_image("{{.image.blah}}", cfg) assert get_registerable_container_image("{{.image.default}}", cfg) == "xyz.com/abc:tag1"
def test_image_name_interpolation(default_image_config): img_to_interpolate = "{{.image.default.fqn}}:{{.image.default.version}}-special" img = get_registerable_container_image(img=img_to_interpolate, cfg=default_image_config) assert img == "docker.io/xyz:some-git-hash-special"