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:
parent
99bc14d62c
commit
ee9e11eb04
5 changed files with 16 additions and 22 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
apt update > /dev/null;
|
||||
|
||||
apt install -y unzip rsync imagemagick
|
||||
apt install -y unzip rsync jq imagemagick
|
||||
|
||||
mkdir /etc/lein/
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -8,5 +8,3 @@ data:
|
|||
AUTHTOKEN: TOKEN
|
||||
GITREPOURL: REPOURL
|
||||
GITCOMMITURL: COMMITURL
|
||||
|
||||
|
Loading…
Reference in a new issue