Skip to content
Snippets Groups Projects
Commit 4ff63b9757b6 authored by Georges Racinet's avatar Georges Racinet :squid:
Browse files

launch: using the configuration file to choose between podamn and docker

parent 1a82dc61c279
No related branches found
No related tags found
No related merge requests found
Pipeline #101675 failed
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
import re import re
import subprocess import subprocess
import tarfile import tarfile
import tomllib # available in Python≥3.11
HOME = os.environ['HOME'] HOME = os.environ['HOME']
# ! Docker context directory for the *heptapod-dev* image! # ! Docker context directory for the *heptapod-dev* image!
...@@ -94,6 +95,9 @@ ...@@ -94,6 +95,9 @@
parser.add_argument('-s', '--simulate', action='store_true', parser.add_argument('-s', '--simulate', action='store_true',
help="Output configuration instead of " help="Output configuration instead of "
"executing commands") "executing commands")
parser.add_argument('--config',
help="Path to configuration file (TOML)",
default='config.toml')
vol_group = parser.add_argument_group("Docker volumes options") vol_group = parser.add_argument_group("Docker volumes options")
vol_group.add_argument('--volumes-dir', vol_group.add_argument('--volumes-dir',
help="Base directory for the three standard " help="Base directory for the three standard "
...@@ -125,7 +129,8 @@ ...@@ -125,7 +129,8 @@
run_group.add_argument('--http-port', type=int, default=8081) run_group.add_argument('--http-port', type=int, default=8081)
run_group.add_argument('--ssh-port', type=int, default=2022) run_group.add_argument('--ssh-port', type=int, default=2022)
run_group.add_argument('--container-name', default='heptapod') run_group.add_argument('--container-name', default='heptapod')
run_group.add_argument('--podman', action="store_true") run_group.add_argument('--driver',
help="docker or podman, defaults to config file")
run_group.add_argument('--root-password', default='5iveL!fe', run_group.add_argument('--root-password', default='5iveL!fe',
help="Force the value of root password in " help="Force the value of root password in "
"the Heptapod instance. By default, is the " "the Heptapod instance. By default, is the "
...@@ -145,6 +150,13 @@ ...@@ -145,6 +150,13 @@
"container if already present") "container if already present")
parsed_args = parser.parse_args() parsed_args = parser.parse_args()
if os.path.exists(parsed_args.config):
with open(parsed_args.config, 'rb') as fobj:
config = tomllib.load(fobj)
else:
config = {}
common_config = config.get('common', {})
simulate = parsed_args.simulate simulate = parsed_args.simulate
volumes_dir = get_volumes_dir(parsed_args, parser) volumes_dir = get_volumes_dir(parsed_args, parser)
...@@ -155,6 +167,5 @@ ...@@ -155,6 +167,5 @@
image_tag = parsed_args.image_tag image_tag = parsed_args.image_tag
run_image_tag = image_tag run_image_tag = image_tag
podman = bool(parsed_args.podman)
pull = not bool(parsed_args.no_pull) pull = not bool(parsed_args.no_pull)
...@@ -159,6 +170,9 @@ ...@@ -159,6 +170,9 @@
pull = not bool(parsed_args.no_pull) pull = not bool(parsed_args.no_pull)
docker = 'podman' if podman else 'docker' docker = parsed_args.driver
if docker is None:
docker = common_config.get('driver', 'docker')
is_podman = docker == 'podman'
full_image_tag = f'{parsed_args.image_repo}:{run_image_tag}' full_image_tag = f'{parsed_args.image_repo}:{run_image_tag}'
...@@ -207,7 +221,7 @@ ...@@ -207,7 +221,7 @@
print() print()
if pull: if pull:
subprocess.check_call(pull_cmd) subprocess.check_call(pull_cmd)
if podman: if is_podman:
ensure_volumes(bind_mounts) ensure_volumes(bind_mounts)
subprocess.check_call(run_cmd) subprocess.check_call(run_cmd)
print() print()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment