2019-01-22 20:25:04 +00:00
|
|
|
import click
|
|
|
|
|
2019-06-03 22:44:12 +00:00
|
|
|
from .. import config as tutor_config
|
2019-05-11 19:20:09 +00:00
|
|
|
from .. import env as tutor_env
|
2019-07-02 20:16:44 +00:00
|
|
|
from .. import images
|
2019-05-11 19:20:09 +00:00
|
|
|
from .. import opts
|
2019-07-02 20:16:44 +00:00
|
|
|
from .. import plugins
|
2019-01-22 20:25:04 +00:00
|
|
|
|
2019-04-23 07:57:55 +00:00
|
|
|
|
2019-05-29 08:30:30 +00:00
|
|
|
@click.group(name="images", short_help="Manage docker images")
|
2019-04-23 07:57:55 +00:00
|
|
|
def images_command():
|
2019-01-22 20:25:04 +00:00
|
|
|
pass
|
|
|
|
|
2019-04-23 07:57:55 +00:00
|
|
|
|
2019-01-22 20:25:04 +00:00
|
|
|
@click.command(
|
|
|
|
short_help="Build docker images",
|
2019-05-05 09:45:24 +00:00
|
|
|
help="Build the docker images necessary for an Open edX platform.",
|
2019-02-13 19:18:47 +00:00
|
|
|
)
|
2019-01-22 20:25:04 +00:00
|
|
|
@opts.root
|
2019-07-02 20:16:44 +00:00
|
|
|
@click.argument("image")
|
2019-05-22 17:17:54 +00:00
|
|
|
@click.option(
|
|
|
|
"--no-cache", is_flag=True, help="Do not use cache when building the image"
|
|
|
|
)
|
2019-01-22 20:25:04 +00:00
|
|
|
@click.option(
|
2019-05-05 09:45:24 +00:00
|
|
|
"-a",
|
|
|
|
"--build-arg",
|
|
|
|
multiple=True,
|
|
|
|
help="Set build-time docker ARGS in the form 'myarg=value'. This option may be specified multiple times.",
|
2019-01-22 20:25:04 +00:00
|
|
|
)
|
2019-05-22 17:17:54 +00:00
|
|
|
def build(root, image, no_cache, build_arg):
|
2019-03-18 16:26:37 +00:00
|
|
|
config = tutor_config.load(root)
|
2019-07-02 20:16:44 +00:00
|
|
|
|
|
|
|
# Build base images
|
|
|
|
for img in openedx_image_names(config):
|
|
|
|
if image in [img, "all"]:
|
|
|
|
tag = get_tag(config, img)
|
|
|
|
images.build(
|
|
|
|
tutor_env.pathjoin(root, "build", img),
|
|
|
|
tag,
|
|
|
|
no_cache=no_cache,
|
|
|
|
build_args=build_arg,
|
|
|
|
)
|
|
|
|
|
|
|
|
# Build plugin images
|
|
|
|
for plugin, hook in plugins.iter_hooks(config, "build-image"):
|
|
|
|
for img, tag in hook.items():
|
|
|
|
if image in [img, "all"]:
|
|
|
|
tag = tutor_env.render_str(config, tag)
|
|
|
|
images.build(
|
|
|
|
tutor_env.pathjoin(root, "plugins", plugin, "build", img),
|
|
|
|
tag,
|
|
|
|
no_cache=no_cache,
|
|
|
|
build_args=build_arg,
|
|
|
|
)
|
2019-01-22 20:25:04 +00:00
|
|
|
|
2019-04-23 07:57:55 +00:00
|
|
|
|
2019-03-18 21:39:35 +00:00
|
|
|
@click.command(short_help="Pull images from the Docker registry")
|
2019-03-18 16:26:37 +00:00
|
|
|
@opts.root
|
2019-07-02 20:16:44 +00:00
|
|
|
@click.argument("image")
|
2019-03-18 20:53:18 +00:00
|
|
|
def pull(root, image):
|
2019-03-18 16:26:37 +00:00
|
|
|
config = tutor_config.load(root)
|
2019-07-02 20:16:44 +00:00
|
|
|
# Pull base images
|
|
|
|
for img in image_names(config):
|
|
|
|
if image in [img, "all"]:
|
|
|
|
tag = get_tag(config, img)
|
|
|
|
images.pull(tag)
|
|
|
|
|
|
|
|
# Pull plugin images
|
|
|
|
for _plugin, hook in plugins.iter_hooks(config, "remote-image"):
|
|
|
|
for img, tag in hook.items():
|
|
|
|
if image in [img, "all"]:
|
|
|
|
tag = config["DOCKER_REGISTRY"] + tutor_env.render_str(config, tag)
|
|
|
|
images.pull(tag)
|
2019-02-13 19:18:47 +00:00
|
|
|
|
2019-04-23 07:57:55 +00:00
|
|
|
|
2019-03-18 20:53:18 +00:00
|
|
|
@click.command(short_help="Push images to the Docker registry")
|
2019-03-18 16:26:37 +00:00
|
|
|
@opts.root
|
2019-07-02 20:16:44 +00:00
|
|
|
@click.argument("image")
|
2019-03-18 20:53:18 +00:00
|
|
|
def push(root, image):
|
2019-03-18 16:26:37 +00:00
|
|
|
config = tutor_config.load(root)
|
2019-07-02 20:16:44 +00:00
|
|
|
# Push base images
|
|
|
|
for img in openedx_image_names(config):
|
|
|
|
if image in [img, "all"]:
|
|
|
|
tag = get_tag(config, img)
|
|
|
|
images.push(tag)
|
|
|
|
|
|
|
|
# Push plugin images
|
|
|
|
for _plugin, hook in plugins.iter_hooks(config, "remote-image"):
|
|
|
|
for img, tag in hook.items():
|
|
|
|
if image in [img, "all"]:
|
|
|
|
tag = config["DOCKER_REGISTRY"] + tutor_env.render_str(config, tag)
|
|
|
|
images.push(tag)
|
2019-01-22 20:25:04 +00:00
|
|
|
|
2019-04-23 07:57:55 +00:00
|
|
|
|
2019-03-18 20:53:18 +00:00
|
|
|
def get_tag(config, name):
|
|
|
|
image = config["DOCKER_IMAGE_" + name.upper()]
|
2019-05-05 09:45:24 +00:00
|
|
|
return "{registry}{image}".format(registry=config["DOCKER_REGISTRY"], image=image)
|
2019-01-22 20:25:04 +00:00
|
|
|
|
2019-04-23 07:57:55 +00:00
|
|
|
|
2019-07-02 20:16:44 +00:00
|
|
|
def image_names(config):
|
|
|
|
return openedx_image_names(config) + vendor_image_names(config)
|
|
|
|
|
|
|
|
|
|
|
|
def openedx_image_names(config):
|
|
|
|
openedx_images = ["openedx", "forum", "notes", "android"]
|
|
|
|
if not config["ACTIVATE_NOTES"]:
|
|
|
|
openedx_images.remove("notes")
|
|
|
|
return openedx_images
|
|
|
|
|
|
|
|
|
|
|
|
def vendor_image_names(config):
|
|
|
|
vendor_images = [
|
|
|
|
"elasticsearch",
|
|
|
|
"memcached",
|
|
|
|
"mongodb",
|
|
|
|
"mysql",
|
|
|
|
"nginx",
|
|
|
|
"rabbitmq",
|
|
|
|
"smtp",
|
|
|
|
]
|
|
|
|
if not config["ACTIVATE_ELASTICSEARCH"]:
|
|
|
|
vendor_images.remove("elasticsearch")
|
|
|
|
if not config["ACTIVATE_MEMCACHED"]:
|
|
|
|
vendor_images.remove("memcached")
|
|
|
|
if not config["ACTIVATE_MONGODB"]:
|
|
|
|
vendor_images.remove("mongodb")
|
|
|
|
if not config["ACTIVATE_MYSQL"]:
|
|
|
|
vendor_images.remove("mysql")
|
|
|
|
if not config["ACTIVATE_RABBITMQ"]:
|
|
|
|
vendor_images.remove("rabbitmq")
|
|
|
|
return vendor_images
|
2019-03-18 21:39:35 +00:00
|
|
|
|
2019-04-23 07:57:55 +00:00
|
|
|
|
|
|
|
images_command.add_command(build)
|
|
|
|
images_command.add_command(pull)
|
|
|
|
images_command.add_command(push)
|