Example #1
0
    def test_deploy_release(self, m_tag, m_bash,
                            victim_release: DockerImageBuilder):
        files = [
            DockerFile("Dockerfile", None, None, None, True),
            DockerFile("File2", "-foo", None, "mycustom/repo", False)
        ]

        victim_release.deploy(files)
        build_call_1 = [
            "docker", "build", "--build-arg",
            "PIP_EXTRA_INDEX_URL=url/to/artifact/store", "-t",
            "pony/myapp:2.1.0", "-f", "./Dockerfile", "."
        ]
        build_call_2 = [
            "docker", "build", "--build-arg",
            "PIP_EXTRA_INDEX_URL=url/to/artifact/store", "-t",
            "mycustom/repo-foo:2.1.0", "-f", "./File2", "."
        ]

        push_call_1 = ["docker", "push", "pony/myapp:2.1.0"]
        tag_call_latest = [
            "docker", "tag", "pony/myapp:2.1.0", "pony/myapp:latest"
        ]
        push_call_1_latest = ["docker", "push", "pony/myapp:latest"]
        push_call_2 = ["docker", "push", "mycustom/repo-foo:2.1.0"]
        calls = list(
            map(mock.call, [
                build_call_1, push_call_1, tag_call_latest, push_call_1_latest,
                build_call_2, push_call_2
            ]))
        m_bash.assert_has_calls(calls)
    def test_deploy_non_release(self, m_tag, m_bash, victim: DockerImageBuilder):
        files = [DockerFile("Dockerfile", None, 'name', None, True), DockerFile("File2", "-foo", None, "mycustom/repo", False)]
        victim.deploy(files)
        build_call_1 = ["docker", "build", "--build-arg", "PIP_EXTRA_INDEX_URL=url/to/artifact/store", "-t", "pony/name/myapp:SNAPSHOT", "-f", "./Dockerfile", "."]
        build_call_2 = ["docker", "build", "--build-arg", "PIP_EXTRA_INDEX_URL=url/to/artifact/store", "-t", "mycustom/repo-foo:SNAPSHOT", "-f", "./File2", "."]

        push_call_1 = ["docker", "push", "pony/name/myapp:SNAPSHOT"]
        push_call_2 = ["docker", "push", "mycustom/repo-foo:SNAPSHOT"]
        calls = list(map(mock.call, [build_call_1, push_call_1, build_call_2, push_call_2]))
        m_bash.assert_has_calls(calls)
    def test_validate_full_schema(self, _):
        conf = {**takeoff_config(),
                **BASE_CONF, **{
                "dockerfiles": [{
                    "file": "Dockerfile_custom",
                    "postfix": "Dave",
                    "custom_image_name": "Mustaine"
                }]}}

        DockerImageBuilder(ApplicationVersion("dev", "v", "branch"), conf)
Example #4
0
    def test_validate_minimal_schema(self, _):
        conf = {**takeoff_config(), **BASE_CONF}

        res = DockerImageBuilder(ApplicationVersion("dev", "v", "branch"),
                                 conf)
        assert res.config['dockerfiles'] == [{
            "file": "Dockerfile",
            "postfix": None,
            "prefix": None,
            "custom_image_name": None,
            'tag_release_as_latest': True
        }]
Example #5
0
def test_construct_docker_build_config(victim: DockerImageBuilder):
    res = victim._construct_docker_build_config()
    assert res == [DockerFile("Dockerfile", None, None, None, True)]
Example #6
0
def victim_release() -> DockerImageBuilder:
    with mock.patch("takeoff.build_docker_image.DockerRegistry.credentials", return_value=CREDS), \
         mock.patch("takeoff.step.ApplicationName.get", return_value="myapp"):
        conf = {**takeoff_config(), **BASE_CONF}
        return DockerImageBuilder(ApplicationVersion('PRD', '2.1.0', 'master'),
                                  conf)
Example #7
0
 def test_build_image_failure(self, m_bash):
     with pytest.raises(ChildProcessError):
         DockerImageBuilder.build_image("Thefile", "stag")
     assert_docker_build(m_bash)
Example #8
0
 def test_build_image_success(self, m_bash):
     DockerImageBuilder.build_image("Thefile", "stag")
     assert_docker_build(m_bash)
Example #9
0
 def test_tag_image_failure(self, m_bash):
     with pytest.raises(ChildProcessError):
         DockerImageBuilder.tag_image("old_tag", "new_tag")
     assert_docker_tag(m_bash)
Example #10
0
 def test_tag_image_success(self, m_bash):
     DockerImageBuilder.tag_image("old_tag", "new_tag")
     assert_docker_tag(m_bash)