From 3686d1c9d7bf728acbeb83b295daa9c755316d19 Mon Sep 17 00:00:00 2001 From: Stefan Schlott Date: Fri, 26 Aug 2022 18:30:50 +0200 Subject: [PATCH] Docker image for updating site --- Dockerfile-siteupdate | 19 +++++++++++++++++ nanoc.yaml | 4 ++++ scripts/build-docker-images.sh | 1 + scripts/update-site.sh | 39 ++++++++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+) create mode 100644 Dockerfile-siteupdate create mode 100755 scripts/update-site.sh diff --git a/Dockerfile-siteupdate b/Dockerfile-siteupdate new file mode 100644 index 00000000..bdbd2647 --- /dev/null +++ b/Dockerfile-siteupdate @@ -0,0 +1,19 @@ +FROM ruby:2-bullseye +COPY Gemfile* /tmp/ +RUN cd /tmp && bundle install && rm Gemfile* +RUN apt-get update && apt-get install -y rsync git && rm -rf /var/lib/apt/lists/* +COPY scripts/update-site.sh /usr/local/bin/ + +# Home directory of user, containing ssh keys, etc. +VOLUME /data +# Website source +ENV WEBSITE_SOURCE=/website-source +VOLUME /website-source +# Compiled website +VOLUME /website + +RUN useradd -M -d /data siteupdate && chown siteupdate:siteupdate /data /website-source /website +USER siteupdate:siteupdate +WORKDIR /data +CMD /usr/local/bin/update-site.sh + diff --git a/nanoc.yaml b/nanoc.yaml index dbe85811..0421e54d 100644 --- a/nanoc.yaml +++ b/nanoc.yaml @@ -109,4 +109,8 @@ deploy: kind: rsync dst: "/var/www/www.cccs.de/htdocs" options: [ '-rlPq', '--delete-after' ] + incontainer: + kind: rsync + dst: "/website" + options: [ '-rlPq', '--delete-after' ] diff --git a/scripts/build-docker-images.sh b/scripts/build-docker-images.sh index 3c2524c0..0f038f5e 100755 --- a/scripts/build-docker-images.sh +++ b/scripts/build-docker-images.sh @@ -5,4 +5,5 @@ set -u -e cd `dirname $0`/.. docker build -f Dockerfile-reminders -t cccs-reminders:latest . +docker build -f Dockerfile-siteupdate -t cccs-siteupdate:latest . diff --git a/scripts/update-site.sh b/scripts/update-site.sh new file mode 100755 index 00000000..5b82fb05 --- /dev/null +++ b/scripts/update-site.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +DEPLOY_TARGET="${1:-incontainer}" +if [[ "$WEBSITE_SOURCE" == "" ]] ; then + WEBSITE_SOURCE=`dirname $0`/.. +fi + +# Update site +cd $WEBSITE_SOURCE +if [[ -d .git ]] ; then + git pull || exit 1 +else + git clone git@github.com:cccs/cccs-website.git . || exit 1 +fi + +# Update Twitter +cd $WEBSITE_SOURCE/content/_data +../../scripts/update-twitter.sh +git add twitter.csv +git commit -m "Update Twitter" + +# Update blog roll +cd $WEBSITE_SOURCE/scripts +./update-planetfeeds.rb ../content/_data/planetcccs-blogroll.yaml ../content/planet-cccs.yaml +git add ../content/planet-cccs.yaml +git commit -m "Update Planet" + +# Push changes +cd $WEBSITE_SOURCE +git push + +# Update site +rm -rf tmp output +#bundle exec nanoc || exit 1 +bundle exec nanoc +rm -f crash.log +umask 0002 +bundle exec nanoc deploy -t "$DEPLOY_TARGET" +