From a214896fca177704998314c22fe6a57314c22827 Mon Sep 17 00:00:00 2001
From: Zen3515 <7106408+Zen3515@users.noreply.github.com>
Date: Tue, 31 Jan 2023 14:23:06 +0700
Subject: container: T4014: Add `command`, `arg` and `entrypoint` configuration
options for containers
(cherry picked from commit 53aebddb4ca54b0cc4a296d6cc4c4d960c5f1d73)
---
interface-definitions/container.xml.in | 27 +++++++++++++++++++++++++++
src/conf_mode/container.py | 21 ++++++++++++++++++---
2 files changed, 45 insertions(+), 3 deletions(-)
diff --git a/interface-definitions/container.xml.in b/interface-definitions/container.xml.in
index 1c971b58a..479f13355 100644
--- a/interface-definitions/container.xml.in
+++ b/interface-definitions/container.xml.in
@@ -104,11 +104,38 @@
+
+
+ Override the default ENTRYPOINT from the image
+
+ [ !#-%&(-~]+
+
+ Entrypoint must be ascii characters, use " and &apos for double and single quotes respectively
+
+
Image name in the hub-registry
+
+
+ Override the default CMD from the image
+
+ [ !#-%&(-~]+
+
+ Command must be ascii characters, use " and &apos for double and single quotes respectively
+
+
+
+
+ The command's arguments for this container
+
+ [ !#-%&(-~]+
+
+ The command's arguments must be ascii characters, use " and &apos for double and single quotes respectively
+
+
Memory (RAM) available to this container (default: 512)
diff --git a/src/conf_mode/container.py b/src/conf_mode/container.py
index 90e5f84f2..4f93c93a1 100755
--- a/src/conf_mode/container.py
+++ b/src/conf_mode/container.py
@@ -279,8 +279,22 @@ def generate_run_arguments(name, container_config):
f'--memory {memory}m --shm-size {shared_memory}m --memory-swap 0 --restart {restart} ' \
f'--name {name} {device} {port} {volume} {env_opt}'
+ entrypoint = ''
+ if 'entrypoint' in container_config:
+ # it needs to be json-formatted with single quote on the outside
+ entrypoint = json_write(container_config['entrypoint'].split()).replace('"', """)
+ entrypoint = f'--entrypoint '{entrypoint}''
+
+ command = ''
+ if 'command' in container_config:
+ command = container_config['command'].strip()
+
+ command_arguments = ''
+ if 'arguments' in container_config:
+ command_arguments = container_config['arguments'].strip()
+
if 'allow_host_networks' in container_config:
- return f'{container_base_cmd} --net host {image}'
+ return f'{container_base_cmd} --net host {entrypoint} {image} {command} {command_arguments}'.strip()
ip_param = ''
networks = ",".join(container_config['network'])
@@ -289,7 +303,7 @@ def generate_run_arguments(name, container_config):
address = container_config['network'][network]['address']
ip_param = f'--ip {address}'
- return f'{container_base_cmd} --net {networks} {ip_param} {image}'
+ return f'{container_base_cmd} --net {networks} {ip_param} {entrypoint} {image} {command} {command_arguments}'.strip()
def generate(container):
# bail out early - looks like removal from running config
@@ -341,7 +355,8 @@ def generate(container):
file_path = os.path.join(systemd_unit_path, f'vyos-container-{name}.service')
run_args = generate_run_arguments(name, container_config)
- render(file_path, 'container/systemd-unit.j2', {'name': name, 'run_args': run_args})
+ render(file_path, 'container/systemd-unit.j2', {'name': name, 'run_args': run_args,},
+ formater=lambda _: _.replace(""", '"').replace("'", "'"))
return None
--
cgit v1.2.3
From 4bcc364559beb0943a725ff6be737630ee78d527 Mon Sep 17 00:00:00 2001
From: Viacheslav Hletenko
Date: Tue, 28 Feb 2023 14:25:39 +0000
Subject: T4967: Allow setting container hostname
Ability setting container hostname
This host name is used as /etc/hostname
set container name host-name 'mybox'
(cherry picked from commit c68d73e6720a7df2b48df17ac7b9b4c906e0294c)
---
interface-definitions/container.xml.in | 9 +++++++++
src/conf_mode/container.py | 12 +++++++++++-
2 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/interface-definitions/container.xml.in b/interface-definitions/container.xml.in
index 479f13355..4614bc892 100644
--- a/interface-definitions/container.xml.in
+++ b/interface-definitions/container.xml.in
@@ -113,6 +113,15 @@
Entrypoint must be ascii characters, use " and &apos for double and single quotes respectively
+
+
+ Container host name
+
+ [A-Za-z0-9][-.A-Za-z0-9]*[A-Za-z0-9]
+
+ Host-name must be alphanumeric and can contain hyphens
+
+
Image name in the hub-registry
diff --git a/src/conf_mode/container.py b/src/conf_mode/container.py
index 4f93c93a1..10e9e9213 100755
--- a/src/conf_mode/container.py
+++ b/src/conf_mode/container.py
@@ -256,6 +256,11 @@ def generate_run_arguments(name, container_config):
for k, v in container_config['environment'].items():
env_opt += f" --env \"{k}={v['value']}\""
+ hostname = ''
+ if 'host_name' in container_config:
+ hostname = container_config['host_name']
+ hostname = f'--hostname {hostname}'
+
# Publish ports
port = ''
if 'port' in container_config:
@@ -277,7 +282,7 @@ def generate_run_arguments(name, container_config):
container_base_cmd = f'--detach --interactive --tty --replace {cap_add} ' \
f'--memory {memory}m --shm-size {shared_memory}m --memory-swap 0 --restart {restart} ' \
- f'--name {name} {device} {port} {volume} {env_opt}'
+ f'--name {name} {hostname} {device} {port} {volume} {env_opt}'
entrypoint = ''
if 'entrypoint' in container_config:
@@ -285,6 +290,11 @@ def generate_run_arguments(name, container_config):
entrypoint = json_write(container_config['entrypoint'].split()).replace('"', """)
entrypoint = f'--entrypoint '{entrypoint}''
+ hostname = ''
+ if 'host_name' in container_config:
+ hostname = container_config['host_name']
+ hostname = f'--hostname {hostname}'
+
command = ''
if 'command' in container_config:
command = container_config['command'].strip()
--
cgit v1.2.3
From 3fbe35c8ab0e5dc5fd7af1a5fc8b39e848655d36 Mon Sep 17 00:00:00 2001
From: Christian Breunig
Date: Tue, 28 Feb 2023 22:24:38 +0100
Subject: T4967: xml: provide re-usable constraint for CLI host-name
definitions
(cherry picked from commit d14a6814acb173cdc6df13212620f7da330434ed)
---
interface-definitions/container.xml.in | 2 +-
interface-definitions/dns-domain-name.xml.in | 2 +-
interface-definitions/include/constraint/host-name.xml.in | 3 +++
3 files changed, 5 insertions(+), 2 deletions(-)
create mode 100644 interface-definitions/include/constraint/host-name.xml.in
diff --git a/interface-definitions/container.xml.in b/interface-definitions/container.xml.in
index 4614bc892..91fb4dba0 100644
--- a/interface-definitions/container.xml.in
+++ b/interface-definitions/container.xml.in
@@ -117,7 +117,7 @@
Container host name
- [A-Za-z0-9][-.A-Za-z0-9]*[A-Za-z0-9]
+ #include
Host-name must be alphanumeric and can contain hyphens
diff --git a/interface-definitions/dns-domain-name.xml.in b/interface-definitions/dns-domain-name.xml.in
index a599a75cc..d77c94898 100644
--- a/interface-definitions/dns-domain-name.xml.in
+++ b/interface-definitions/dns-domain-name.xml.in
@@ -33,7 +33,7 @@
System host name (default: vyos)
- [A-Za-z0-9][-.A-Za-z0-9]*[A-Za-z0-9]
+ #include
diff --git a/interface-definitions/include/constraint/host-name.xml.in b/interface-definitions/include/constraint/host-name.xml.in
new file mode 100644
index 000000000..202c200f4
--- /dev/null
+++ b/interface-definitions/include/constraint/host-name.xml.in
@@ -0,0 +1,3 @@
+
+[A-Za-z0-9][-.A-Za-z0-9]*[A-Za-z0-9]
+
--
cgit v1.2.3