From c19d780f1505ea100df4effdaaaf68a7d84d96bf Mon Sep 17 00:00:00 2001 From: Andreas Knote Date: Mon, 11 May 2020 17:06:28 +0200 Subject: [PATCH] migrate to faster image resizing --- Dockerfile | 41 ++++++++++++++++++++++++++-------------- scripts/development | 12 ++++++++---- scripts/watch-and-resize | 12 ++++++++++++ 3 files changed, 47 insertions(+), 18 deletions(-) create mode 100755 scripts/watch-and-resize diff --git a/Dockerfile b/Dockerfile index 1acc8b4..2e4132c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:focal AS nodejs_base +FROM ubuntu:focal AS essential_base LABEL maintainer="andreas.knote@uni-wuerzburg.de" @@ -9,15 +9,9 @@ RUN apt-get update && apt-get upgrade && \ apt-get install -y \ curl ssh git-lfs build-essential locales -RUN apt-get update && \ - curl -sL https://deb.nodesource.com/setup_13.x | bash - && \ - apt-get install -y nodejs && \ - echo 'Node: ' && \ - node -v && \ - echo 'NPM: ' && \ - npm -v -FROM nodejs_base AS ruby_jekyll +# Install Ruby and Jekyll +FROM essential_base AS ruby_jekyll RUN apt-get update && \ apt-get install -y \ @@ -39,18 +33,37 @@ RUN locale-gen en_US.UTF-8 && \ ENV LANG en_US.UTF-8 ENV LC_ALL en_US.UTF-8 -FROM ruby_jekyll AS image_resize -RUN apt-get update && apt-get install -y \ - imagemagick +## Install NodeJS +FROM ruby_jekyll AS nodejs + +RUN apt-get update && \ + curl -sL https://deb.nodesource.com/setup_13.x | bash - && \ + apt-get install -y nodejs && \ + echo 'Node: ' && \ + node -v && \ + echo 'NPM: ' && \ + npm -v + -FROM image_resize AS hci_theme +## Install the batch-resize script +FROM nodejs AS image_resize -## Build Theme from source +RUN apt-get update && apt-get install -y \ + python3-pil imgp rsync inotify-tools && \ + git clone https://gitlab2.informatik.uni-wuerzburg.de/hci-development/batch-resize.git /batch-resize && \ + ln -s /batch-resize/batch-resize /usr/bin/batch-resize + +## Build HCI-Theme from source ## Installs the built gem system-wide + COPY . / RUN bundle install && \ bundle exec rake gem && \ gem install hci-theme.gem && \ rm -rf node_modules && \ rm package-lock.json + +# Make development scripts available +RUN ln -s /scripts/* /usr/bin/ && hash + diff --git a/scripts/development b/scripts/development index 7d6b58b..0fe58fb 100755 --- a/scripts/development +++ b/scripts/development @@ -1,9 +1,13 @@ #!/usr/bin/env bash -# Build + +# Resize Images +watch-and-resize ./assets/images/ ./public/assets/images/ & + +# Serve HCI Site bundle bundle update -bundle exec war& -jekyll serve --host=0.0.0.0 --port=4200 --trace --incremental& +jekyll serve --host=0.0.0.0 --port=4200 --trace --incremental & + PIDS[0]=$! trap "kill ${PIDS[*]}" SIGINT -wait \ No newline at end of file +wait diff --git a/scripts/watch-and-resize b/scripts/watch-and-resize new file mode 100755 index 0000000..dfefb33 --- /dev/null +++ b/scripts/watch-and-resize @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +source_dir=${1} +target_dir=${2} + +batch-resize ${source_dir} ${target_dir} + +echo "[watch-and-resize] $source_dir -> $target_dir" +while inotifywait -q -e modify -r ${source_dir}; do + batch-resize ${source_dir} ${target_dir} +done + -- GitLab