confd: add support for custom container ENTRYPOINT

This was a tough nut to crack.  Turns out the trick to changing the
ENTRYPOINT is to set --entrypoint=command and then call 'podman create
... command args'.  Not entirely obvious since the documented approach
is to use a JSON array as the argument: podman create
--entrypoint='["command", "args" ]'.

Admittedly, encoding this in C to transfer it via a POSIX shell script
to the command line, is not the easiest task I've undertaken.  So I gave
up and found this workaround.

Worth noting, however, is that one *must* set `--entrypoint`, it is not
enough to just append the command to the 'podman create' command line.
Due to differences in docker and podman, we cannot supply the full args
to an alternate entrypoint command.  But for the command to actually run
we need to override the image's ENTRYPOINT and send the command and args
as the last arguments on the command line to podman create.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2024-02-25 19:49:27 +01:00
parent f1bf02eda5
commit d8dde9cde2
3 changed files with 18 additions and 2 deletions
+7 -2
View File
@@ -43,9 +43,10 @@ create()
fi
# --syslog --log-level info
log "Calling \"podman create --name $name --conmon-pidfile=$pidfn $hostname $env $network $port $args $image\""
log "Calling \"podman create --name $name --conmon-pidfile=$pidfn $hostname $entrypoint $env $network $port $args $image $*\""
set -x
if podman create --name "$name" --conmon-pidfile="$pidfn" $hostname $env $network $port $args "$image"; then
# shellcheck disable=SC2048
if podman create --name "$name" --conmon-pidfile="$pidfn" $hostname $entrypoint $env $network $port $args "$image" $*; then
log "Successfully created container $name from $image"
rm -f "/run/containers/env/${name}.env"
initctl show "container:$name" |grep -q manual:yes || initctl -bq start "container:$name"
@@ -83,6 +84,7 @@ options:
--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
--entrypoint Disable container image's ENTRYPOINT, run cmd + arg
-f, --force Force operation, e.g. remove
-h, --help Show this help text
--hostname NAME Set hostname when creating container
@@ -122,6 +124,9 @@ while [ "$1" != "" ]; do
shift
env="$env --env-file=$1"
;;
--entrypoint)
entrypoint="--entrypoint=\"\""
;;
-f | --force)
force="-f"
;;
+6
View File
@@ -86,8 +86,14 @@ static int add(const char *name, struct lyd_node *cif)
if (lydx_is_enabled(cif, "host-network"))
fprintf(fp, " --net host");
if ((string = lydx_get_cattr(cif, "entrypoint")))
fprintf(fp, " --entrypoint");
fprintf(fp, " create %s %s", name, image);
if ((string = lydx_get_cattr(cif, "entrypoint")))
fprintf(fp, " %s", string);
fprintf(fp, "\n");
fchmod(fileno(fp), 0700);
fclose(fp);
@@ -83,6 +83,11 @@ module infix-containers {
}
}
leaf entrypoint {
description "Override the default ENTRYPOINT from the image.";
type string;
}
leaf hostname {
description "Sets the container host name that is available inside the container.";
type inet:domain-name;