add container update script
This commit is contained in:
parent
a9dc71ffb7
commit
4f41394763
1 changed files with 47 additions and 1 deletions
|
|
@ -1,5 +1,47 @@
|
||||||
{ config, pkgs, lib, ... }:
|
{ config, pkgs, lib, ... }:
|
||||||
|
|
||||||
|
let
|
||||||
|
# System-wide script for updating containers (works with sudo)
|
||||||
|
update-containers-script = pkgs.writeShellScriptBin "update-containers" ''
|
||||||
|
echo "Scanning running containers..."
|
||||||
|
containers=$(podman ps --format "{{.Names}}")
|
||||||
|
|
||||||
|
if [[ -z "$containers" ]]; then
|
||||||
|
echo "No running containers found."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
for container in $containers; do
|
||||||
|
echo "=================================================="
|
||||||
|
echo "Processing container: $container"
|
||||||
|
|
||||||
|
# Get the image used by this container
|
||||||
|
image=$(podman inspect "$container" --format "{{.ImageName}}")
|
||||||
|
echo "Current image: $image"
|
||||||
|
|
||||||
|
# Pull the latest version of the image
|
||||||
|
echo "Pulling latest version of $image..."
|
||||||
|
if podman pull "$image"; then
|
||||||
|
# Check if the image was updated by comparing IDs
|
||||||
|
old_id=$(podman inspect "$container" --format "{{.Image}}")
|
||||||
|
new_id=$(podman inspect "$image" --format "{{.Id}}")
|
||||||
|
|
||||||
|
if [[ "$old_id" != "$new_id" ]]; then
|
||||||
|
echo "New version available! Restarting container..."
|
||||||
|
podman restart "$container"
|
||||||
|
echo "Container $container restarted with new image"
|
||||||
|
else
|
||||||
|
echo "Container $container is already using the latest image"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "Failed to pull image for $container"
|
||||||
|
fi
|
||||||
|
echo ""
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "Container update scan complete!"
|
||||||
|
'';
|
||||||
|
in
|
||||||
{
|
{
|
||||||
# Container virtualization with Podman
|
# Container virtualization with Podman
|
||||||
virtualisation = {
|
virtualisation = {
|
||||||
|
|
@ -19,4 +61,8 @@
|
||||||
# and will be merged with this base configuration
|
# and will be merged with this base configuration
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
# Make update-containers available system-wide (works with sudo)
|
||||||
|
environment.systemPackages = [ update-containers-script ];
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue