mirror of
https://github.com/ChristianLight/tutor.git
synced 2024-12-12 14:17:46 +00:00
Do not require bash to be installed in docker containers.
Tutor is not using any bash-specific feature. This commit changes (almost) all invocations to /bin/bash replacing them with /bin/sh. It allows building a docker image that does not bundle bash in it. The file k8s.py still has a bash invocation, to make sure this change does not impact functionality for any user.
This commit is contained in:
parent
ce03d5fe4a
commit
4b6e6bcbf7
12
tutor/k8s.py
12
tutor/k8s.py
@ -66,7 +66,7 @@ def delete(yes):
|
|||||||
)
|
)
|
||||||
@opts.root
|
@opts.root
|
||||||
def databases(root):
|
def databases(root):
|
||||||
scripts.migrate(root, run_bash)
|
scripts.migrate(root, run_sh)
|
||||||
|
|
||||||
|
|
||||||
@click.command(help="Create an Open edX user and interactively set their password")
|
@click.command(help="Create an Open edX user and interactively set their password")
|
||||||
@ -76,14 +76,14 @@ def databases(root):
|
|||||||
@click.argument("name")
|
@click.argument("name")
|
||||||
@click.argument("email")
|
@click.argument("email")
|
||||||
def createuser(root, superuser, staff, name, email):
|
def createuser(root, superuser, staff, name, email):
|
||||||
scripts.create_user(root, run_bash, superuser, staff, name, email)
|
scripts.create_user(root, run_sh, superuser, staff, name, email)
|
||||||
|
|
||||||
|
|
||||||
@click.command(help="Import the demo course")
|
@click.command(help="Import the demo course")
|
||||||
@opts.root
|
@opts.root
|
||||||
def importdemocourse(root):
|
def importdemocourse(root):
|
||||||
click.echo(fmt.info("Importing demo course"))
|
click.echo(fmt.info("Importing demo course"))
|
||||||
scripts.import_demo_course(root, run_bash)
|
scripts.import_demo_course(root, run_sh)
|
||||||
click.echo(fmt.info("Re-indexing courses"))
|
click.echo(fmt.info("Re-indexing courses"))
|
||||||
indexcourses.callback(root)
|
indexcourses.callback(root)
|
||||||
|
|
||||||
@ -93,7 +93,7 @@ def importdemocourse(root):
|
|||||||
def indexcourses(root):
|
def indexcourses(root):
|
||||||
# Note: this is currently broken with "pymongo.errors.ConnectionFailure: [Errno 111] Connection refused"
|
# Note: this is currently broken with "pymongo.errors.ConnectionFailure: [Errno 111] Connection refused"
|
||||||
# I'm not quite sure the settings are correctly picked up. Which is weird because migrations work very well.
|
# I'm not quite sure the settings are correctly picked up. Which is weird because migrations work very well.
|
||||||
scripts.index_courses(root, run_bash)
|
scripts.index_courses(root, run_sh)
|
||||||
|
|
||||||
|
|
||||||
@click.command(
|
@click.command(
|
||||||
@ -176,8 +176,8 @@ class K8s:
|
|||||||
kubectl_no_fail("exec", "--namespace", self.NAMESPACE, "-it", podname, "--", *command)
|
kubectl_no_fail("exec", "--namespace", self.NAMESPACE, "-it", podname, "--", *command)
|
||||||
|
|
||||||
|
|
||||||
def run_bash(root, service, command): # pylint: disable=unused-argument
|
def run_sh(root, service, command): # pylint: disable=unused-argument
|
||||||
K8s().execute(service, "bash", "-e", "-c", command)
|
K8s().execute(service, "sh", "-e", "-c", command)
|
||||||
|
|
||||||
|
|
||||||
k8s.add_command(quickstart)
|
k8s.add_command(quickstart)
|
||||||
|
@ -129,7 +129,7 @@ def run(root, service, command, args):
|
|||||||
@opts.root
|
@opts.root
|
||||||
def databases(root):
|
def databases(root):
|
||||||
init_mysql(root)
|
init_mysql(root)
|
||||||
scripts.migrate(root, run_bash)
|
scripts.migrate(root, run_sh)
|
||||||
|
|
||||||
|
|
||||||
def init_mysql(root):
|
def init_mysql(root):
|
||||||
@ -247,7 +247,7 @@ def logs(root, follow, tail, service):
|
|||||||
def createuser(root, superuser, staff, name, email):
|
def createuser(root, superuser, staff, name, email):
|
||||||
config = tutor_config.load(root)
|
config = tutor_config.load(root)
|
||||||
check_service_is_activated(config, "lms")
|
check_service_is_activated(config, "lms")
|
||||||
scripts.create_user(root, run_bash, superuser, staff, name, email)
|
scripts.create_user(root, run_sh, superuser, staff, name, email)
|
||||||
|
|
||||||
|
|
||||||
@click.command(help="Import the demo course")
|
@click.command(help="Import the demo course")
|
||||||
@ -256,7 +256,7 @@ def importdemocourse(root):
|
|||||||
config = tutor_config.load(root)
|
config = tutor_config.load(root)
|
||||||
check_service_is_activated(config, "cms")
|
check_service_is_activated(config, "cms")
|
||||||
click.echo(fmt.info("Importing demo course"))
|
click.echo(fmt.info("Importing demo course"))
|
||||||
scripts.import_demo_course(root, run_bash)
|
scripts.import_demo_course(root, run_sh)
|
||||||
click.echo(fmt.info("Re-indexing courses"))
|
click.echo(fmt.info("Re-indexing courses"))
|
||||||
indexcourses.callback(root)
|
indexcourses.callback(root)
|
||||||
|
|
||||||
@ -266,7 +266,7 @@ def importdemocourse(root):
|
|||||||
def indexcourses(root):
|
def indexcourses(root):
|
||||||
config = tutor_config.load(root)
|
config = tutor_config.load(root)
|
||||||
check_service_is_activated(config, "cms")
|
check_service_is_activated(config, "cms")
|
||||||
scripts.index_courses(root, run_bash)
|
scripts.index_courses(root, run_sh)
|
||||||
|
|
||||||
|
|
||||||
@click.command(
|
@click.command(
|
||||||
@ -292,9 +292,9 @@ def check_service_is_activated(config, service):
|
|||||||
raise exceptions.TutorError("This command may only be executed on the server where the {} is running".format(service))
|
raise exceptions.TutorError("This command may only be executed on the server where the {} is running".format(service))
|
||||||
|
|
||||||
|
|
||||||
def run_bash(root, service, command):
|
def run_sh(root, service, command):
|
||||||
config = tutor_config.load(root)
|
config = tutor_config.load(root)
|
||||||
docker_compose(root, config, "run", "--rm", service, "bash", "-e", "-c", command)
|
docker_compose(root, config, "run", "--rm", service, "sh", "-e", "-c", command)
|
||||||
|
|
||||||
|
|
||||||
def docker_compose(root, config, *command):
|
def docker_compose(root, config, *command):
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#!/bin/bash -e
|
#!/bin/sh -e
|
||||||
export DJANGO_SETTINGS_MODULE=$SERVICE_VARIANT.envs.$SETTINGS
|
export DJANGO_SETTINGS_MODULE=$SERVICE_VARIANT.envs.$SETTINGS
|
||||||
USERID=${USERID:=0}
|
USERID=${USERID:=0}
|
||||||
|
|
||||||
@ -13,7 +13,7 @@ if [ "$USERID" -ne 0 ]
|
|||||||
|
|
||||||
# Run CMD as different user
|
# Run CMD as different user
|
||||||
exec chroot --userspec="$USERID" --skip-chdir / env HOME=/openedx "$@"
|
exec chroot --userspec="$USERID" --skip-chdir / env HOME=/openedx "$@"
|
||||||
else
|
else
|
||||||
# Run CMD as root (business as usual)
|
# Run CMD as root (business as usual)
|
||||||
exec "$@"
|
exec "$@"
|
||||||
fi
|
fi
|
||||||
|
@ -49,7 +49,7 @@ services:
|
|||||||
image: {{ DOCKER_REGISTRY }}{{ DOCKER_IMAGE_OPENEDX }}
|
image: {{ DOCKER_REGISTRY }}{{ DOCKER_IMAGE_OPENEDX }}
|
||||||
volumes:
|
volumes:
|
||||||
- ../../data/openedx:/var/www/openedx
|
- ../../data/openedx:/var/www/openedx
|
||||||
command: bash -c "rm -rf /var/www/openedx/staticfiles && cp -r /openedx/staticfiles/ /var/www/openedx/"
|
command: sh -c "rm -rf /var/www/openedx/staticfiles && cp -r /openedx/staticfiles/ /var/www/openedx/"
|
||||||
|
|
||||||
nginx:
|
nginx:
|
||||||
image: {{ DOCKER_REGISTRY }}{{ DOCKER_IMAGE_NGINX }}
|
image: {{ DOCKER_REGISTRY }}{{ DOCKER_IMAGE_NGINX }}
|
||||||
|
Loading…
Reference in New Issue
Block a user