diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7721c14 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,19 @@ +FROM alpine:3.20 + +COPY inotiy.sh /inotiy.sh +RUN CHOWN +x /inotiy.sh + +RUN apk --no-cache add \ + inotify-tools \ + curl \ + && rm -rf /var/cache/apk/* + + +ENV CHUNK_SIZE=1048576 \ + WATCH_PATH=/opt/livekit-egress \ + UPLOAD_URL= \ + AUTH_TOKEN=verySecretToken \ + + + +CMD ["sh", "/inotiy.sh" ] \ No newline at end of file diff --git a/inotify.sh b/inotify.sh new file mode 100644 index 0000000..5c263dd --- /dev/null +++ b/inotify.sh @@ -0,0 +1,29 @@ +#!/bin/sh + +inotifywait -m "$WATCH_PATH" -e close_write | + while read PATH ACTION FILE; do + + if [[ "${FILE}" == *.mp4 ]] + then + echo "Following PATH is selected: $PATH" + echo "Uploading following FILE: $FILE" + + file_path="${PATH}${FILE}" + chunk_size="$CHUNK_SIZE" + id="${FILE%.mp4}" + + file_size=$(stat -c%s "$file_path") + num_chunks=$(( (file_size + chunk_size - 1) / chunk_size )) + + for (( i=0; i/dev/null | curl \ + --location "$UPLOAD_URL" \ + --header "Authorization: Bearer $AUTH_TOKEN" \ + --form "recording_id=${id}" \ + --form "chunk_index=${i}" \ + --form "total_chunks=${num_chunks}" \ + --form "FILE=@-" + done + fi + done