From 70f356a1a950cdabbfe55c1e82ea552fe9b1a1d3 Mon Sep 17 00:00:00 2001 From: erik Date: Fri, 11 Nov 2022 15:10:47 +0100 Subject: [PATCH] Execute script in subshell located in folder Better handling of white spaces in input. Add test for creation of build jobs without sha256sum input. --- .../image/resources/functions.sh | 4 +-- .../image/resources/install.sh | 2 +- src/main/cljc/dda/c4k_website/website.cljc | 8 ++++-- .../cljc/dda/c4k_website/website_test.cljc | 26 +++++++++++++++++++ 4 files changed, 35 insertions(+), 5 deletions(-) diff --git a/infrastructure/c4k-website-build/image/resources/functions.sh b/infrastructure/c4k-website-build/image/resources/functions.sh index f5923cd..411b9e4 100644 --- a/infrastructure/c4k-website-build/image/resources/functions.sh +++ b/infrastructure/c4k-website-build/image/resources/functions.sh @@ -8,7 +8,7 @@ function get-and-unzip-website-data() { function execute-scripts-when-existing { websitedir=$(ls $BUILDDIR) - if [[ -e $BUILDDIR/$websitedir/$SCRIPTFILE ]] + if [[ -f $BUILDDIR/$websitedir/$SCRIPTFILE ]] then checksum="$(sha256sum $BUILDDIR/$websitedir/$SCRIPTFILE)" if [[ "$SHA256SUM" == "$checksum" ]] @@ -22,7 +22,7 @@ function execute-scripts-when-existing { exit 1 fi else - prinf "No script file provided, exiting." + printf "No script file provided, exiting." exit 0 fi } diff --git a/infrastructure/c4k-website-build/image/resources/install.sh b/infrastructure/c4k-website-build/image/resources/install.sh index d5f53f6..9137061 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 mkdir /etc/lein/ diff --git a/src/main/cljc/dda/c4k_website/website.cljc b/src/main/cljc/dda/c4k_website/website.cljc index fc3e687..8fb4747 100644 --- a/src/main/cljc/dda/c4k_website/website.cljc +++ b/src/main/cljc/dda/c4k_website/website.cljc @@ -47,11 +47,15 @@ (defn-spec get-hash-from-sha256sum-output string? [sha256sum-output string?] - (first (st/split sha256sum-output #" "))) + (if (nil? sha256sum-output) + nil + (first (st/split sha256sum-output #"\ +")))) (defn-spec get-file-name-from-sha256sum-output string? [sha256sum-output string?] - (second (st/split sha256sum-output #" "))) + (if (nil? sha256sum-output) + nil + (second (st/split (st/trim sha256sum-output) #"\ +")))) (defn-spec replace-dots-by-minus string? [fqdn pred/fqdn-string?] diff --git a/src/test/cljc/dda/c4k_website/website_test.cljc b/src/test/cljc/dda/c4k_website/website_test.cljc index 65ca044..7f632d6 100644 --- a/src/test/cljc/dda/c4k_website/website_test.cljc +++ b/src/test/cljc/dda/c4k_website/website_test.cljc @@ -230,6 +230,32 @@ :branchname "main", :unique-name "test.io"})))) +(deftest should-generate-website-initial-build-job-without-script-file + (is (= {:apiVersion "batch/v1", + :kind "Job", + :metadata {:name "test-io-initial-build-job", :labels {:app.kubernetes.part-of "test-io-website"}}, + :spec + {:template + {:spec + {:containers + [{:image "domaindrivenarchitecture/c4k-website-build", + :name "test-io-build-app", + :imagePullPolicy "IfNotPresent", + :command ["/entrypoint.sh"], + :envFrom [{:secretRef {:name "test-io-secret"}}], + :env [{:name "SHA256SUM", :value nil} {:name "SCRIPTFILE", :value nil}], + :volumeMounts [{:name "content-volume", :mountPath "/var/www/html/website"}]}], + :volumes [{:name "content-volume", :persistentVolumeClaim {:claimName "test-io-content-volume"}}], + :restartPolicy "OnFailure"}}}} + (cut/generate-website-initial-build-job {:authtoken "abedjgbasdodj", + :gitea-host "gitlab.de", + :username "someuser", + :fqdns ["test.de" "test.org" "www.test.de" "www.test.org"], + :gitea-repo "repo", + :issuer "staging", + :branchname "main", + :unique-name "test.io"})))) + (deftest should-generate-website-build-secret (is (= {:name-c1 "test-io-secret", :name-c2 "test-org-secret",