|
22 | 22 | parser.add_argument("-o", "--out", "--output", default="Dockerfile", |
23 | 23 | help="output file name to write Dockerfile to, defaults to 'Dockerfile'") |
24 | 24 | parser.add_argument("-j", action="store_true", help="Also output a json with information about the image.") |
| 25 | +parser.add_argument("--tests", action="store_true", help="Also generate test.sh that will run tests for the image") |
25 | 26 |
|
26 | 27 |
|
27 | 28 | args = parser.parse_args() |
|
37 | 38 | context = config.default_env.load(args.config) |
38 | 39 | else: |
39 | 40 | package_info = package_filename.parse(args.package_url.rsplit("/", 1)[-1]) |
40 | | - package_version = package_info.get("version") |
41 | | - package_version_extra = package_info.get("version_extra") |
42 | | - if args.wheels_url and package_version and package_version_extra: |
43 | | - # concatenating without the last part |
44 | | - package_version += "." + package_version_extra.rsplit(".", 1)[0] |
| 41 | + package_version = package_info["version"] |
| 42 | + wheels_version = package_version |
| 43 | + if args.wheels_url: |
| 44 | + # this is a pre-release then add extra version |
| 45 | + package_version += "." + package_info["version_extra"] |
45 | 46 | config_data = { |
46 | 47 | "_based_on": package_info["os"], |
47 | 48 | "_template": "Dockerfile_default.j2", |
|
50 | 51 | "version": package_version, |
51 | 52 | "wheels": { |
52 | 53 | "url": args.wheels_url, |
53 | | - # "version": None |
| 54 | + "version": wheels_version |
54 | 55 | } |
55 | 56 | } |
56 | 57 | } |
|
72 | 73 | with open(args.out, "w") as outfile: |
73 | 74 | outfile.write(dockerfile) |
74 | 75 |
|
| 76 | +image_name = f"{context['os_id']}_{args.preset}:{context['package']['version']}" |
| 77 | + |
75 | 78 | if args.j: |
76 | 79 | with open("image_data.json", "w") as file: |
77 | 80 | json.dump({ |
78 | | - "image_name": f"{context['os_id']}_{args.preset}:{context['package']['version']}", |
| 81 | + "image_name": image_name, |
79 | 82 | "base_image": context["base_image"], |
80 | 83 | "product_version": context["package"]["version"], |
81 | 84 | "wheels_version": None, |
82 | 85 | "distribution": args.preset, |
83 | 86 | "os": context["os_id"] |
84 | 87 | }, file) |
| 88 | + |
| 89 | +if args.tests: |
| 90 | + testfile = open("test.sh", "w") |
| 91 | + testfile.write("set -e\n") |
| 92 | + testfile.write(f"IMAGE_NAME={image_name}\n") |
| 93 | + testfile.write("TESTS_VOLUME=./refactor/tests/in_container:/tests\n") |
| 94 | + testfile.write('crun() { docker run --rm -it -v $TESTS_VOLUME $IMAGE_NAME bash -c "$1"; }\n') |
| 95 | + testfile.write('run_test() { echo TEST $1 $2; crun "/tests/$1 $2 2>&1 >/dev/null && echo SUCCESS || echo ERROR"; }\n') |
| 96 | + testfile.write("docker build -t $IMAGE_NAME .\n") |
| 97 | + for test in context["tests"]: |
| 98 | + arg = None |
| 99 | + try: |
| 100 | + test, arg = test.split("@", 1) |
| 101 | + except ValueError: |
| 102 | + pass |
| 103 | + testfile.write(f"run_test {test} {arg}\n") |
0 commit comments