mirror of
https://github.com/mag37/dockcheck.git
synced 2026-04-18 02:17:46 +00:00
Compare commits
2 Commits
v0.7.5
...
log_digest
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
37575cad98 | ||
|
|
4e0b705b8b |
34
dockcheck.sh
34
dockcheck.sh
@@ -582,6 +582,25 @@ if [[ -n "${GotUpdates:-}" ]]; then
|
||||
|
||||
NumberofUpdates="${#SelectedUpdates[@]}"
|
||||
|
||||
# TODO: move this to proper place + setup optarg etc.
|
||||
# Digest log setup
|
||||
LogDigestChanges="true"
|
||||
LogPath="$ScriptWorkDir/updatelog"
|
||||
if [[ -n "${LogDigestChanges}" ]]; then
|
||||
LogStore=()
|
||||
LogStore+=("$(printf "%-30s %s > %s\n" "IMAGE:TAG" "OLD DIGEST" "NEW DIGEST")")
|
||||
fi
|
||||
|
||||
# TODO: move this to proper place
|
||||
get_image_facts(){
|
||||
ImageConfig=$(docker image inspect "$ImageId" --format '{{ json . }}')
|
||||
ContRepoDigests=$($jqbin -r '.RepoDigests[0]' <<< "$ImageConfig")
|
||||
[[ "$ContRepoDigests" == "null" ]] && ContRepoDigests=""
|
||||
ContRepo=${ContImage%:*}
|
||||
ContApp=${ContRepo#*/}
|
||||
[[ "$ContImage" =~ ":" ]] && ContTag=${ContImage#*:} || ContTag="latest"
|
||||
}
|
||||
|
||||
CurrentQue=0
|
||||
for i in "${SelectedUpdates[@]}"; do
|
||||
((CurrentQue+=1))
|
||||
@@ -592,19 +611,17 @@ if [[ -n "${GotUpdates:-}" ]]; then
|
||||
ContPath=$($jqbin -r '."Config"."Labels"."com.docker.compose.project.working_dir"' <<< "$ContConfig")
|
||||
[[ "$ContPath" == "null" ]] && ContPath=""
|
||||
|
||||
|
||||
# Add new backup tag prior to pulling if option is set
|
||||
if [[ -n "${BackupForDays:-}" ]]; then
|
||||
ImageConfig=$(docker image inspect "$ImageId" --format '{{ json . }}')
|
||||
ContRepoDigests=$($jqbin -r '.RepoDigests[0]' <<< "$ImageConfig")
|
||||
[[ "$ContRepoDigests" == "null" ]] && ContRepoDigests=""
|
||||
ContRepo=${ContImage%:*}
|
||||
ContApp=${ContRepo#*/}
|
||||
[[ "$ContImage" =~ ":" ]] && ContTag=${ContImage#*:} || ContTag="latest"
|
||||
get_image_facts
|
||||
BackupName="dockcheck/${ContApp}:${RunTimestamp}_${ContTag}"
|
||||
docker tag "$ImageId" "$BackupName"
|
||||
printf "%b%s backed up as %s%b\n" "$c_teal" "$i" "$BackupName" "$c_reset"
|
||||
fi
|
||||
|
||||
[[ -n "${LogDigestChanges}" ]] && get_image_facts
|
||||
|
||||
# Checking if compose-values are empty - hence started with docker run
|
||||
if [[ -z "$ContPath" ]]; then
|
||||
if [[ "$DRunUp" == true ]]; then
|
||||
@@ -619,12 +636,17 @@ if [[ -n "${GotUpdates:-}" ]]; then
|
||||
if docker pull "$ContImage"; then
|
||||
# Removal of the <none>-tag image left behind from backup
|
||||
if [[ ! -z "${ContRepoDigests:-}" ]] && [[ -n "${BackupForDays:-}" ]]; then docker rmi "$ContRepoDigests"; fi
|
||||
if [[ -n "${LogDigestChanges}" ]]; then
|
||||
NewDigest=$(docker image inspect "$ContImage" --format '{{index .RepoDigests 0 }}')
|
||||
LogStore+=("$(printf "%-30s %s > %s\n" "$i:$ContTag" "$ContRepoDigests" "$NewDigest")")
|
||||
fi
|
||||
else
|
||||
printf "\n%bDocker error, exiting!%b\n" "$c_red" "$c_reset" ; exit 1
|
||||
fi
|
||||
|
||||
done
|
||||
printf "\n%bDone pulling updates.%b\n" "$c_green" "$c_reset"
|
||||
[[ -n "${LogDigestChanges}" ]] && { printf "%s\n" "${LogStore[@]}" > "${LogPath}_$(date +'%Y-%m-%d_%H%M')"; }
|
||||
|
||||
if [[ "$SkipRecreate" == true ]]; then
|
||||
printf "%bSkipping container recreation due to -R.%b\n" "$c_yellow" "$c_reset"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
|
||||
NOTIFY_MATRIX_VERSION="v0.4"
|
||||
NOTIFY_MATRIX_VERSION="v0.5"
|
||||
#
|
||||
# Required receiving services must already be set up.
|
||||
# Leave (or place) this file in the "notify_templates" subdirectory within the same directory as the main dockcheck.sh script.
|
||||
@@ -29,7 +29,7 @@ trigger_matrix_notification() {
|
||||
AccessToken="${!AccessTokenVar}" # e.g. MATRIX_ACCESS_TOKEN=token-value
|
||||
RoomId="${!RoomIdVar}" # e.g. MATRIX_ROOM_ID=myroom
|
||||
MatrixServer="${!MatrixServerVar}" # e.g. MATRIX_SERVER_URL=http://matrix.yourdomain.tld
|
||||
MsgBody="{\"msgtype\":\"m.text\",\"body\":\"$MessageBody\"}"
|
||||
MsgBody=$($jqbin -Rn --arg body "$MessageBody" '{msgtype:"m.text", body:$body}')
|
||||
|
||||
# URL Example: https://matrix.org/_matrix/client/r0/rooms/!xxxxxx:example.com/send/m.room.message?access_token=xxxxxxxx
|
||||
curl -S -o /dev/null ${CurlArgs} -X POST "$MatrixServer/_matrix/client/r0/rooms/$RoomId/send/m.room.message?access_token=$AccessToken" -H 'Content-Type: application/json' -d "$MsgBody"
|
||||
@@ -37,4 +37,4 @@ trigger_matrix_notification() {
|
||||
if [[ $? -gt 0 ]]; then
|
||||
NotifyError=true
|
||||
fi
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user