File size: 1,266 Bytes
0e239c6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
"""Build a task's environment-only Docker image from its release recipe."""
import argparse
import json
from pathlib import Path
import subprocess
from common import ROOT, contained, load_task, sha256


def build(instance_id, tag):
    task = load_task(instance_id)
    directory = contained(ROOT / "instances", task["instance_id"])
    recipe = contained(directory, "environment/Dockerfile")
    if not recipe.is_file():
        raise ValueError("This task does not yet have a portable environment recipe")
    refs = {ref["path"]: ref for ref in task["artifacts"]}
    for path in recipe.parent.rglob("*"):
        if path.is_file():
            relative = str(path.relative_to(directory))
            if relative not in refs or sha256(path) != refs[relative]["sha256"]:
                raise ValueError(f"Environment recipe artifact changed: {relative}")
    subprocess.run(["docker", "build", "--pull", "--platform", "linux/amd64", "--tag", tag, "--file", str(recipe), str(recipe.parent)], check=True)


if __name__ == "__main__":
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument("--instance-id", required=True)
    parser.add_argument("--tag", required=True)
    args = parser.parse_args()
    build(args.instance_id, args.tag)