Skip to content

Commit

Permalink
define docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
miampf committed Nov 7, 2024
1 parent df0b8a6 commit 7564cdb
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions packages/by-name/k8s-log-collector/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Copyright 2024 Edgeless Systems GmbH
# SPDX-License-Identifier: AGPL-3.0-only

{
dockerTools,
writeShellApplication,
inotify-tools,
busybox
}:

let
collection-script = writeShellApplication {
name = "collect-logs";
runtimeInputs = [
inotify-tools
busybox
];
text = ''
set -euo pipefail
mkdir /export
# collect all logs that may have been missed during startup
find /logs -name "*.log" |
while read -r file; do
if [[ -f "$file" && "$file" == *"$POD_NAMESPACE"* ]]; then
mkdir -p "/export$(dirname "$file")"
tail --follow=name "$file" > "export$file" &
fi
done
inotifywait -m /logs -r -e create -e moved_to |
while read -r path _action file; do
filepath="$path$file"
if [[ -f "$filepath" && "$filepath" == *"$POD_NAMESPACE"* ]]; then
mkdir -p "/export$path"
tail --follow=name "$filepath" >"/export$filepath" &
fi
done
'';
};
in
dockerTools.buildLayeredImage {
name = "k8s-log-collector";
tag = "0.1.0";
config = {
Cmd = [ "${collection-script}/bin/collect-logs" ];
Volumes = { "/logs" = {}; };
};
}

0 comments on commit 7564cdb

Please sign in to comment.