mirror of
https://github.com/kernelkit/infix.git
synced 2026-07-29 20:23:01 +02:00
board/common: container not restarting on env variable changes
Environment variables are stored in a separate .env file from the main container script. The config SHA256 checksum only covered the script file, so changes to env vars went undetected -- the container was not recreated and kept running with stale values. Include the env file contents in the config checksum calculation so that any change to environment variables triggers a proper container restart. Fixes #1313 Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
@@ -63,6 +63,21 @@ calc_sha()
|
||||
sha256sum "$1" 2>/dev/null | awk '{print $1}'
|
||||
}
|
||||
|
||||
# Calculate a combined SHA256 over the container script and its
|
||||
# optional env file. Environment variables are stored separately
|
||||
# from the script, so both must be included in the checksum to
|
||||
# detect configuration changes such as added/changed env vars.
|
||||
calc_config_sha()
|
||||
{
|
||||
_envfile="/run/containers/args/${name}.env"
|
||||
|
||||
if [ -f "$_envfile" ]; then
|
||||
cat "$1" "$_envfile" | sha256sum | awk '{print $1}'
|
||||
else
|
||||
calc_sha "$1"
|
||||
fi
|
||||
}
|
||||
|
||||
# Check image transport, return 0 if remote, 1 if local
|
||||
is_remote()
|
||||
{
|
||||
@@ -124,7 +139,7 @@ is_uptodate()
|
||||
# If SHA matches, check container instance
|
||||
if [ "$stored_sha" = "$current_sha" ]; then
|
||||
if podman container exists "$name"; then
|
||||
config_sha=$(calc_sha "$script")
|
||||
config_sha=$(calc_config_sha "$script")
|
||||
container_sha=$(podman inspect "$name" --format '{{index .Config.Labels "config-sha256"}}' 2>/dev/null)
|
||||
container_img_sha=$(podman inspect "$name" --format '{{index .Config.Labels "meta-image-sha256"}}' 2>/dev/null)
|
||||
|
||||
@@ -143,7 +158,7 @@ is_uptodate()
|
||||
else
|
||||
# Remote image optimization: check config-sha256 only
|
||||
if podman container exists "$name"; then
|
||||
config_sha=$(calc_sha "$script")
|
||||
config_sha=$(calc_config_sha "$script")
|
||||
container_sha=$(podman inspect "$name" --format '{{index .Config.Labels "config-sha256"}}' 2>/dev/null)
|
||||
|
||||
if [ "$container_sha" = "$config_sha" ]; then
|
||||
@@ -459,7 +474,7 @@ create()
|
||||
fi
|
||||
|
||||
# Add config checksum label
|
||||
args="$args --label config-sha256=$(calc_sha "$script")"
|
||||
args="$args --label config-sha256=$(calc_config_sha "$script")"
|
||||
fi
|
||||
|
||||
# shellcheck disable=SC2048
|
||||
|
||||
Reference in New Issue
Block a user