7
0
mirror of https://github.com/ChristianLight/tutor.git synced 2024-05-28 20:00:49 +00:00

Slim down configurator image with alpine

By switching from ubuntu:18.04 to alpine, we reduce the local image size
from 510 to 87 Mb. Because we don't use bash anymore, it's difficult to
rely on chroot, so we just get rid of docker-entrypoint.sh
This commit is contained in:
Régis Behmo 2018-12-25 20:33:27 +01:00 committed by Régis Behmo
parent c903ab2b12
commit fbef486ad4
4 changed files with 29 additions and 26 deletions

View File

@ -1,14 +1,11 @@
FROM ubuntu:18.04
FROM python:3.6-alpine
RUN apt update && \
apt install -y python3 python3-pip curl
RUN pip3 install jinja2
RUN apk add --no-cache curl
RUN pip install jinja2
RUN mkdir /openedx /openedx/config /openedx/templates
COPY ./bin/configurator /usr/local/bin
COPY ./bin/docker-entrypoint.sh /usr/local/bin
WORKDIR /openedx/
ENTRYPOINT ["docker-entrypoint.sh"]
CMD configurator -c /openedx/config/config.json interactive && \
configurator -c /openedx/config/config.json substitute /openedx/templates/ /openedx/output/

View File

@ -103,6 +103,7 @@ def main():
parser_substitute.set_defaults(func=substitute)
args = parser.parse_args()
args.func(args)
def load_config(path):
@ -183,6 +184,7 @@ def interactive_configuration(config_path):
# Save values
with open(config_path, 'w') as f:
json.dump(configurator.as_dict(), f, sort_keys=True, indent=4)
set_owner(config_path)
def substitute(args):
@ -206,14 +208,35 @@ def substitute_file(config, src, dst):
sys.exit(1)
dst_dir = os.path.dirname(dst)
if not os.path.exists(dst_dir):
os.makedirs(dst_dir)
ensure_path_exists(dst_dir)
with codecs.open(dst, encoding='utf-8', mode='w') as fo:
fo.write(substituted)
set_owner(dst)
# Set same permissions as original file
os.chmod(dst, os.stat(src).st_mode)
def ensure_path_exists(directory):
"""
Create the required subfolders one by one, if necessary, and assign them
the right uid/gid.
"""
to_create = []
while not os.path.exists(directory):
to_create.append(directory)
directory = os.path.dirname(directory)
for d in to_create[::-1]:
os.mkdir(d)
set_owner(d)
def set_owner(path):
"""
If the USER_ID environment variable is defined, use it to set the
owner/group of the given file path.
"""
user_id = int(os.environ.get('USERID', 0))
if user_id:
os.chown(path, user_id, user_id)
def random_string(length):
return "".join([random.choice(string.ascii_letters + string.digits) for _ in range(length)])

View File

@ -1,17 +0,0 @@
#!/bin/bash -e
USERID=${USERID:=0}
## Configure user with a different USERID if requested.
if [ "$USERID" -ne 0 ]
then
useradd --home-dir /openedx -u $USERID openedx
# Change file permissions
chown --no-dereference -R openedx /openedx/config
# Run CMD as different user
exec chroot --userspec="$USERID" --skip-chdir / env HOME=/openedx "$@"
else
# Run CMD as root (business as usual)
exec "$@"
fi

View File

@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/sh
# This is a small script that helps me collect stats about who is using this
# project and understand how they are using it. Please don't remove me! As you
# can see, no personal data is leaked.