From 33d326f774e95f25c353e6c8d643f0b543711497 Mon Sep 17 00:00:00 2001 From: Maxime Daniel Date: Wed, 17 Jan 2024 01:11:30 +0100 Subject: [PATCH] container: improve auto-configuration - Fix issue with /public and /workdir not working out-of-box - Automatically set zflist-bin config if container special file detected --- README.md | 3 ++- deployment/Dockerfile | 1 + src/config.py.sample | 5 +++-- src/flist-uploader.py | 26 ++++++++++++++++++-------- 4 files changed, 24 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index b1e45a1..9db3378 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,8 @@ Here are some point you need to run the hub: - Mount host docker.sock to `/var/run/docker.sock` to be able to run docker converter Regarding configuration, here are some requirement: -- `zflist-bin` have to be set to: `/usr/bin/zflist` (it's part of the image) +- `zflist-bin` have to be or unset or set to: `/usr/bin/zflist` (it's part of the image) + - Comment this line in config to make it simple Dockerfile can be found on `deployment` directory. diff --git a/deployment/Dockerfile b/deployment/Dockerfile index dec1991..7e27caa 100644 --- a/deployment/Dockerfile +++ b/deployment/Dockerfile @@ -47,6 +47,7 @@ RUN apt-get update && apt-get install -y \ python3-requests python3-nacl python3-jose && \ tar -xf /hub.tar -C / && rm -f /hub.tar && \ mkdir /public /workdir && \ + touch /.hub-container && \ rm -rf /var/lib/apt/lists/* WORKDIR /hub/src diff --git a/src/config.py.sample b/src/config.py.sample index 8e75b0c..4bccea1 100644 --- a/src/config.py.sample +++ b/src/config.py.sample @@ -58,7 +58,8 @@ config = { ## You can provide an optional zflist binary path ## if not provided, the default value will be used - ## (/opt/0-flist/zflist/zflist) + ## - /opt/0-flist/zflist/zflist (default) + ## - /usr/bin/zflist (hub container) ## ## Note: you _need_ to use a non-debug version of zflist ## you can make a non-debug version of zflist by using @@ -71,7 +72,7 @@ config = { ## If you have a debug version of zflist, it will print ## extra debug information and json won't be parsed ## correctly - 'zflist-bin': '/opt/0-flist/zflist/zflist', + # 'zflist-bin': '/opt/0-flist/zflist/zflist', ## You can specify a special userdata (list of users ## directories) and workdir (temporary directories where diff --git a/src/flist-uploader.py b/src/flist-uploader.py index 56880ce..28b5991 100644 --- a/src/flist-uploader.py +++ b/src/flist-uploader.py @@ -23,10 +23,16 @@ # theses location should works out-of-box if you use default settings # if not 'userdata-root-path' in config: - config['userdata-root-path'] = os.path.join(os.path.dirname(os.path.realpath(__file__)), "../public") + if os.path.exists("/.hub-container"): + config['userdata-root-path'] = "/public" + else: + config['userdata-root-path'] = os.path.join(os.path.dirname(os.path.realpath(__file__)), "../public") if not 'workdir-root-path' in config: - config['workdir-root-path'] = os.path.join(os.path.dirname(os.path.realpath(__file__)), "../workdir") + if os.path.exists("/.hub-container"): + config['workdir-root-path'] = "/workdir" + else: + config['workdir-root-path'] = os.path.join(os.path.dirname(os.path.realpath(__file__)), "../workdir") if not 'public-directory' in config: config['public-directory'] = os.path.join(config['userdata-root-path'], "users") @@ -46,12 +52,16 @@ if not 'authentication' in config: config['authentication'] = True -print("[+] user directory : %s" % config['userdata-root-path']) -print("[+] works directory : %s" % config['workdir-root-path']) -print("[+] upload directory: %s" % config['upload-directory']) -print("[+] flist creation : %s" % config['flist-work-directory']) -print("[+] docker creation : %s" % config['docker-work-directory']) -print("[+] public directory: %s" % config['public-directory']) +if not 'zflist-bin' in config and os.path.exists("/.hub-container"): + config['zflist-bin'] = '/usr/bin/zflist' + +print("[+] userdata directory: %s" % config['userdata-root-path']) +print("[+] workdir directory : %s" % config['workdir-root-path']) +print("[+] upload directory : %s" % config['upload-directory']) +print("[+] flist creation : %s" % config['flist-work-directory']) +print("[+] docker creation : %s" % config['docker-work-directory']) +print("[+] public directory : %s" % config['public-directory']) +print("[+] zflist binary path: %s" % config['zflist-bin']) checking = [ config['userdata-root-path'],