Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions board/common/rootfs/usr/sbin/container
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -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)

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions doc/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ Noteworthy changes and additions in this release are marked below in bold text.
similar to IPv4, correctly mapping to the ietf-ip.yang model semantics
- Fix #1082: Wi-Fi interfaces always scanned, introduce a `scan-mode` to the
Wi-Fi concept in Infix
- Fix #1313: Container is not restarted if environment variable is changed
- Fix #1314: Raspberry Pi 4B with 1 or 8 GiB RAM does not boot. This was due
newer EEPROM firmware in newer boards require a newer rpi-firmware package
- Fix #1345: firewall not updating when interfaces become bridge/lag ports
Expand Down
1 change: 1 addition & 0 deletions doc/cli/keybindings.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ CLI has several keybindings, most significant first:
| Ctrl-q | Ctrl-v | Insert next character literally |
| Ctrl-r | | History, reversed interactive search (i-search) |
| Ctrl-t | | Transpose/Swap characters before and at cursor |
| Meta-# | Alt-Shift-3 | Prepend # to current line and submit to history |

## What is Meta?

Expand Down
2 changes: 1 addition & 1 deletion package/klish/klish.hash
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Locally calculated
sha256 9d9d33b873917ca5d0bdcc47a36d2fd385971ab0c045d1472fcadf95ee5bcf5b LICENCE
sha256 39a73fdaa7e41001e804e2bbdebdc885da79d540f0246777e8fd1c0dd9fc9475 klish-1c31f50ab775d467fa18f2e0a798006949536a2a-git4.tar.gz
sha256 cd9bc969350b8b30d9a7a31b0f19fb3218c602f04fe7e6a1d80682a75ed26d18 klish-3ae496c43d90354ffa94d364d7775c089f0e119a-git4.tar.gz
2 changes: 1 addition & 1 deletion package/klish/klish.mk
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
################################################################################

KLISH_VERSION = 1c31f50ab775d467fa18f2e0a798006949536a2a
KLISH_VERSION = 3ae496c43d90354ffa94d364d7775c089f0e119a
KLISH_SITE = https://github.com/kernelkit/klish.git
#KLISH_VERSION = tags/3.0.0
#KLISH_SITE = https://src.libcode.org/pkun/klish.git
Expand Down
6 changes: 5 additions & 1 deletion test/case/containers/environment/test.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ ifdef::topdoc[:imagesdir: {topdoc}../../test/case/containers/environment]
==== Description

Verify that environment variables can be set in container configuration
and are available inside the running container.
and are available inside the running container. Also verify that
changing an environment variable triggers a container restart.

1 Set up a container config with multiple environment variables
2. Serve variables back to host using a CGI script in container
3. Verify served content against environment variables
4. Change an environment variable and verify the container restarts

==== Topology

Expand All @@ -23,5 +25,7 @@ image::topology.svg[Container environment variables topology, align=center, scal
. Verify container has started
. Verify basic connectivity to data interface
. Verify environment variables in CGI response
. Change environment variable and verify container restarts
. Verify container has restarted with updated env


24 changes: 23 additions & 1 deletion test/case/containers/environment/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
Container environment variables

Verify that environment variables can be set in container configuration
and are available inside the running container.
and are available inside the running container. Also verify that
changing an environment variable triggers a container restart.

1 Set up a container config with multiple environment variables
2. Serve variables back to host using a CGI script in container
3. Verify served content against environment variables
4. Change an environment variable and verify the container restarts
"""
import infamy
from infamy.util import until, to_binary, curl
Expand Down Expand Up @@ -105,4 +107,24 @@

until(lambda: all(string in ns.call(lambda: curl(URL)) for string in expected_strings))

with test.step("Change environment variable and verify container restarts"):
UPDATED_ENV_VARS = [
{"key": "TEST_VAR", "value": "updated-value"},
{"key": "APP_PORT", "value": "8080"},
{"key": "DEBUG_MODE", "value": "true"},
{"key": "PATH_WITH_SPACES", "value": "/path with spaces/test"}
]

target.put_config_dict("infix-containers", {
"containers": {
"container": [{
"name": f"{NAME}",
"env": UPDATED_ENV_VARS,
}]
}
})

with test.step("Verify container has restarted with updated env"):
until(lambda: "TEST_VAR=updated-value" in ns.call(lambda: curl(URL)), attempts=60)

test.succeed()
Loading