From ee9e11eb042b137da66f1394565037b1a9025cc6 Mon Sep 17 00:00:00 2001 From: erik Date: Fri, 9 Dec 2022 09:50:13 +0100 Subject: [PATCH] Implement API call to check commit hash We now download a few kb of commit info and check for changes in the hash first, before downloading the full zip. Also use the clojure:lein image in test. --- .../image/resources/entrypoint.sh | 21 ++++++++----------- .../image/resources/functions.sh | 11 +++++----- .../image/resources/install.sh | 2 +- .../c4k-website-build/test/Dockerfile | 2 +- .../website/website-build-secret.yaml | 2 -- 5 files changed, 16 insertions(+), 22 deletions(-) diff --git a/infrastructure/c4k-website-build/image/resources/entrypoint.sh b/infrastructure/c4k-website-build/image/resources/entrypoint.sh index 52eff16..871a00d 100755 --- a/infrastructure/c4k-website-build/image/resources/entrypoint.sh +++ b/infrastructure/c4k-website-build/image/resources/entrypoint.sh @@ -1,30 +1,27 @@ #!/bin/bash -# curl -s -H "Authorization: token xxxx" https://gitea.host/api/v1/repos/{owner}/{repo}/git/commits/HEAD | jq '.sha' mkdir $BUILDDIR mkdir $SOURCEDIR -set -o nounset -set -o xtrace -set -o errexit -set -eo pipefail +set -euo pipefail source /usr/local/bin/functions.sh filename="website.zip" hashfilename="hashfile" -echo "Downloading website data" -get-website-data $filename - echo "Check for new content" -currentHash=$( print-hash-from-file $filename ) touch $HASHFILEDIR/$hashfilename -if [[ $currentHash == $(cat $HASHFILEDIR/$hashfilename) ]] +currentHash=$( cat $HASHFILEDIR/$hashfilename ) +newHash=$( get-hash-data ) + +if [[ $currentHash == $newHash ]] then echo "Nothing to do" - else - write-hashfile $currentHash $hashfilename + else + write-hash-data $currentHash $hashfilename + echo "Downloading website data" + get-website-data $filename unzip-website-data $filename echo "Executing Custom Scripts, if applicable" execute-scripts-when-existing diff --git a/infrastructure/c4k-website-build/image/resources/functions.sh b/infrastructure/c4k-website-build/image/resources/functions.sh index e3cbcea..7ab68db 100644 --- a/infrastructure/c4k-website-build/image/resources/functions.sh +++ b/infrastructure/c4k-website-build/image/resources/functions.sh @@ -1,23 +1,22 @@ #!/bin/bash -# curl -s -H "Authorization: token xxxx" https://gitea.host/api/v1/repos/{owner}/{repo}/git/commits/HEAD | jq '.sha' function get-website-data() { curl -H "Authorization: token $AUTHTOKEN" -o $SOURCEDIR/$1 $GITREPOURL } -function write-hashfile() { - echo $1 > $HASHFILEDIR/$2 +function get-hash-data() { + curl -s -H "Authorization: token $AUTHTOKEN" $GITCOMMITURL | jq '.sha' } -function print-hash-from-file() { - (cd $SOURCEDIR; sha256sum $1 | cut -d " " -f 1;) +function write-hash-data() { + echo $1 > $HASHFILEDIR/$2 } function unzip-website-data() { unzip $SOURCEDIR/$1 -d $BUILDDIR } -function execute-scripts-when-existing { +function execute-scripts-when-existing() { websitedir=$(ls $BUILDDIR) if [[ -f $BUILDDIR/$websitedir/$SCRIPTFILE ]] then diff --git a/infrastructure/c4k-website-build/image/resources/install.sh b/infrastructure/c4k-website-build/image/resources/install.sh index d5f53f6..cd78ccb 100755 --- a/infrastructure/c4k-website-build/image/resources/install.sh +++ b/infrastructure/c4k-website-build/image/resources/install.sh @@ -2,7 +2,7 @@ apt update > /dev/null; -apt install -y unzip rsync imagemagick +apt install -y unzip rsync jq imagemagick mkdir /etc/lein/ diff --git a/infrastructure/c4k-website-build/test/Dockerfile b/infrastructure/c4k-website-build/test/Dockerfile index f2e19b6..47c3702 100644 --- a/infrastructure/c4k-website-build/test/Dockerfile +++ b/infrastructure/c4k-website-build/test/Dockerfile @@ -1,4 +1,4 @@ -FROM c4k-jira-backup +FROM clojure:lein RUN apt update RUN apt -yqq --no-install-recommends --yes install curl default-jre-headless diff --git a/src/main/resources/website/website-build-secret.yaml b/src/main/resources/website/website-build-secret.yaml index 770ce10..f173d46 100644 --- a/src/main/resources/website/website-build-secret.yaml +++ b/src/main/resources/website/website-build-secret.yaml @@ -8,5 +8,3 @@ data: AUTHTOKEN: TOKEN GITREPOURL: REPOURL GITCOMMITURL: COMMITURL - - \ No newline at end of file