diff --git a/podman_compose.py b/podman_compose.py index f2fd423..896166a 100755 --- a/podman_compose.py +++ b/podman_compose.py @@ -1071,7 +1071,7 @@ def build_one(compose, args, cnt): if getattr(args, 'pull_always', None): build_args.append("--pull-always") elif getattr(args, 'pull', None): build_args.append("--pull") args_list = norm_as_list(build_desc.get('args', {})) - for build_arg in args_list: + for build_arg in args_list + args.build_arg: build_args.extend(("--build-arg", build_arg,)) build_args.append(ctx) compose.podman.run(build_args, sleep=0) @@ -1364,6 +1364,8 @@ def compose_build_parse(parser): help="attempt to pull a newer version of the image", action='store_true') parser.add_argument("--pull-always", help="attempt to pull a newer version of the image, Raise an error even if the image is present locally.", action='store_true') + parser.add_argument("--build-arg", metavar="key=val", action="append", default=[], + help="Set build-time variables for services.") def main(): diff --git a/tests/build/context/Dockerfile-alt b/tests/build/context/Dockerfile-alt index e0e71d7..75b5852 100644 --- a/tests/build/context/Dockerfile-alt +++ b/tests/build/context/Dockerfile-alt @@ -1,7 +1,9 @@ FROM busybox ARG buildno=1 ARG httpd_port=80 +ARG other_variable=not_set ENV httpd_port ${httpd_port} +ENV other_variable ${other_variable} RUN mkdir -p /var/www/html/ && \ echo "ALT buildno=$buildno port=$httpd_port `date -Iseconds`" > /var/www/html/index.txt CMD httpd -f -p "$httpd_port" -h /var/www/html diff --git a/tests/build/docker-compose.yml b/tests/build/docker-compose.yml index 6984b24..a1116ad 100644 --- a/tests/build/docker-compose.yml +++ b/tests/build/docker-compose.yml @@ -17,3 +17,9 @@ services: image: my-busybox-httpd2 ports: - 8000:8000 + test_build_arg_argument: + build: + context: ./context + dockerfile: Dockerfile-alt + image: my-busybox-httpd2 + command: env