Skip to content

Commit 42228d4

Browse files
committed
Add service name and description
1 parent 35546bd commit 42228d4

File tree

1 file changed

+25
-15
lines changed

1 file changed

+25
-15
lines changed

stepup/version-info.sh

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,47 +13,57 @@ if [ -z "$running" ]; then
1313
exit 1
1414
fi
1515

16-
# Use docker compose ps with JSON output to get the image and labels of the running containers
17-
image_list=$(docker compose -p stepup -f "${DIR}/docker-compose.yml" ps --format json | jq -s 'sort_by(.Image) | .[] | .Image,.Labels')
16+
# Use docker compose ps with JSON output to get the image, service name and labels of the running containers
17+
image_list=$(docker compose -p stepup -f "${DIR}/docker-compose.yml" ps --format json | jq -s 'sort_by(.Service) | .[] | .Image,.Service,.Labels')
1818

19-
# image_list is text lines with image and labels alternating:
19+
# image_list is text lines with service, image and labels alternating:
2020
# "image1"
21+
# "service1"
2122
# "labels1_1=value1_1,labels1_2=value1_2, ..."
2223
# "image2"
24+
# "service2"
2325
# "labels2_1=value2_1,labels2_2=value2_2, ..."
2426
# ...
25-
# Get the image name and the value for the "opencontainers.image.version" label
2627

2728
# Table header
28-
printf "%-10s %-21s %-13s %s\n" "Git SHA-1" "Build date" "Version" "Image"
29+
printf "%-12s %-20s %-10s %-21s %-13s %s\n" "Service" "Title" "Git SHA-1" "Build date" "Version" "Image"
2930

3031
# process the image_list
3132
while read -r image; do
32-
# Remove the quotes
33-
image=$(echo $image | tr -d '"')
33+
image=$(echo "${image}" | tr -d '"') # Remove the quotes
34+
35+
read -r service
36+
service=$(echo "${service}" | tr -d '"') # Remove the quotes
37+
3438
read -r labels
35-
# Remove the quotes and split the labels into an array by the comma, do not split on whitespace
36-
labels=$(echo $labels | tr -d '"')
39+
# Remove the quotes and split the labels into an array by comma
40+
labels=$(echo "${labels}" | tr -d '"')
3741
IFS=',' read -r -a label_array <<< "$labels"
3842

43+
title="-" # Image title (org.opencontainers.image.title)
3944
version="-" # Version (git tag) of the image
4045
date="-" # Date and time the image was created
4146
commit="-" # Git SHA-1 commit hash of the source code used to build the image
4247
# Find the label with the key "org.opencontainers.image.version"
4348
for label in "${label_array[@]}"; do
44-
key=$(echo $label | cut -d= -f1)
49+
key=$(echo "${label}" | cut -d= -f1)
50+
if [ "$key" == "org.opencontainers.image.title" ]; then
51+
value=$(echo "${label}" | cut -d= -f2)
52+
title=$value
53+
fi
4554
if [ "$key" == "org.opencontainers.image.revision" ]; then
46-
value=$(echo $label | cut -d= -f2)
55+
value=$(echo "${label}" | cut -d= -f2)
4756
commit=$value
4857
fi
4958
if [ "$key" == "org.opencontainers.image.version" ]; then
50-
value=$(echo $label | cut -d= -f2)
59+
value=$(echo "${label}" | cut -d= -f2)
5160
version=$value
5261
fi
5362
if [ "$key" == "org.opencontainers.image.created" ]; then
54-
value=$(echo $label | cut -d= -f2)
55-
date=$value
63+
value=$(echo "${label}" | cut -d= -f2)
64+
# Date is formatted in ISO, convert to local timezone
65+
date=$(date -j -f "%Y-%m-%dT%H:%M:%S" "${value}Z" "+%Y-%m-%d %H:%M:%S" 2>/dev/null || date -d "${value}Z" "+%Y-%m-%d %H:%M:%S" 2>/dev/null || echo "$value")
5666
fi
5767
done
58-
printf "%-10s %-21s %-13s %s\n" "${commit:0:6}" "${date:0:19}" "$version" "$image"
68+
printf "%-12s %-20s %-10s %-21s %-13s %s\n" "${service:0:12}" "${title:0:19}" "${commit:0:6}" "${date:0:19}" "$version" "$image"
5969
done <<< "$image_list"

0 commit comments

Comments
 (0)