diff --git a/board/common/rootfs/usr/sbin/container b/board/common/rootfs/usr/sbin/container index f7e47d77..b90fb4b9 100755 --- a/board/common/rootfs/usr/sbin/container +++ b/board/common/rootfs/usr/sbin/container @@ -1,6 +1,7 @@ #!/bin/sh all="" +env="" port="" log() @@ -45,9 +46,10 @@ create() fi # --syslog --log-level info - log "Calling \"podman create --name $name --conmon-pidfile=$pidfn $network $port $args $image\"" - if podman create --name "$name" --conmon-pidfile="$pidfn" $network $port $args "$image"; then + log "Calling \"podman create --name $name --conmon-pidfile=$pidfn $env $network $port $args $image\"" + if podman create --name "$name" --conmon-pidfile="$pidfn" $env $network $port $args "$image"; then log "Successfully created container $name from $image" + rm "/run/containers/env/${name}.env" initctl show "container:$name" |grep -q manual:yes || initctl -bq start "container:$name" initctl -nbq cond set container:$name exit 0 @@ -82,6 +84,7 @@ options: -a, --all Show all, of something --dns NAMESERVER Set nameserver(s) when creating a container --dns-search LIST Set host lookup search list when creating container + -e, --env FILE Environment variables when creating container -f, --force Force operation, e.g. remove -h, --help Show this help text -p, --publish PORT Publish ports when creating container @@ -115,6 +118,10 @@ while [ "$1" != "" ]; do shift search="$search $1" ;; + -e | --env) + shift + env="$env --env-file=$1" + ;; -f | --force) force="-f" ;; diff --git a/package/execd/tmpfiles.conf b/package/execd/tmpfiles.conf index 286e791b..48aae29b 100644 --- a/package/execd/tmpfiles.conf +++ b/package/execd/tmpfiles.conf @@ -1,5 +1,6 @@ +d /run/containers/env 0700 - - +d /run/containers/done 0700 - - d /run/containers/inbox 0700 - - d /run/containers/queue 0700 - - -d /run/containers/done 0700 - - d /run/cni 0755 - - L+ /var/lib/cni - - - - /run/cni diff --git a/src/confd/src/infix-containers.c b/src/confd/src/infix-containers.c index 7edeae1c..4484b256 100644 --- a/src/confd/src/infix-containers.c +++ b/src/confd/src/infix-containers.c @@ -31,8 +31,8 @@ static int add(const char *name, struct lyd_node *cif) const char *image = lydx_get_cattr(cif, "image"); const char *restart_policy; struct lyd_node *node; + FILE *fp, *ep = NULL; char *restart = ""; /* Default restart:10 */ - FILE *fp; fp = fopenf("w", "%s/%s.sh", INBOX_QUEUE, name); if (!fp) { @@ -55,6 +55,16 @@ static int add(const char *name, struct lyd_node *cif) LYX_LIST_FOR_EACH(lyd_child(cif), node, "publish") fprintf(fp, " -p %s", lyd_get_value(node)); + LYX_LIST_FOR_EACH(lyd_child(cif), node, "env") { + if (!ep) + ep = fopenf("w", "/run/containers/env/%s.env", name); + fprintf(ep, "%s=%s\n", lydx_get_cattr(node, "key"), lydx_get_cattr(node, "value")); + } + if (ep) { + fclose(ep); + fprintf(fp, " -e /run/containers/env/%s.env", name); + } + fprintf(fp, " create %s %s", name, image); LYX_LIST_FOR_EACH(lyd_child(cif), node, "network") { diff --git a/src/confd/yang/infix-containers@2023-12-14.yang b/src/confd/yang/infix-containers@2023-12-14.yang index 89320fcf..5a11e87c 100644 --- a/src/confd/yang/infix-containers@2023-12-14.yang +++ b/src/confd/yang/infix-containers@2023-12-14.yang @@ -67,6 +67,22 @@ module infix-containers { default true; } + list env { + description "Set environment variables, key=\"value\" pairs."; + key key; + + leaf key { + description "Single word, [A-Za-z_]"; + type string; + } + + leaf value { + description "Argument to key can be a single word or quoted multiple words."; + mandatory true; + type string; + } + } + leaf image { description "Docker image used for the container"; mandatory true;