feat(updateImage): check version before downloading image
All checks were successful
Discord / discord commits (push) Has been skipped

This commit is contained in:
matt1432 2024-04-09 20:33:00 -04:00
parent 974d231027
commit b1162ce7a8

View file

@ -103,18 +103,25 @@ in {
runtimeInputs = [ runtimeInputs = [
(writeShellApplication { (writeShellApplication {
name = "pullImage"; name = "pullImage";
runtimeInputs = [nix-prefetch-docker]; runtimeInputs = [nix-prefetch-docker skopeo];
text = '' text = ''
FILE="$1" FILE="$1"
IMAGE=$(sed -n 's/.*imageName = "\([^"]*\).*/\1/p' "$FILE") IMAGE=$(sed -n 's/.*imageName = "\([^"]*\).*/\1/p' "$FILE")
TAG=$(sed -n 's/.*finalImageTag = "\([^"]*\).*/\1/p' "$FILE") TAG=$(sed -n 's/.*finalImageTag = "\([^"]*\).*/\1/p' "$FILE")
CURRENT_DIGEST=$(sed -n 's/.*imageDigest = "\([^"]*\).*/\1/p' "$FILE")
NEW_DIGEST=$(skopeo inspect "docker://$IMAGE:$TAG" | jq '.Digest' -r)
echo "$IMAGE $TAG" echo "$IMAGE $TAG"
if ! grep "Locked" "$FILE"; then if ! grep "Locked" "$FILE"; then
if [[ "$CURRENT_DIGEST" == "$NEW_DIGEST" ]]; then
echo "Already up-to-date"
else
PREFETCH=$(nix-prefetch-docker "$IMAGE" "$TAG") PREFETCH=$(nix-prefetch-docker "$IMAGE" "$TAG")
echo -e "pkgs:\npkgs.dockerTools.pullImage $PREFETCH" > "$FILE" echo -e "pkgs:\npkgs.dockerTools.pullImage $PREFETCH" > "$FILE"
fi fi
fi
''; '';
}) })
]; ];