Handle docker ports mapping.

This commit is contained in:
Shuai Lin 2016-11-16 09:46:08 +08:00
parent 1832ad5acb
commit ec8d6e638d
3 changed files with 32 additions and 4 deletions

View file

@ -9,6 +9,7 @@ local_image=local_seafile/server:latest
dockerdir=$(cd "$(dirname $0)"; pwd -P) dockerdir=$(cd "$(dirname $0)"; pwd -P)
sharedir=$dockerdir/shared sharedir=$dockerdir/shared
installdir=/opt/seafile/seafile-server-$version installdir=/opt/seafile/seafile-server-$version
bootstrap_conf=$dockerdir/bootstrap/bootstrap.conf
cd $dockerdir cd $dockerdir
@ -37,8 +38,11 @@ init_shared() {
} }
set_ports() { set_ports() {
ports="-p 80:80 -p 443:443" ports=$(docker run --rm -it \
ports="" -v ${dockerdir}/scripts:/scripts \
-v ${dockerdir}/bootstrap:/bootstrap:ro \
$image \
/scripts/bootstrap.py --parse-ports)
} }
set_bootstrap_volumes() { set_bootstrap_volumes() {
@ -80,7 +84,6 @@ set_volumes() {
} }
bootstrap() { bootstrap() {
local bootstrap_conf=$dockerdir/bootstrap/bootstrap.conf
if [[ ! -e $bootstrap_conf ]]; then if [[ ! -e $bootstrap_conf ]]; then
err_and_quit "The file $bootstrap_conf doesn't exist. Have you run seafile-server-setup?" err_and_quit "The file $bootstrap_conf doesn't exist. Have you run seafile-server-setup?"
fi fi

View file

@ -1,5 +1,7 @@
# If you edit this file, remember to run ./launcher rebuild
[server] [server]
server.hostname = seafile.example.com server.hostname = seafile.example.com
server.https = true server.https = true
admin.email = me@example.com admin.email = me@example.com
admin.password = asecret admin.password = asecret
server.port_mappings = 80:80,443:443

View file

@ -7,6 +7,7 @@ setup-seafile.sh or setup-seafile-mysql.sh. It's supposed to run inside the
container. container.
""" """
import argparse
import os import os
from os.path import abspath, basename, exists, dirname, join, isdir from os.path import abspath, basename, exists, dirname, join, isdir
import shutil import shutil
@ -56,7 +57,28 @@ def generate_local_dockerfile():
} }
render_template('/templates/Dockerfile.template', join(generated_dir, 'Dockerfile'), context) 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(): def main():
args = parse_args()
if args.parse_ports:
do_parse_ports()
return
if not exists(shared_seafiledir): if not exists(shared_seafiledir):
os.mkdir(shared_seafiledir) os.mkdir(shared_seafiledir)
if not exists(generated_dir): if not exists(generated_dir):
@ -92,4 +114,5 @@ def main():
shutil.move(src, shared_seafiledir) shutil.move(src, shared_seafiledir)
if __name__ == '__main__': if __name__ == '__main__':
# TODO: validate the content of bootstrap.conf is valid
main() main()