Пример #1
0
    def test_tag_with_invalid_version(self, mocker):
        mocker.patch.object(
            config,
            "get_app_config",
            return_value={"workflow": ["master", "staging", "production"]},
        )
        mocker.patch.object(io, "execute", side_effect=["", "", "1ab2c3d", ""])

        with pytest.raises(RuntimeError):
            git.tag("/path_to/a_git_repository", "my-app", "1.0")
Пример #2
0
    def test_tag(self, get_last_commit_hash_mock, io_mock):
        get_last_commit_hash_mock.return_value = "1ab2c3d"

        tag = git.tag("/path_to/a_git_repository", "1.0.0")

        io_mock.execute.assert_called_once_with(
            "git tag -a 1.0.0-sha-1ab2c3d 1ab2c3d -m 'NESTOR_AUTO_TAG'", "/path_to/a_git_repository"
        )
        self.assertEqual(tag, "1.0.0-sha-1ab2c3d")
Пример #3
0
    def test_tag(self, mocker):
        mocker.patch.object(
            config,
            "get_app_config",
            return_value={"workflow": ["master", "staging", "production"]},
        )
        mocker.patch.object(io, "execute", side_effect=["", "", "1ab2c3d", ""])

        tag = git.tag("/path_to/a_git_repository", "my-app", "1.0.0")

        config.get_app_config.assert_called_once_with("my-app")

        assert io.execute.call_count == 4
        assert io.execute.mock_calls[3] == call(
            "git tag -a 1.0.0-sha-1ab2c3d 1ab2c3d",
            "/path_to/a_git_repository")

        assert tag == "1.0.0-sha-1ab2c3d"
Пример #4
0
def _differed_build(app_name: str):
    config_dir = None
    app_dir = None

    try:
        # Retrieve app's configuration
        config_dir = config.create_temporary_config_copy()
        config.change_environment(Configuration.get_config_default_branch(), config_dir)
        app_config = config.get_app_config(app_name, config_dir)
        Logger.debug(
            {"app": app_name, "config_directory": config_dir},
            "[/api/builds/:app] Application's configuration retrieved",
        )

        # Retrieve app's repository
        app_dir = git.create_working_repository(app_name, app_config["git"]["origin"])
        git.branch(app_dir, app_config["workflow"][0])
        Logger.debug(
            {"app": app_name, "working_directory": app_dir},
            "[/api/builds/:app] Application's repository retrieved",
        )

        try:
            # Create a new tag
            version = app.get_version(app_dir)
            git_tag = git.tag(app_dir, version)
            Logger.debug(
                {"app": app_name, "tag": git_tag}, "[/api/builds/:app] New tag created",
            )
        except Exception as err:
            # The tag may already exist
            Logger.warn(
                {"app": app_name, "err": err}, "[/api/builds/:app] Error while tagging the app"
            )

        # Build and publish the new docker image
        image_tag = docker.build(app_name, app_dir, app_config)
        Logger.debug(
            {"app": app_name, "image": image_tag}, "[/api/builds/:app] Docker image created"
        )
        docker.push(app_name, image_tag, app_config)
        Logger.debug(
            {"app": app_name, "image": image_tag},
            "[/api/builds/:app] Docker image published on registry",
        )

        # Send the new tag to git
        git.push(app_dir)
        Logger.debug({"app": app_name}, "[/api/builds/:app] Tag pushed to Git")

    except Exception as err:
        Logger.error(
            {"app": app_name, "err": err},
            "[/api/builds/:app] Error while tagging and building the app",
        )

    # Clean up temporary directories
    try:
        if config_dir is not None:
            io.remove(config_dir)
        if app_dir is not None:
            io.remove(app_dir)
    except Exception as err:
        Logger.error({"app": app_name, "err": err}, "[/api/builds/:app] Error during cleanup")
Пример #5
0
    def test_tag_with_invalid_version(self, get_last_commit_hash_mock, _io_mock):
        get_last_commit_hash_mock.return_value = "1ab2c3d"

        with self.assertRaises(RuntimeError):
            git.tag("/path_to/a_git_repository", "my-app", "1.0")