| 
16 | 16 | import urllib.request  | 
17 | 17 | import json  | 
18 | 18 | import subprocess  | 
 | 19 | +import shlex  | 
19 | 20 | import sys  | 
20 | 21 | import os  | 
21 | 22 | 
 
  | 
22 | 23 | 
 
  | 
23 | 24 | def run_command(cmd, log_file=None):  | 
24 |  | -    print("Running: {}".format(cmd))  | 
 | 25 | +    if isinstance(cmd, str):  | 
 | 26 | +        cmd = shlex.split(cmd)  | 
 | 27 | +    print("Running: {}".format(shlex.join(cmd)))  | 
25 | 28 |     sys.stdout.flush()  | 
26 | 29 |     if log_file:  | 
27 | 30 |         file = open(log_file, "w")  | 
28 |  | -        p = subprocess.Popen(cmd, shell=True, stdout=file, stderr=file)  | 
29 | 31 |     else:  | 
30 |  | -        p = subprocess.Popen(cmd, shell=True)  | 
31 |  | -        | 
 | 32 | +        file = None  | 
 | 33 | +    p = subprocess.Popen(cmd, stdout=file, stderr=file)  | 
 | 34 | + | 
32 | 35 |     (output, err) = p.communicate()  | 
33 | 36 |     return p.wait()  | 
34 | 37 | 
 
  | 
@@ -62,30 +65,47 @@ def main():  | 
62 | 65 |     results = {}  | 
63 | 66 |     suite_status = True  | 
64 | 67 |     dockerfiles = get_dockerfiles()  | 
 | 68 | +    root_dir = os.path.dirname(os.path.realpath(__file__))  | 
65 | 69 |     for dockerfile in dockerfiles:  | 
66 |  | -        docker_dir = os.path.dirname(os.path.realpath(__file__))  | 
 | 70 | +        # Make sure everything is relative  | 
 | 71 | +        dockerfile = os.path.relpath(os.path.realpath(dockerfile), root_dir)  | 
 | 72 | + | 
 | 73 | +        docker_dir, docker_name = os.path.split(dockerfile)  | 
 | 74 | + | 
67 | 75 |         print("Testing {}".format(dockerfile))  | 
68 | 76 |         sys.stdout.flush()  | 
69 |  | -        log_file = dockerfile.replace(docker_dir,"").replace("/", "_")  | 
 | 77 | +        log_file = dockerfile.replace("/", "_")  | 
70 | 78 |         log_file = "{}.log".format(log_file)  | 
71 |  | -        cmd = "docker build --no-cache=true -f {dockerfile} .".format(dockerfile=dockerfile)  | 
 | 79 | +        cmd = [  | 
 | 80 | +            'docker', 'build', '--no-cache=true',  | 
 | 81 | +            '-f', dockerfile,  | 
 | 82 | +            docker_dir  | 
 | 83 | +        ]  | 
72 | 84 |         if "buildx" in dockerfile:  | 
73 | 85 |             # if "buildx" is part of the path, we want to use the new buildx build system and build  | 
74 | 86 |             # for both amd64 and arm64.  | 
75 |  | -            cmd = "docker buildx create --use"  | 
76 |  | -            run_command(cmd, log_file)  | 
77 |  | -            cmd = "docker buildx inspect --bootstrap"  | 
78 |  | -            run_command(cmd, log_file)  | 
79 |  | -            cmd = "docker buildx build --platform linux/arm64,linux/amd64 --no-cache=true -f {dockerfile} .".format(dockerfile=dockerfile)  | 
80 |  | -        status = run_command(cmd, log_file)  | 
 | 87 | +            run_command("docker buildx create --use", log_file=log_file)  | 
 | 88 | +            run_command("docker buildx inspect --bootstrap", log_file=log_file)  | 
 | 89 | + | 
 | 90 | +            cmd = [  | 
 | 91 | +                'docker', 'buildx', 'build',  | 
 | 92 | +                '--platform', 'linux/arm64,linux/amd64',  | 
 | 93 | +                '--no-cache=true',  | 
 | 94 | +                '-f', dockerfile,  | 
 | 95 | +                docker_dir  | 
 | 96 | +            ]  | 
 | 97 | + | 
 | 98 | +        status = run_command(cmd, log_file=log_file)  | 
81 | 99 |         results[dockerfile] = status  | 
82 | 100 |         if status != 0:  | 
83 | 101 |             suite_status = False  | 
84 | 102 |             results[dockerfile] = "FAILED"  | 
85 | 103 |         else:  | 
86 | 104 |             results[dockerfile] = "PASSED"  | 
87 | 105 | 
 
  | 
88 |  | -        cmd = "mv {log} {results}{log}".format(log=log_file, results=results[dockerfile])  | 
 | 106 | +        cmd = [  | 
 | 107 | +            'mv', log_file, results[dockerfile] + log_file  | 
 | 108 | +        ]  | 
89 | 109 |         run_command(cmd)  | 
90 | 110 |         print("[{}] - {}".format(results[dockerfile], dockerfile))  | 
91 | 111 |         sys.stdout.flush()  | 
 | 
0 commit comments