Commit 27420b89 authored by Pietro Albini's avatar Pietro Albini

Clone the source code of the branches during the build

This commit removes the shared git repository in the root directory:
instead, a 1-depth clone of the branch is done at the start of each
build, so the source code is guaranteed to be fresh.

This doesn't affect build times so much, because only the latest commit
is cloned, not the whole history.
parent c49b31b3
...@@ -75,7 +75,7 @@ def init_command(ctx, git_url): ...@@ -75,7 +75,7 @@ def init_command(ctx, git_url):
error("root directory not empty") error("root directory not empty")
root.mkdir(parents=True) root.mkdir(parents=True)
for dir in ("git", "branches"): for dir in ("branches",):
(root / dir).mkdir() (root / dir).mkdir()
with (root / "version").open("w") as f: with (root / "version").open("w") as f:
...@@ -83,6 +83,7 @@ def init_command(ctx, git_url): ...@@ -83,6 +83,7 @@ def init_command(ctx, git_url):
with (root / "config.json").open("w") as f: with (root / "config.json").open("w") as f:
content = { content = {
"git-url": git_url,
"gitlab-url": "http://code.ubuntu-it.org", "gitlab-url": "http://code.ubuntu-it.org",
"gitlab-project": "ubuntu-it-web/www", "gitlab-project": "ubuntu-it-web/www",
"gitlab-token": "abcdefghi", "gitlab-token": "abcdefghi",
...@@ -101,8 +102,6 @@ def init_command(ctx, git_url): ...@@ -101,8 +102,6 @@ def init_command(ctx, git_url):
json.dump(content, f, indent=4) json.dump(content, f, indent=4)
f.write("\n") f.write("\n")
subprocess.call(["git", "clone", git_url, str(root / "git"), "--bare"])
@cli.command("run") @cli.command("run")
@click.option("-p", "--port", help="The port for the frontend application", @click.option("-p", "--port", help="The port for the frontend application",
......
...@@ -206,7 +206,7 @@ class Branch: ...@@ -206,7 +206,7 @@ class Branch:
shutil.rmtree(str(branch)) shutil.rmtree(str(branch))
branch.mkdir() branch.mkdir()
git_dir = str(self.manager.root / "git") git_url = self.manager.config["git-url"]
build_dir = branch / "build" build_dir = branch / "build"
log_file = branch / "build.log" log_file = branch / "build.log"
...@@ -227,19 +227,16 @@ class Branch: ...@@ -227,19 +227,16 @@ class Branch:
# Update the bare git repository and checkout the branch # Update the bare git repository and checkout the branch
subprocess.call([ subprocess.call([
"git", "--git-dir", git_dir, "fetch", "origin" "git", "clone", "--depth", "1", "--branch", self.name, git_url,
], stdout=log_file.open("a"), stderr=subprocess.STDOUT) str(build_dir),
subprocess.call([
"git", "--git-dir", git_dir, "--work-tree", str(build_dir),
"checkout", "-f", self.name,
], stdout=log_file.open("a"), stderr=subprocess.STDOUT) ], stdout=log_file.open("a"), stderr=subprocess.STDOUT)
# Get the commit of the branch # Get the commit of the branch
commit_file = branch / "commit" commit_file = branch / "commit"
subprocess.call( subprocess.call([
["git", "--git-dir", git_dir, "rev-parse", self.name], "git", "--git-dir", str(build_dir / ".git"), "rev-parse",
stdout=commit_file.open("w"), stderr=log_file.open("a"), self.name
) ], stdout=commit_file.open("w"), stderr=log_file.open("a"))
# Copy and load the configuration file # Copy and load the configuration file
if not (build_dir / "managetests.json").exists(): if not (build_dir / "managetests.json").exists():
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
import pathlib import pathlib
ROOT_DIR_VERSION = "1" ROOT_DIR_VERSION = "2"
def is_root_valid(path): def is_root_valid(path):
...@@ -27,7 +27,7 @@ def is_root_valid(path): ...@@ -27,7 +27,7 @@ def is_root_valid(path):
if not (path.exists() and path.is_dir()): if not (path.exists() and path.is_dir()):
return False return False
required_dirs = ["git", "branches"] required_dirs = ["branches"]
required_files = ["config.json", "details.json", "version"] required_files = ["config.json", "details.json", "version"]
for dir in required_dirs: for dir in required_dirs:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment