Skip to content
This repository has been archived by the owner on Jan 22, 2022. It is now read-only.

Build from berkeley-cs61a directly #426

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 34 additions & 41 deletions buildserver/app_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,18 @@


class Config(TypedDict):
build_type: Literal[
"create_react_app",
"oh_queue",
"webpack",
"61a_website",
"hugo",
"jekyll",
"none",
target: str
match: List[str]
build_type: Optional[
Literal[
"create_react_app",
"oh_queue",
"webpack",
"61a_website",
"hugo",
"jekyll",
"none",
]
]
deploy_type: Literal[
"flask",
Expand Down Expand Up @@ -90,39 +94,28 @@ class App:
# updated by deploy.py, since PyPI takes a while to update
deployed_pypi_version: Optional[str]

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]
)
self.config["permissions"] = self.config.get(
"permissions", ["rpc", "database"]
)
except FileNotFoundError:
# app has been deleted in PR
self.config = None
def __init__(self, name: str, data: Optional[dict]):
if data is None:
self.config = None
return

self.config = Config(**data)
self.config["build_type"] = self.config.get("build_type", None)
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])
self.config["permissions"] = self.config.get("permissions", ["rpc", "database"])

def __str__(self):
return self.name
51 changes: 31 additions & 20 deletions buildserver/build.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from os.path import join
from shutil import copytree, rmtree
from urllib.parse import urlparse

Expand Down Expand Up @@ -34,29 +35,39 @@ def clone():

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("..")
if app.config["build_type"]:
{
"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"]]()
else:
# bt will place the built output here:
# // -> working_dir -> _destination -> target
destination_name = "__destination"
output_directory = join(working_dir, destination_name)
target = app.config["target"]
sh(
"bt",
target,
"--quiet",
"--profile",
*("--num-threads", 4),
*("--flag", output_directory),
)

# We will move _destination/target into working_dir, then clear _destination
clean_all_except([destination_name])
copytree(join(destination_name, target), ".", dirs_exist_ok=True)
rmtree(destination_name)


def run_oh_queue_build():
Expand Down
3 changes: 2 additions & 1 deletion buildserver/conf.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
GITHUB_REPO = "Cal-CS-61A-Staff/cs61a-apps"
GITHUB_REPO = "Cal-CS-61A-Staff/berkeley-cs61a"
PROJECT_ID = "cs61a-140900"
DB_SHORT_INSTANCE_NAME = "cs61a-apps-us-west1"
DB_INSTANCE_NAME = f"{PROJECT_ID}:us-west2:{DB_SHORT_INSTANCE_NAME}"
DB_IP_ADDRESS = "35.236.93.51"
STATIC_SERVER = "static-server"
GITHUB_BOT_USER = "pusherbot"
1 change: 0 additions & 1 deletion buildserver/env.py

This file was deleted.

22 changes: 0 additions & 22 deletions buildserver/external_build_worker.py

This file was deleted.

7 changes: 0 additions & 7 deletions buildserver/external_repo_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,3 @@ def update_config(app: App, pr_number: int):
"INSERT INTO services VALUES (%s, %s, %s, %s)",
[app.name, pr_number, False, app.config["deploy_type"] in WEB_DEPLOY_TYPES],
)
if pr_number == 0:
db("DELETE FROM apps WHERE app=%s", [app.name])
if app.config["repo"]:
db(
"INSERT INTO apps (app, repo, autobuild) VALUES (%s, %s, %s)",
[app.name, app.config["repo"], True],
)
Loading