Skip to content

Commit

Permalink
container: improve auto-configuration
Browse files Browse the repository at this point in the history
- Fix issue with /public and /workdir not working out-of-box
- Automatically set zflist-bin config if container special file detected
  • Loading branch information
maxux committed Jan 17, 2024
1 parent 6a6bcd5 commit 33d326f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
1 change: 1 addition & 0 deletions deployment/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/config.py.sample
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
26 changes: 18 additions & 8 deletions src/flist-uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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'],
Expand Down

0 comments on commit 33d326f

Please sign in to comment.