7
0
mirror of https://github.com/ChristianLight/tutor.git synced 2024-06-18 05:12:21 +00:00

Add support for images build --add-host

This was originally proposed here by @grinderz:
https://github.com/overhangio/tutor/pull/355
This commit is contained in:
Régis Behmo 2020-09-04 12:35:44 +02:00
parent e9585bdc80
commit b1c7dab03e
3 changed files with 25 additions and 25 deletions

View File

@ -4,6 +4,7 @@ Note: Breaking changes between versions are indicated by "💥".
## Unreleased
- [Feature] Add support for `images build --add-host` option (thanks @grinderz!)
- [Bugfix] Fix podman compatibility by replacing `docker-compose rm` command by `docker-compose stop` when stopping containers
- [Improvement] Improve plugin data deletion
- [Improvement] Introduce the `OPENEDX_COMMON_VERSION` setting

View File

@ -27,27 +27,36 @@ def images_command():
@click.option(
"-a",
"--build-arg",
"build_args",
multiple=True,
help="Set build-time docker ARGS in the form 'myarg=value'. This option may be specified multiple times.",
)
@click.option(
"--add-host",
"add_hosts",
multiple=True,
help="Set a custom host-to-IP mapping (host:ip).",
)
@click.pass_obj
def build(context, image, no_cache, build_arg):
def build(context, image, no_cache, build_args, add_hosts):
config = tutor_config.load(context.root)
command_args = []
if no_cache:
command_args.append("--no-cache")
for build_arg in build_args:
command_args += ["--build-arg", build_arg]
for add_host in add_hosts:
command_args += ["--add-host", add_host]
for i in image:
build_image(context.root, config, i, no_cache, build_arg)
build_image(context.root, config, i, *command_args)
def build_image(root, config, image, no_cache, build_arg):
def build_image(root, config, image, *args):
# Build base images
for img in BASE_IMAGE_NAMES:
if image in [img, "all"]:
tag = images.get_tag(config, img)
images.build(
tutor_env.pathjoin(root, "build", img),
tag,
no_cache=no_cache,
build_args=build_arg,
)
images.build(tutor_env.pathjoin(root, "build", img), tag, *args)
# Build plugin images
for plugin, hook in plugins.iter_hooks(config, "build-image"):
@ -57,21 +66,17 @@ def build_image(root, config, image, no_cache, build_arg):
images.build(
tutor_env.pathjoin(root, "plugins", plugin, "build", img),
tag,
no_cache=no_cache,
build_args=build_arg,
*args
)
# Build dev images
# Build dev images with user id argument
user_id = subprocess.check_output(["id", "-u"]).strip().decode()
dev_build_args = list(build_arg) + ["USERID={}".format(user_id)]
dev_build_arg = ["--build-arg", "USERID={}".format(user_id)]
for img in DEV_IMAGE_NAMES:
if image in [img, "all"]:
tag = images.get_tag(config, img)
images.build(
tutor_env.pathjoin(root, "build", img),
tag,
no_cache=no_cache,
build_args=dev_build_args,
tutor_env.pathjoin(root, "build", img), tag, *dev_build_arg, *args
)

View File

@ -6,15 +6,9 @@ def get_tag(config, name):
return config["DOCKER_IMAGE_" + name.upper().replace("-", "_")]
def build(path, tag, no_cache=False, build_args=None):
def build(path, tag, *args):
fmt.echo_info("Building image {}".format(tag))
command = ["build", "-t", tag, path]
build_args = build_args or {}
if no_cache:
command.append("--no-cache")
for arg in build_args:
command += ["--build-arg", arg]
utils.docker(*command)
utils.docker("build", "-t", tag, *args, path)
def pull(tag):