From 7b1d7b9eeb31e3a35a740a87af02f41ea7755d62 Mon Sep 17 00:00:00 2001 From: Gres Date: Tue, 14 Apr 2020 21:15:26 +0300 Subject: [PATCH] Add resources mirror creation tool --- share/mirror/Dockerfile | 13 +++++++++ share/mirror/docker-compose.yml | 15 ++++++++++ share/mirror/entrypoint.sh | 51 +++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 share/mirror/Dockerfile create mode 100644 share/mirror/docker-compose.yml create mode 100755 share/mirror/entrypoint.sh diff --git a/share/mirror/Dockerfile b/share/mirror/Dockerfile new file mode 100644 index 0000000..5703445 --- /dev/null +++ b/share/mirror/Dockerfile @@ -0,0 +1,13 @@ +FROM alpine:latest + +ADD entrypoint.sh /entrypoint.sh + +RUN \ + addgroup -g 1200 -S app && \ + adduser -g 1200 -u 1200 -S app && \ + apk add --upgrade --no-cache git zip && \ + chmod +x /entrypoint.sh + +USER app +VOLUME [ "/git", "/packed" ] +ENTRYPOINT ["/entrypoint.sh"] diff --git a/share/mirror/docker-compose.yml b/share/mirror/docker-compose.yml new file mode 100644 index 0000000..457226b --- /dev/null +++ b/share/mirror/docker-compose.yml @@ -0,0 +1,15 @@ +version: '3' +services: + mirror: + build: . + image: gres/st_mirror + restart: always + container_name: st_mirror + logging: + driver: json-file + options: + max-size: "10m" + max-file: "5" + volumes: + - ./git:/git + - ./packed:/packed diff --git a/share/mirror/entrypoint.sh b/share/mirror/entrypoint.sh new file mode 100755 index 0000000..1725073 --- /dev/null +++ b/share/mirror/entrypoint.sh @@ -0,0 +1,51 @@ +#!/bin/sh + +pack() { + mkdir -p "$2" + for f in $(ls $1); do + source="$1/$f" + target="$2/$f" + if [ -d "$source" ]; then + pack "$source" "$target" + elif [ -f "$source" ]; then + if [ "$target.zip" -nt "$source" ]; then + echo "$source is up to date" + continue + fi + tmp=/tmp/archive.zip + echo "packing $source -> $tmp" + ls -l "$source" + zip -9 -j "$tmp" "$source" + + echo "moving $tmp -> $target.zip" + mv "$tmp" "$target.zip" + chmod 444 "$target.zip" + ls -l "$target.zip" + fi + done +} + +mirror() { + cur="$(pwd)" + url="$1" + dir="$2" + git_dir="/git/$dir" + pack_dir="/packed/$dir" + echo $url $git_dir $pack_dir + if [ -d $git_dir ]; then + echo "fetching" + cd $git_dir && git fetch --depth=1 origin master + else + echo "cloning" + git clone --depth=1 --single-branch "$url" $git_dir + fi + echo "packing" + pack "$git_dir" "$pack_dir" +} + +while true; do + mirror 'git://anongit.freedesktop.org/libreoffice/dictionaries' 'dictionaries' + mirror 'https://github.com/tesseract-ocr/tessdata_best.git' 'tessdata_best' + echo "sleeping" + sleep 6h +done