Esempio n. 1
0
 def test_docker_build_context(self, generate_create):
     build_context = BuildContextConfig(image="foo")
     self.runner.invoke(
         docker,
         ["generate", "--build-context={}".format(build_context.to_dict(dump=True))],
     )
     assert generate_create.call_count == 1
Esempio n. 2
0
    def test_build_config_with_default_values(self):
        config_dict = {"image": "some_image_name"}
        config = BuildContextConfig.from_dict(config_dict)
        assert config.image_tag == "latest"
        assert config.name == POLYAXON_DOCKERFILE_NAME
        assert config.shell == POLYAXON_DOCKER_SHELL
        assert config.workdir == POLYAXON_DOCKER_WORKDIR

        config_dict = {}
        with self.assertRaises(ValidationError):
            BuildContextConfig.from_dict(config_dict)
Esempio n. 3
0
 def test_build_repo_with_install_step_copy_path_config(self):
     config_dict = {
         "image": "tensorflow:1.3.0",
         "path": ["./module"],
         "copy": ["/foo/bar"],
         "run": ["pip install tensor2tensor"],
         "env": [["LC_ALL", "en_US.UTF-8"]],
         "name": "dockerfile",
         "workdir": "",
         "shell": "sh",
     }
     config = BuildContextConfig.from_dict(config_dict)
     assert config.to_dict() == config_dict
     assert config.image_tag == "1.3.0"
Esempio n. 4
0
 def test_build_repo_with_security_context(self):
     config_dict = {
         "image": "tensorflow:1.3.0",
         "run": ["pip install tensor2tensor"],
         "env": [["LC_ALL", "en_US.UTF-8"]],
         "uid": 1000,
         "gid": 3000,
         "name": "dockerfile",
         "workdir": "",
         "shell": "sh",
     }
     config = BuildContextConfig.from_dict(config_dict)
     assert config.to_dict() == config_dict
     assert config.image_tag == "1.3.0"
     assert config.uid == 1000
     assert config.gid == 3000
Esempio n. 5
0
def generate(polyaxonfile, build_context, destination, params):
    """Generate a dockerfile given the polyaxonfile."""
    if all([polyaxonfile, build_context]):
        Printer.print_error(
            "Only a polyaxonfile or a build context option is required.")
        sys.exit(1)

    if build_context:
        try:
            build_context = BuildContextConfig.from_dict(
                rhea.read(build_context))
        except (RheaError, ValidationError) as e:
            Printer.print_error("received a non valid build context.")
            Printer.print_error("Error message: {}.".format(e))
            sys.exit(1)
    else:
        specification = check_polyaxonfile(polyaxonfile,
                                           params=params,
                                           log=False)

        try:
            run_spec = get_specification(specification.generate_run_data())
            run_spec.apply_params(params=specification.config.params)
            run_spec.apply_context()
        except PolyaxonSchemaError:
            Printer.print_error(
                "Could not run this polyaxonfile locally, "
                "a context is required to resolve it dependencies.")
            sys.exit(1)

        build_context = run_spec.build_context

    generator = DockerFileGenerator(build_context=build_context,
                                    destination=destination or ".")
    generator.create()
    Printer.print_success("Dockerfile was generated: `{}`".format(
        generator.dockerfile_path))
Esempio n. 6
0
    def test_build_config_image_use_cases(self):
        # Latest
        config_dict = {"image": "some_image_name"}
        config = BuildContextConfig.from_dict(config_dict)
        assert config.image_tag == "latest"

        # Latest from with docker registry url
        config_dict = {
            "image": "registry.foobar.com/my/docker/some_image_name"
        }
        config = BuildContextConfig.from_dict(config_dict)
        assert config.image_tag == "latest"

        # Latest from with docker registry url with port
        config_dict = {"image": "registry.foobar.com:4567/some_image_name"}
        config = BuildContextConfig.from_dict(config_dict)
        assert config.image_tag == "latest"

        # Some tag
        config_dict = {"image": "some_image_name:4567"}
        config = BuildContextConfig.from_dict(config_dict)
        assert config.image_tag == "4567"

        # Some tag
        config_dict = {"image": "some_image_name:foo"}
        config = BuildContextConfig.from_dict(config_dict)
        assert config.image_tag == "foo"

        # Some tag from with docker registry url
        config_dict = {
            "image": "registry.foobar.com/my/docker/some_image_name:foo"
        }
        config = BuildContextConfig.from_dict(config_dict)
        assert config.image_tag == "foo"

        # Some tag from with docker registry url with port
        config_dict = {"image": "registry.foobar.com:4567/some_image_name:foo"}
        config = BuildContextConfig.from_dict(config_dict)
        assert config.image_tag == "foo"
Esempio n. 7
0
 def test_build_config(self):
     config_dict = {"image": "some_image_name"}
     config = BuildContextConfig.from_dict(config_dict)
     assert config.image_tag == "latest"
Esempio n. 8
0
 def test_does_not_accept_dockerfiles(self):
     config_dict = {"dockerfile": "foo/bar"}
     with self.assertRaises(ValidationError):
         BuildContextConfig.from_dict(config_dict)
Esempio n. 9
0
    def test_valid_image(self):
        config_dict = {"image": None}
        with self.assertRaises(ValidationError):
            BuildContextConfig.from_dict(config_dict)

        config_dict = {"image": ""}
        with self.assertRaises(ValidationError):
            BuildContextConfig.from_dict(config_dict)

        config_dict = {"image": "some_image_name:sdf:sdf:foo"}
        with self.assertRaises(ValidationError):
            BuildContextConfig.from_dict(config_dict)

        config_dict = {
            "image": "registry.foobar.com/my/docker/some_image_name:foo:foo"
        }
        with self.assertRaises(ValidationError):
            BuildContextConfig.from_dict(config_dict)

        config_dict = {"image": "some_image_name / foo"}
        with self.assertRaises(ValidationError):
            BuildContextConfig.from_dict(config_dict)

        config_dict = {"image": "some_image_name /foo:sdf"}
        with self.assertRaises(ValidationError):
            BuildContextConfig.from_dict(config_dict)

        config_dict = {"image": "some_image_name /foo :sdf"}
        with self.assertRaises(ValidationError):
            BuildContextConfig.from_dict(config_dict)

        config_dict = {
            "image":
            "registry.foobar.com:foo:foo/my/docker/some_image_name:foo"
        }
        with self.assertRaises(ValidationError):
            BuildContextConfig.from_dict(config_dict)

        config_dict = {
            "image": "registry.foobar.com:foo:foo/my/docker/some_image_name"
        }
        with self.assertRaises(ValidationError):
            BuildContextConfig.from_dict(config_dict)

        config_dict = {
            "image": "registry.foobar.com:/my/docker/some_image_name:foo"
        }
        with self.assertRaises(ValidationError):
            BuildContextConfig.from_dict(config_dict)