Skip to content

Commit

Permalink
config/docker: add --build-arg option to kci_docker
Browse files Browse the repository at this point in the history
Add --build-arg command line argument to kci_docker to work in the
same way as the 'docker build' command, to pass an arbitrary number of
key-valye build argument pairs.

Also add a note in the README.md with an example.

Signed-off-by: Guillaume Tucker <guillaume.tucker@collabora.com>
  • Loading branch information
gctucker committed Jul 29, 2022
1 parent 2882a7f commit 2ada261
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
4 changes: 4 additions & 0 deletions config/docker-new/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,7 @@ installed, as well as the KernelCI core tools:

$ ./kci_docker build clang-14 --prefix=my-stuff/ --fragment=kselftest --fragment=kernelci
Building my-stuff/clang-14:kselftest-kernelci

Build the `kernelci` image with a particular revision using `--build-arg`:

./kci_docker build kernelci --build-arg core_rev=staging-20220728.1
15 changes: 12 additions & 3 deletions config/docker-new/kci_docker
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ def _gen_dockerfile(img_name, params):
return template.render(params)


def _build_image(dockerfile, tag_name):
def _build_image(dockerfile, tag_name, buildargs):
client = docker.from_env()
dockerfile_obj = io.BytesIO(dockerfile.encode())
return client.images.build(fileobj=dockerfile_obj, tag=tag_name)
return client.images.build(
fileobj=dockerfile_obj, tag=tag_name, buildargs=buildargs
)


def _dump_dockerfile(dockerfile):
Expand Down Expand Up @@ -79,7 +81,12 @@ def main(args):
_dump_dockerfile(dockerfile)

print(f"Building {name}")
_, build_log = _build_image(dockerfile, name)
buildargs = {
name: value for (name, value) in (
barg.split('=') for barg in args.build_arg
)
}
_, build_log = _build_image(dockerfile, name, buildargs)
if args.verbose:
_dump_log(build_log)

Expand All @@ -98,5 +105,7 @@ if __name__ == '__main__':
help="Extra fragments, e.g. kernelci")
parser.add_argument('--verbose', action='store_true',
help="Verbose output")
parser.add_argument('--build-arg', action='append',
help="Build argument to pass to docker build")
main(parser.parse_args())
sys.exit(0)

0 comments on commit 2ada261

Please sign in to comment.