mirror of
https://github.com/kernelkit/infix.git
synced 2026-08-01 13:23:01 +02:00
confd: add support for container environment variables
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
@@ -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"
|
||||
;;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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") {
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user