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.
This commit is contained in:
erik 2022-12-09 09:50:13 +01:00
parent 99bc14d62c
commit ee9e11eb04
5 changed files with 16 additions and 22 deletions

View file

@ -1,30 +1,27 @@
#!/bin/bash #!/bin/bash
# curl -s -H "Authorization: token xxxx" https://gitea.host/api/v1/repos/{owner}/{repo}/git/commits/HEAD | jq '.sha'
mkdir $BUILDDIR mkdir $BUILDDIR
mkdir $SOURCEDIR mkdir $SOURCEDIR
set -o nounset set -euo pipefail
set -o xtrace
set -o errexit
set -eo pipefail
source /usr/local/bin/functions.sh source /usr/local/bin/functions.sh
filename="website.zip" filename="website.zip"
hashfilename="hashfile" hashfilename="hashfile"
echo "Downloading website data"
get-website-data $filename
echo "Check for new content" echo "Check for new content"
currentHash=$( print-hash-from-file $filename )
touch $HASHFILEDIR/$hashfilename touch $HASHFILEDIR/$hashfilename
if [[ $currentHash == $(cat $HASHFILEDIR/$hashfilename) ]] currentHash=$( cat $HASHFILEDIR/$hashfilename )
newHash=$( get-hash-data )
if [[ $currentHash == $newHash ]]
then then
echo "Nothing to do" echo "Nothing to do"
else else
write-hashfile $currentHash $hashfilename write-hash-data $currentHash $hashfilename
echo "Downloading website data"
get-website-data $filename
unzip-website-data $filename unzip-website-data $filename
echo "Executing Custom Scripts, if applicable" echo "Executing Custom Scripts, if applicable"
execute-scripts-when-existing execute-scripts-when-existing

View file

@ -1,23 +1,22 @@
#!/bin/bash #!/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() { function get-website-data() {
curl -H "Authorization: token $AUTHTOKEN" -o $SOURCEDIR/$1 $GITREPOURL curl -H "Authorization: token $AUTHTOKEN" -o $SOURCEDIR/$1 $GITREPOURL
} }
function write-hashfile() { function get-hash-data() {
echo $1 > $HASHFILEDIR/$2 curl -s -H "Authorization: token $AUTHTOKEN" $GITCOMMITURL | jq '.sha'
} }
function print-hash-from-file() { function write-hash-data() {
(cd $SOURCEDIR; sha256sum $1 | cut -d " " -f 1;) echo $1 > $HASHFILEDIR/$2
} }
function unzip-website-data() { function unzip-website-data() {
unzip $SOURCEDIR/$1 -d $BUILDDIR unzip $SOURCEDIR/$1 -d $BUILDDIR
} }
function execute-scripts-when-existing { function execute-scripts-when-existing() {
websitedir=$(ls $BUILDDIR) websitedir=$(ls $BUILDDIR)
if [[ -f $BUILDDIR/$websitedir/$SCRIPTFILE ]] if [[ -f $BUILDDIR/$websitedir/$SCRIPTFILE ]]
then then

View file

@ -2,7 +2,7 @@
apt update > /dev/null; apt update > /dev/null;
apt install -y unzip rsync imagemagick apt install -y unzip rsync jq imagemagick
mkdir /etc/lein/ mkdir /etc/lein/

View file

@ -1,4 +1,4 @@
FROM c4k-jira-backup FROM clojure:lein
RUN apt update RUN apt update
RUN apt -yqq --no-install-recommends --yes install curl default-jre-headless RUN apt -yqq --no-install-recommends --yes install curl default-jre-headless

View file

@ -8,5 +8,3 @@ data:
AUTHTOKEN: TOKEN AUTHTOKEN: TOKEN
GITREPOURL: REPOURL GITREPOURL: REPOURL
GITCOMMITURL: COMMITURL GITCOMMITURL: COMMITURL