mirror of
https://github.com/kernelkit/infix.git
synced 2026-07-30 20:43:02 +02:00
confd: add support for upgrading container images
This patch adds a new CLI command 'container upgrade foo', where 'foo' is the name of the container. If more than one container use the same image, multiple upgrades must be done because a container runs not on the 'image:tag' but on the hash of the 'image:tag' it was created from. Rename "done" queue to "active", since we want to recreate an active container after fetching an updated base image. Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
@@ -246,6 +246,17 @@ case $cmd in
|
||||
stop)
|
||||
initctl -bq stop "container:$1" || podman kill "$1"
|
||||
;;
|
||||
upgrade)
|
||||
img=$(podman inspect "$1" | jq -r .[].ImageName)
|
||||
if [ -z "$img" ]; then
|
||||
echo "No such container ($1), or invalid ImageName. Cannot upgrade."
|
||||
exit 1;
|
||||
fi
|
||||
podman stop "$1"
|
||||
podman pull "$img" || (echo "Failed fetching $img, check your network (settings)."; exit 1)
|
||||
"/var/lib/containers/active/${1}.sh" || (echo "Failed recreating container $1"; exit 1)
|
||||
echo "Container $1 recreated, restart with 'container start $1'"
|
||||
;;
|
||||
volume)
|
||||
cmd=$1
|
||||
shift
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
service log:prio:local1.err,tag:container \
|
||||
[2345] execd /run/containers/queue /var/lib/containers/done -- Container job runner
|
||||
[2345] execd /run/containers/queue /var/lib/containers/active -- Container job runner
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
d /run/containers/args 0700 - -
|
||||
d /var/lib/containers/done 0700 - -
|
||||
d /var/lib/containers/active 0700 - -
|
||||
d /run/containers/inbox 0700 - -
|
||||
d /run/containers/queue 0700 - -
|
||||
d /run/cni 0755 - -
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
#define CFG_XPATH "/infix-containers:container"
|
||||
#define INBOX_QUEUE "/run/containers/inbox"
|
||||
#define JOB_QUEUE "/run/containers/queue"
|
||||
#define DONE_QUEUE "/var/lib/containers/done"
|
||||
#define ACTIVE_QUEUE "/var/lib/containers/active"
|
||||
#define LOGGER "logger -t container -p local1.notice"
|
||||
|
||||
static const struct srx_module_requirement reqs[] = {
|
||||
@@ -231,13 +231,13 @@ void infix_containers_launch(void)
|
||||
}
|
||||
|
||||
while ((d = readdir(dir))) {
|
||||
char curr[strlen(ACTIVE_QUEUE) + strlen(d->d_name) + 2];
|
||||
char next[strlen(INBOX_QUEUE) + strlen(d->d_name) + 2];
|
||||
char curr[strlen(DONE_QUEUE) + strlen(d->d_name) + 2];
|
||||
|
||||
snprintf(curr, sizeof(curr), "%s/%s", ACTIVE_QUEUE, d->d_name);
|
||||
snprintf(next, sizeof(next), "%s/%s", INBOX_QUEUE, d->d_name);
|
||||
snprintf(curr, sizeof(curr), "%s/%s", DONE_QUEUE, d->d_name);
|
||||
if (!systemf("cmp %s %s", curr, next)) {
|
||||
ERRNO("New job %s is already done, no changes, skipping.", next);
|
||||
ERRNO("New job %s is already active, no changes, skipping.", next);
|
||||
systemf("initctl -nbq cond set container:$(basename %s .sh)", d->d_name);
|
||||
remove(next);
|
||||
continue;
|
||||
|
||||
@@ -245,6 +245,13 @@
|
||||
<PARAM name="name" ptype="/CONTAINERS" help="Container name" />
|
||||
<ACTION sym="script" out="tty" interrupt="true">container stop $KLISH_PARAM_name</ACTION>
|
||||
</COMMAND>
|
||||
|
||||
<COMMAND name="upgrade" help="Upgrade image of a container (writable layer is lost!)">
|
||||
<PARAM name="name" ptype="/CONTAINERS" help="Container name" />
|
||||
<ACTION sym="script" out="tty" interrupt="true">
|
||||
container upgrade $KLISH_PARAM_name
|
||||
</ACTION>
|
||||
</COMMAND>
|
||||
</COMMAND>
|
||||
|
||||
<COMMAND name="copy" help="Copy configuration, e.g., copy running-config startup-config">
|
||||
|
||||
Reference in New Issue
Block a user