Last active
March 24, 2024 20:35
-
-
Save tgagor/fdd09a6938ceb3eefc56eeeaea30351f to your computer and use it in GitHub Desktop.
How old official Docker images are?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
CURRENT_TIMESTAMP=$(date +%s) | |
echo "Image | Creation date | Age (in days) | Packages to upgrade" | |
echo "---|---|---|---" | |
for i in centos:7 quay.io/centos/centos:centos7 quay.io/centos/centos:stream8 quay.io/centos/centos:stream9 \ | |
debian:10 debian:11 debian:12 \ | |
ubuntu:18.04 ubuntu:20.04 ubuntu:22.04 ubuntu:24.04 \ | |
alpine:3.17 alpine:3.18 alpine:3.19 \ | |
node:16 node:18 node:20 node:21 \ | |
openjdk:8 openjdk:11 openjdk:17 openjdk:21 \ | |
amazoncorretto:8 amazoncorretto:11 amazoncorretto:17 amazoncorretto:21 \ | |
eclipse-temurin:8 eclipse-temurin:11 eclipse-temurin:17 eclipse-temurin:21 ; | |
do | |
docker pull $i >/dev/null; | |
OUTPUT=$(docker inspect $i -f '{{ index .RepoTags 0 }} {{ .Created }}') | |
FORMAT_TIME=$(echo $OUTPUT | cut -f2 -d ' ' | xargs -I{} date +%s -d {} ) | |
for r in "$OUTPUT"; do | |
IMAGE_NAME=$(echo $r | cut -f1 -d ' ') | |
CREATION_DATE=$(echo $r | cut -f2 -d ' ') | |
CREATION_TIMESTAMP=$(date +%s -d $CREATION_DATE) | |
TIME_DIFF=$(( $CURRENT_TIMESTAMP - $CREATION_TIMESTAMP )) | |
TIME_DIFF_DAYS=$(( $TIME_DIFF / 86400)) | |
PACKAGES_TO_UPGRADE=$(docker run -ti --rm $i sh -c 'if command -v yum >/dev/null; then yum list updates -q | grep -v Updated | wc -l; elif command -v apt >/dev/null; then apt-get update -qq && apt list --upgradable 2>/dev/null | grep -vP "^List" | wc -l ; elif command -v apk >/dev/null; then apk --no-cache upgrade -s 2>/dev/null | grep -E "^\(" | wc -l; elif command -v microdnf >/dev/null; then microdnf upgrade --assumeno | grep "^ Upgrading:" | tr -s " " | cut -f3 -d " "; fi') | |
echo "$IMAGE_NAME | $(date +%Y-%m-%d -d $CREATION_DATE) | $TIME_DIFF_DAYS | $PACKAGES_TO_UPGRADE" | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment