Add support for --build-arg option

This commit is contained in:
Andrej Zieger 2020-04-02 16:18:16 +02:00 committed by Muayyad Alsadi
parent e8147e350b
commit 19733407b4
3 changed files with 11 additions and 1 deletions

View File

@ -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():

View File

@ -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

View File

@ -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