addet new docker update function
This commit is contained in:
parent
bb3deb719d
commit
ec82414987
2 changed files with 40 additions and 4 deletions
1
.zsh/themes
Submodule
1
.zsh/themes
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit 9a6accbb320abd6eeafe391cf68abc99ed726ec2
|
43
.zshrc
43
.zshrc
|
@ -174,14 +174,49 @@ __docker__() {
|
|||
alias dl="docker compose logs -f"
|
||||
alias dc="docker compose"
|
||||
check_for_updates() {
|
||||
# Check for required dependencies
|
||||
if ! command -v jq &>/dev/null; then
|
||||
echo -e "${RED}Error: jq is required but not installed. Please install jq.${NC}"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if ! docker compose version &>/dev/null; then
|
||||
echo -e "${RED}Error: docker compose is not available.${NC}"
|
||||
return 1
|
||||
fi
|
||||
|
||||
local updated=false
|
||||
local images=$(docker compose config | grep 'image:' | awk '{print $2}')
|
||||
local images
|
||||
images=$(docker compose config --format json | jq -r '.services[] | .image' 2>/dev/null)
|
||||
|
||||
if [[ -z "$images" ]]; then
|
||||
echo -e "${RED}Error: No Docker images found in the compose configuration.${NC}"
|
||||
return 1
|
||||
fi
|
||||
|
||||
for image in $images; do
|
||||
echo -e "${CYAN}Checking for updates for image: ${YELLOW}$image${NC}"
|
||||
local local_digest=$(docker image inspect "$image" --format '{{index .RepoDigests 0}}' 2>/dev/null)
|
||||
local remote_digest=$(docker pull --quiet --dry-run "$image" 2>/dev/null | grep 'Digest:' | awk '{print $2}')
|
||||
|
||||
# Get local image digest
|
||||
local local_digest
|
||||
local_digest=$(docker image inspect "$image" --format '{{index .RepoDigests 0}}' 2>/dev/null)
|
||||
|
||||
if [[ -z "$local_digest" ]]; then
|
||||
echo -e "${YELLOW}Image not present or digest unavailable. Update needed.${NC}"
|
||||
updated=true
|
||||
continue
|
||||
fi
|
||||
|
||||
# Get remote image digest using manifest inspect
|
||||
local remote_digest
|
||||
remote_digest=$(DOCKER_CLI_EXPERIMENTAL=enabled docker manifest inspect -v "$image" 2>/dev/null | jq -r '.Descriptor.digest' 2>/dev/null)
|
||||
|
||||
if [[ -z "$remote_digest" ]]; then
|
||||
echo -e "${RED}Failed to retrieve remote digest. Skipping.${NC}"
|
||||
continue
|
||||
fi
|
||||
|
||||
# Compare digests
|
||||
if [[ "$local_digest" != "$remote_digest" ]]; then
|
||||
echo -e "${GREEN}Update available for $image${NC}"
|
||||
updated=true
|
||||
|
@ -192,7 +227,7 @@ __docker__() {
|
|||
|
||||
if $updated; then
|
||||
echo -e "${CYAN}Pulling updates and recreating containers...${NC}"
|
||||
docker compose pull && docker compose up -d --force-recreate
|
||||
docker compose pull --quiet && docker compose up -d --force-recreate
|
||||
else
|
||||
echo -e "${GREEN}All images are up to date. No action needed.${NC}"
|
||||
fi
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue