diff --git a/launcher b/launcher index bcf6a81..bc1c994 100755 --- a/launcher +++ b/launcher @@ -9,6 +9,7 @@ local_image=local_seafile/server:latest dockerdir=$(cd "$(dirname $0)"; pwd -P) sharedir=$dockerdir/shared installdir=/opt/seafile/seafile-server-$version +bootstrap_conf=$dockerdir/bootstrap/bootstrap.conf cd $dockerdir @@ -37,8 +38,11 @@ init_shared() { } set_ports() { - ports="-p 80:80 -p 443:443" - ports="" + ports=$(docker run --rm -it \ + -v ${dockerdir}/scripts:/scripts \ + -v ${dockerdir}/bootstrap:/bootstrap:ro \ + $image \ + /scripts/bootstrap.py --parse-ports) } set_bootstrap_volumes() { @@ -80,7 +84,6 @@ set_volumes() { } bootstrap() { - local bootstrap_conf=$dockerdir/bootstrap/bootstrap.conf if [[ ! -e $bootstrap_conf ]]; then err_and_quit "The file $bootstrap_conf doesn't exist. Have you run seafile-server-setup?" fi diff --git a/samples/server.conf b/samples/server.conf index 00a21dc..e64be3d 100644 --- a/samples/server.conf +++ b/samples/server.conf @@ -1,5 +1,7 @@ +# If you edit this file, remember to run ./launcher rebuild [server] server.hostname = seafile.example.com server.https = true admin.email = me@example.com -admin.password = asecret \ No newline at end of file +admin.password = asecret +server.port_mappings = 80:80,443:443 \ No newline at end of file diff --git a/scripts/bootstrap.py b/scripts/bootstrap.py index d7fe3ac..6912d34 100755 --- a/scripts/bootstrap.py +++ b/scripts/bootstrap.py @@ -7,6 +7,7 @@ setup-seafile.sh or setup-seafile-mysql.sh. It's supposed to run inside the container. """ +import argparse import os from os.path import abspath, basename, exists, dirname, join, isdir import shutil @@ -56,7 +57,28 @@ def generate_local_dockerfile(): } render_template('/templates/Dockerfile.template', join(generated_dir, 'Dockerfile'), context) +def parse_args(): + ap = argparse.ArgumentParser() + ap.add_argument('--parse-ports', action='store_true') + + return ap.parse_args() + +def do_parse_ports(): + """ + Parse the server.port_mappings option and print docker command line port + mapping flags like "-p 80:80 -p 443:443" + """ + # conf is like '80:80,443:443' + conf = get_conf('server.port_mappings', '').strip() + if conf: + sys.stdout.write(' '.join(['-p {}'.format(part.strip()) for part in conf.split(',')])) + sys.stdout.flush() + def main(): + args = parse_args() + if args.parse_ports: + do_parse_ports() + return if not exists(shared_seafiledir): os.mkdir(shared_seafiledir) if not exists(generated_dir): @@ -92,4 +114,5 @@ def main(): shutil.move(src, shared_seafiledir) if __name__ == '__main__': + # TODO: validate the content of bootstrap.conf is valid main()