Пример #1
0
def build(app: App):
    with tmp_directory():
        os.chdir(app.name)

        app_dir = app.name

        os.chdir("..")
        working_dir = gen_working_dir(app)

        copytree(app_dir, working_dir, dirs_exist_ok=True, symlinks=False)

        os.chdir(working_dir)

        {
            "oh_queue": run_oh_queue_build,
            "create_react_app": run_create_react_app_build,
            "webpack": run_webpack_build,
            "61a_website": run_61a_website_build,
            "hugo": run_hugo_build,
            "sphinx": run_sphinx_build,
            "jekyll": run_jekyll_build,
            "none": run_noop_build,
        }[app.config["build_type"]]()

        os.chdir("..")
Пример #2
0
 def __init__(self, name: str):
     self.name = name
     self.deployed_pypi_version = None
     with tmp_directory():
         try:
             with open(f"{name}/deploy.yaml") as f:
                 self.config = Config(**yaml.safe_load(f))
                 self.config["build_image"] = self.config.get(
                     "build_image", None)
                 self.config["cpus"] = self.config.get("cpus", 1)
                 self.config["memory_limit"] = self.config.get(
                     "memory_limit", "256M")
                 self.config["first_party_domains"] = self.config.get(
                     "first_party_domains", [f"{name}.cs61a.org"])
                 self.config["concurrency"] = self.config.get(
                     "concurrency", 80)
                 self.config["tasks"] = self.config.get("tasks", [])
                 self.config["dependencies"] = self.config.get(
                     "dependencies", [])
                 self.config["package_name"] = self.config.get(
                     "package_name", name)
                 self.config["static_consumers"] = self.config.get(
                     "static_consumers", [])
                 self.config["repo"] = self.config.get("repo")
                 self.config["service"] = self.config.get("service")
                 self.config["pr_consumers"] = self.config.get(
                     "pr_consumers", [name])
         except FileNotFoundError:
             # app has been deleted in PR
             self.config = None
Пример #3
0
def create_test_env(snapshot):
    with tmp_directory(clean=True) as tmp:
        env = Environment(tmp)
        try:
            yield env
        finally:
            logs = env.get_logs()

    assert logs == snapshot
Пример #4
0
def deploy_commit(app: App, pr_number: int):
    with tmp_directory():
        os.chdir(gen_working_dir(app))
        {
            "flask": run_flask_deploy,
            "flask-pandas": run_flask_pandas_deploy,
            "docker": run_dockerfile_deploy,
            "pypi": run_pypi_deploy,
            "cloud_function": run_cloud_function_deploy,
            "service": run_service_deploy,
            "static": run_static_deploy,
            "hosted": run_hosted_deploy,
            "none": run_noop_deploy,
        }[app.config["deploy_type"]](app, pr_number)
Пример #5
0
def clone_commit(remote: str, sha: str, *, in_place=False):
    path = urlparse(remote).path

    def clone():
        sh("git", "init")
        sh(
            "git",
            "fetch",
            "--depth=1",
            f"https://{get_secret(secret_name='GITHUB_ACCESS_TOKEN')}@github.com{path}",
            sha,
        )
        sh("git", "checkout", "FETCH_HEAD", "-f")

    if in_place:
        clone()
    else:
        with tmp_directory(clean=True):
            clone()
Пример #6
0
def load_dependencies(app: App, sha: str, repo: Repository):
    g = Github(get_secret(secret_name="GITHUB_ACCESS_TOKEN"))

    def clone_repo(repo_str: str):
        cloned_repo = g.get_repo(repo_str)
        cloned_sha = (sha if cloned_repo.full_name == repo.full_name else
                      cloned_repo.get_branch(
                          cloned_repo.default_branch).commit.sha)
        clone_commit(cloned_repo.clone_url, cloned_sha, in_place=True)

    with tmp_directory():
        for dependency in app.config["dependencies"]:
            folder_name = dependency["repo"].replace("/", "-")
            if not isdir(folder_name):
                # dependency is not already loaded
                mkdir(folder_name)
                chdir(folder_name)
                clone_repo(dependency["repo"])
                chdir("..")
            try:
                copytree(
                    os.path.join(folder_name, dependency["src"]),
                    os.path.join(app.name, dependency["dest"]),
                    symlinks=False,
                    dirs_exist_ok=True,
                )
            except NotADirectoryError:
                copyfile(
                    os.path.join(folder_name, dependency["src"]),
                    os.path.join(app.name, dependency["dest"]),
                )
        if app.config["repo"]:
            working_dir = gen_working_dir(app)
            mkdir(working_dir)
            chdir(working_dir)
            clone_repo(app.config["repo"])
            chdir("..")