From a844a9e94777424e5055ca46cdf6cb4bcf829909 Mon Sep 17 00:00:00 2001 From: erik Date: Fri, 2 Dec 2022 09:37:03 +0100 Subject: [PATCH] [Skip-CI] WIP Build only when new data available --- .../image/resources/entrypoint.sh | 34 +++++++++++++++++-- .../image/resources/functions.sh | 15 ++++++-- 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/infrastructure/c4k-website-build/image/resources/entrypoint.sh b/infrastructure/c4k-website-build/image/resources/entrypoint.sh index ddb1a37..4a8d3ac 100755 --- a/infrastructure/c4k-website-build/image/resources/entrypoint.sh +++ b/infrastructure/c4k-website-build/image/resources/entrypoint.sh @@ -10,8 +10,38 @@ set -eo pipefail source /usr/local/bin/functions.sh -echo "Downloading website" -get-and-unzip-website-data +filename="website.zip" +hashfilename="hashfile" + +# download website data +# check if hashfile exists +# if yes + # hash the current file + # compare current hash to hashfile + # same? + # do nothing + # not same? + # overwrite hashfile with new hash + # start the website build +# if not + # hash the current file + # write the hashfile + # start the build + +echo "Downloading website data" +get-website-data filename +echo "Check for new content" +if [[ -f $hashfile ]] + then + currentHash=$( sha256sum $SOURCEDIR/$filename | cut -d " " -f 1 > ~/$2 ) #ToDo: output of sh256sum without path to file? + + + else + write-hashfile $filename $hashfilename + +fi + + echo "Executing Custom Scripts, if applicable" execute-scripts-when-existing echo "Building website" diff --git a/infrastructure/c4k-website-build/image/resources/functions.sh b/infrastructure/c4k-website-build/image/resources/functions.sh index 323831a..821a59f 100644 --- a/infrastructure/c4k-website-build/image/resources/functions.sh +++ b/infrastructure/c4k-website-build/image/resources/functions.sh @@ -1,8 +1,19 @@ #!/bin/bash -function get-and-unzip-website-data() { - filename="website.zip" +function get-website-data() { curl -H "Authorization: token $AUTHTOKEN" -o $SOURCEDIR/$filename $GITREPOURL +} + +function write-hashfile() { + (cd $SOURCEDIR; sha256sum $1 | cut -d " " -f 1 > ~/$2;) +} + +function compare-website-data() { + oldHash="$( cat ~/hashfile )" + +} + +function unzip-website-data() { unzip $SOURCEDIR/$filename -d $BUILDDIR }