From a844a9e94777424e5055ca46cdf6cb4bcf829909 Mon Sep 17 00:00:00 2001 From: erik Date: Fri, 2 Dec 2022 09:37:03 +0100 Subject: [PATCH 01/15] [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 } From 37170ee982ede3c074c31c477b74642573c9f89b Mon Sep 17 00:00:00 2001 From: Clemens Date: Fri, 2 Dec 2022 10:04:09 +0100 Subject: [PATCH 02/15] SKIP-CI // Started with hash check --- infrastructure/c4k-website-build/image/Dockerfile | 1 + .../c4k-website-build/image/resources/entrypoint.sh | 6 +++--- .../c4k-website-build/image/resources/functions.sh | 10 +++++++--- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/infrastructure/c4k-website-build/image/Dockerfile b/infrastructure/c4k-website-build/image/Dockerfile index 270be95..b24df8e 100644 --- a/infrastructure/c4k-website-build/image/Dockerfile +++ b/infrastructure/c4k-website-build/image/Dockerfile @@ -6,5 +6,6 @@ ADD resources /tmp ENV SOURCEDIR="/etc/websitesource" ENV BUILDDIR="/etc/website" ENV WEBSITEROOT="/var/www/html/website/" +ENV HASHFILEDIR="/data/hasfiles/" RUN /tmp/install.sh diff --git a/infrastructure/c4k-website-build/image/resources/entrypoint.sh b/infrastructure/c4k-website-build/image/resources/entrypoint.sh index 4a8d3ac..1b693be 100755 --- a/infrastructure/c4k-website-build/image/resources/entrypoint.sh +++ b/infrastructure/c4k-website-build/image/resources/entrypoint.sh @@ -2,6 +2,7 @@ mkdir $BUILDDIR mkdir $SOURCEDIR +mkdir -p $HASHFILEDIR set -o nounset set -o xtrace @@ -29,12 +30,11 @@ hashfilename="hashfile" # start the build echo "Downloading website data" -get-website-data filename +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? - + currentHash=$(print-hash-from-file $filename ) else write-hashfile $filename $hashfilename diff --git a/infrastructure/c4k-website-build/image/resources/functions.sh b/infrastructure/c4k-website-build/image/resources/functions.sh index 821a59f..ec8897f 100644 --- a/infrastructure/c4k-website-build/image/resources/functions.sh +++ b/infrastructure/c4k-website-build/image/resources/functions.sh @@ -1,11 +1,15 @@ #!/bin/bash function get-website-data() { - curl -H "Authorization: token $AUTHTOKEN" -o $SOURCEDIR/$filename $GITREPOURL + curl -H "Authorization: token $AUTHTOKEN" -o $SOURCEDIR/$1 $GITREPOURL } function write-hashfile() { - (cd $SOURCEDIR; sha256sum $1 | cut -d " " -f 1 > ~/$2;) + (cd $SOURCEDIR; sha256sum $1 | cut -d " " -f 1 > $HASHFILEDIR/$2;) +} + +function print-hash-from-file() { + (cd $SOURCEDIR; sha256sum $1 | cut -d " " -f 1;) } function compare-website-data() { @@ -14,7 +18,7 @@ function compare-website-data() { } function unzip-website-data() { - unzip $SOURCEDIR/$filename -d $BUILDDIR + unzip $SOURCEDIR/$1 -d $BUILDDIR } function execute-scripts-when-existing { From e6c51ed4798a0fb44affad4add866ec92a1d8834 Mon Sep 17 00:00:00 2001 From: erik Date: Fri, 2 Dec 2022 10:36:44 +0100 Subject: [PATCH 03/15] [Skip-CI] WIP check file before building --- .../image/resources/entrypoint.sh | 53 ++++++++++--------- .../image/resources/functions.sh | 9 +--- 2 files changed, 29 insertions(+), 33 deletions(-) diff --git a/infrastructure/c4k-website-build/image/resources/entrypoint.sh b/infrastructure/c4k-website-build/image/resources/entrypoint.sh index 1b693be..9387560 100755 --- a/infrastructure/c4k-website-build/image/resources/entrypoint.sh +++ b/infrastructure/c4k-website-build/image/resources/entrypoint.sh @@ -13,38 +13,39 @@ source /usr/local/bin/functions.sh filename="website.zip" hashfilename="hashfile" +touch $HASHFILEDIR/$hashfilename +# create empty 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 +# compare current hash to hashfile + # same? + # do nothing + # not same? + # overwrite hashfile with new hash + # unzip website + # execute scripts (if applicable) + # build website + # move files echo "Downloading website data" get-website-data $filename -echo "Check for new content" -if [[ -f $hashfile ]] - then - currentHash=$(print-hash-from-file $filename ) - - else - write-hashfile $filename $hashfilename +echo "Check for new content" +currentHash=$( print-hash-from-file $filename ) +if [[ $currentHash == $(cat $HASHFILEDIR/$hashfilename) ]] + then + echo "Nothing to do" + else + write-hashfile $currentHash $hashfilename + unzip-website-data $filename + echo "Executing Custom Scripts, if applicable" + execute-scripts-when-existing + echo "Building website" + build-website + echo "Moving files" + move-website-files-to-target fi -echo "Executing Custom Scripts, if applicable" -execute-scripts-when-existing -echo "Building website" -build-and-extract-website -echo "Moving files" -move-website-files-to-target + + diff --git a/infrastructure/c4k-website-build/image/resources/functions.sh b/infrastructure/c4k-website-build/image/resources/functions.sh index ec8897f..844edc9 100644 --- a/infrastructure/c4k-website-build/image/resources/functions.sh +++ b/infrastructure/c4k-website-build/image/resources/functions.sh @@ -5,18 +5,13 @@ function get-website-data() { } function write-hashfile() { - (cd $SOURCEDIR; sha256sum $1 | cut -d " " -f 1 > $HASHFILEDIR/$2;) + echo $1 > $HASHFILEDIR/$2 } function print-hash-from-file() { (cd $SOURCEDIR; sha256sum $1 | cut -d " " -f 1;) } -function compare-website-data() { - oldHash="$( cat ~/hashfile )" - -} - function unzip-website-data() { unzip $SOURCEDIR/$1 -d $BUILDDIR } @@ -41,7 +36,7 @@ function execute-scripts-when-existing { fi } -function build-and-extract-website() { +function build-website() { (cd $BUILDDIR; dir=$(ls); cd $dir; lein run;) } From 8c98c3eb8fc696914da2e462c68356bc635b151c Mon Sep 17 00:00:00 2001 From: Clemens Date: Fri, 2 Dec 2022 11:33:27 +0100 Subject: [PATCH 04/15] [SKIP-CI] Fix typo --- infrastructure/c4k-website-build/image/Dockerfile | 2 +- infrastructure/c4k-website-build/image/resources/entrypoint.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/infrastructure/c4k-website-build/image/Dockerfile b/infrastructure/c4k-website-build/image/Dockerfile index b24df8e..02615d1 100644 --- a/infrastructure/c4k-website-build/image/Dockerfile +++ b/infrastructure/c4k-website-build/image/Dockerfile @@ -6,6 +6,6 @@ ADD resources /tmp ENV SOURCEDIR="/etc/websitesource" ENV BUILDDIR="/etc/website" ENV WEBSITEROOT="/var/www/html/website/" -ENV HASHFILEDIR="/data/hasfiles/" +ENV HASHFILEDIR="/data/hashfiles" RUN /tmp/install.sh diff --git a/infrastructure/c4k-website-build/image/resources/entrypoint.sh b/infrastructure/c4k-website-build/image/resources/entrypoint.sh index 9387560..6d8e90a 100755 --- a/infrastructure/c4k-website-build/image/resources/entrypoint.sh +++ b/infrastructure/c4k-website-build/image/resources/entrypoint.sh @@ -13,7 +13,6 @@ source /usr/local/bin/functions.sh filename="website.zip" hashfilename="hashfile" -touch $HASHFILEDIR/$hashfilename # create empty hashfile # download website data @@ -32,6 +31,7 @@ get-website-data $filename echo "Check for new content" currentHash=$( print-hash-from-file $filename ) +touch $HASHFILEDIR/$hashfilename if [[ $currentHash == $(cat $HASHFILEDIR/$hashfilename) ]] then echo "Nothing to do" From f126035e8443bcab97ad06f1517950cb93a90c4c Mon Sep 17 00:00:00 2001 From: erik Date: Fri, 2 Dec 2022 11:56:21 +0100 Subject: [PATCH 05/15] [Skip-CI] WIP add hashfile storage --- .../c4k-website-build/image/Dockerfile | 4 ++-- .../image/resources/entrypoint.sh | 4 ++-- src/main/cljc/dda/c4k_website/website.cljc | 7 ++++++- src/main/resources/website/hashfile-volume.yaml | 16 ++++++++++++++++ src/main/resources/website/nginx-deployment.yaml | 5 +++++ .../resources/website/website-build-cron.yaml | 5 +++++ 6 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 src/main/resources/website/hashfile-volume.yaml diff --git a/infrastructure/c4k-website-build/image/Dockerfile b/infrastructure/c4k-website-build/image/Dockerfile index 02615d1..4d3289b 100644 --- a/infrastructure/c4k-website-build/image/Dockerfile +++ b/infrastructure/c4k-website-build/image/Dockerfile @@ -3,9 +3,9 @@ FROM clojure:lein # Prepare Entrypoint Script ADD resources /tmp -ENV SOURCEDIR="/etc/websitesource" ENV BUILDDIR="/etc/website" +ENV SOURCEDIR="/etc/websitesource" ENV WEBSITEROOT="/var/www/html/website/" -ENV HASHFILEDIR="/data/hashfiles" +ENV HASHFILEDIR="/var/hashfile.d" RUN /tmp/install.sh diff --git a/infrastructure/c4k-website-build/image/resources/entrypoint.sh b/infrastructure/c4k-website-build/image/resources/entrypoint.sh index 6d8e90a..75cbe2d 100755 --- a/infrastructure/c4k-website-build/image/resources/entrypoint.sh +++ b/infrastructure/c4k-website-build/image/resources/entrypoint.sh @@ -1,8 +1,8 @@ #!/bin/bash +# curl -s -H "Authorization: token d92668fff6e005582dcb09c6590982a39b2523fc" https://repo.prod.meissa.de/api/v1/repos/meissa-intern/meissa-io/git/commits/HEAD | jq '.' mkdir $BUILDDIR mkdir $SOURCEDIR -mkdir -p $HASHFILEDIR set -o nounset set -o xtrace @@ -14,8 +14,8 @@ source /usr/local/bin/functions.sh filename="website.zip" hashfilename="hashfile" -# create empty hashfile # download website data +# create empty hashfile # compare current hash to hashfile # same? # do nothing diff --git a/src/main/cljc/dda/c4k_website/website.cljc b/src/main/cljc/dda/c4k_website/website.cljc index c82cad2..446cba1 100644 --- a/src/main/cljc/dda/c4k_website/website.cljc +++ b/src/main/cljc/dda/c4k_website/website.cljc @@ -185,6 +185,10 @@ (replace-common-data "website/website-content-volume.yaml" config) (cm/replace-all-matching-values-by-new-value "WEBSITESTORAGESIZE" (str volume-size "Gi"))))) +(defn-spec generate-hashfile-volume pred/map-or-seq? + [config flattened-and-reduced-config?] + (replace-common-data "website/website-content-volume.yaml" config)) + (defn-spec generate-website-build-cron pred/map-or-seq? [config flattened-and-reduced-config?] (replace-build-data "website/website-build-cron.yaml" config)) @@ -204,4 +208,5 @@ gitea-host gitea-repo username - branchname)))))) \ No newline at end of file + branchname)))))) + diff --git a/src/main/resources/website/hashfile-volume.yaml b/src/main/resources/website/hashfile-volume.yaml new file mode 100644 index 0000000..99f35db --- /dev/null +++ b/src/main/resources/website/hashfile-volume.yaml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: NAME-hashfile-volume + namespace: default + labels: + app: NAME-nginx + app.kubernetes.part-of: NAME-website +spec: + storageClassName: local-path + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 16Mi + \ No newline at end of file diff --git a/src/main/resources/website/nginx-deployment.yaml b/src/main/resources/website/nginx-deployment.yaml index 234bc7e..9133cd2 100644 --- a/src/main/resources/website/nginx-deployment.yaml +++ b/src/main/resources/website/nginx-deployment.yaml @@ -52,6 +52,8 @@ spec: volumeMounts: - name: content-volume mountPath: /var/www/html/website + - name: hashfile-volume + mountPath: /var/hashfile.d volumes: - name: nginx-config-volume configMap: @@ -68,4 +70,7 @@ spec: - name: content-volume persistentVolumeClaim: claimName: NAME-content-volume + - name: hashfile-volume + persistentVolumeClaim: + claimName: NAME-hashfile-volume \ No newline at end of file diff --git a/src/main/resources/website/website-build-cron.yaml b/src/main/resources/website/website-build-cron.yaml index 371444c..c6cb277 100644 --- a/src/main/resources/website/website-build-cron.yaml +++ b/src/main/resources/website/website-build-cron.yaml @@ -35,9 +35,14 @@ spec: volumeMounts: - name: content-volume mountPath: /var/www/html/website + - name: hashfile-volume + mountPath: /var/hashfile.d volumes: - name: content-volume persistentVolumeClaim: claimName: NAME-content-volume + - name: hashfile-volume + persistentVolumeClaim: + claimName: NAME-hashfile-volume restartPolicy: OnFailure \ No newline at end of file From 529e7d46b6ff4b6724651d7fcd9246a469e7cf81 Mon Sep 17 00:00:00 2001 From: Clemens Date: Fri, 2 Dec 2022 12:03:48 +0100 Subject: [PATCH 06/15] [SKIP-CI] Renamed function --- src/main/cljc/dda/c4k_website/website.cljc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/cljc/dda/c4k_website/website.cljc b/src/main/cljc/dda/c4k_website/website.cljc index 446cba1..cecf5f7 100644 --- a/src/main/cljc/dda/c4k_website/website.cljc +++ b/src/main/cljc/dda/c4k_website/website.cljc @@ -98,7 +98,7 @@ branch string?] (str "https://" host "/api/v1/repos/" user "/" repo "/archive/" branch ".zip")) -(defn-spec replace-all-matching-subvalues-in-string-start pred/map-or-seq? +(defn-spec replace-all-matching-substrings-beginning-with pred/map-or-seq? [col pred/map-or-seq? value-to-partly-match string? value-to-inplace string?] @@ -114,7 +114,7 @@ (-> (yaml/load-as-edn resource-file) (assoc-in [:metadata :labels :app.kubernetes.part-of] (generate-app-name unique-name)) - (replace-all-matching-subvalues-in-string-start "NAME" (replace-dots-by-minus unique-name))))) + (replace-all-matching-substrings-beginning-with "NAME" (replace-dots-by-minus unique-name))))) (defn-spec replace-build-data pred/map-or-seq? [resource-file string? From 9e18e99d0ebf89d098fa45a7e02faa1fc0ddaefe Mon Sep 17 00:00:00 2001 From: Clemens Date: Fri, 2 Dec 2022 12:18:08 +0100 Subject: [PATCH 07/15] [SKIP-CI] Fixed tests --- src/main/resources/website/website-build-cron.yaml | 4 ++-- src/test/cljc/dda/c4k_website/website_test.cljc | 14 +++++++++----- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/main/resources/website/website-build-cron.yaml b/src/main/resources/website/website-build-cron.yaml index c6cb277..1c79d09 100644 --- a/src/main/resources/website/website-build-cron.yaml +++ b/src/main/resources/website/website-build-cron.yaml @@ -42,7 +42,7 @@ spec: persistentVolumeClaim: claimName: NAME-content-volume - name: hashfile-volume - persistentVolumeClaim: - claimName: NAME-hashfile-volume + persistentVolumeClaim: + claimName: NAME-hashfile-volume restartPolicy: OnFailure \ No newline at end of file diff --git a/src/test/cljc/dda/c4k_website/website_test.cljc b/src/test/cljc/dda/c4k_website/website_test.cljc index bf92958..d798877 100644 --- a/src/test/cljc/dda/c4k_website/website_test.cljc +++ b/src/test/cljc/dda/c4k_website/website_test.cljc @@ -101,11 +101,12 @@ [{:image "domaindrivenarchitecture/c4k-website-build", :name "test-io-init-build-container", :imagePullPolicy "IfNotPresent", - :resources {:requests {:cpu "1000m", :memory "256Mi"}, :limits {:cpu "1700m", :memory "512Mi"}}, + :resources {:requests {:cpu "500m", :memory "256Mi"}, :limits {:cpu "1700m", :memory "512Mi"}}, :command ["/entrypoint.sh"], :envFrom [{:secretRef {:name "test-io-secret"}}], :env [{:name "SHA256SUM", :value "123456789ab123cd345de"} {:name "SCRIPTFILE", :value "script-file-name.sh"}], - :volumeMounts [{:name "content-volume", :mountPath "/var/www/html/website"}]}], + :volumeMounts [{:name "content-volume", :mountPath "/var/www/html/website"} + {:name "hashfile-volume", :mountPath "/var/hashfile.d"}]}], :volumes [{:name "nginx-config-volume", :configMap @@ -115,7 +116,8 @@ {:key "website.conf", :path "conf.d/website.conf"} {:key "mime.types", :path "mime.types"}]}} {:name "log", :emptyDir {}} - {:name "content-volume", :persistentVolumeClaim {:claimName "test-io-content-volume"}}]}}}} + {:name "content-volume", :persistentVolumeClaim {:claimName "test-io-content-volume"}} + {:name "hashfile-volume", :persistentVolumeClaim {:claimName "test-io-hashfile-volume"}}]}}}} (cut/generate-nginx-deployment {:authtoken "abedjgbasdodj", :gitea-host "gitlab.de", :username "someuser", @@ -196,8 +198,10 @@ :command ["/entrypoint.sh"], :envFrom [{:secretRef {:name "test-io-secret"}}], :env [{:name "SHA256SUM", :value "123456789ab123cd345de"} {:name "SCRIPTFILE", :value "script-file-name.sh"}], - :volumeMounts [{:name "content-volume", :mountPath "/var/www/html/website"}]}], - :volumes [{:name "content-volume", :persistentVolumeClaim {:claimName "test-io-content-volume"}}], + :volumeMounts [{:name "content-volume", :mountPath "/var/www/html/website"} + {:name "hashfile-volume", :mountPath "/var/hashfile.d"}]}], + :volumes [{:name "content-volume", :persistentVolumeClaim {:claimName "test-io-content-volume"}} + {:name "hashfile-volume", :persistentVolumeClaim {:claimName "test-io-hashfile-volume"}}], :restartPolicy "OnFailure"}}}}}} (cut/generate-website-build-cron {:authtoken "abedjgbasdodj", :gitea-host "gitlab.de", From cb06b081bac5415d086373a9a2e250b5e9f647e9 Mon Sep 17 00:00:00 2001 From: erik Date: Fri, 2 Dec 2022 12:33:45 +0100 Subject: [PATCH 08/15] [Skip-CI] Add test for hashfile-vol Add resource file for cljs. Formatting in entrypoint.sh --- .../image/resources/entrypoint.sh | 12 ------------ src/main/cljc/dda/c4k_website/website.cljc | 3 ++- src/test/cljc/dda/c4k_website/website_test.cljc | 17 +++++++++++++++++ 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/infrastructure/c4k-website-build/image/resources/entrypoint.sh b/infrastructure/c4k-website-build/image/resources/entrypoint.sh index 75cbe2d..aa4dcf5 100755 --- a/infrastructure/c4k-website-build/image/resources/entrypoint.sh +++ b/infrastructure/c4k-website-build/image/resources/entrypoint.sh @@ -14,18 +14,6 @@ source /usr/local/bin/functions.sh filename="website.zip" hashfilename="hashfile" -# download website data -# create empty hashfile -# compare current hash to hashfile - # same? - # do nothing - # not same? - # overwrite hashfile with new hash - # unzip website - # execute scripts (if applicable) - # build website - # move files - echo "Downloading website data" get-website-data $filename diff --git a/src/main/cljc/dda/c4k_website/website.cljc b/src/main/cljc/dda/c4k_website/website.cljc index cecf5f7..bb1d09f 100644 --- a/src/main/cljc/dda/c4k_website/website.cljc +++ b/src/main/cljc/dda/c4k_website/website.cljc @@ -139,6 +139,7 @@ "website/website-build-cron.yaml" (rc/inline "website/website-build-cron.yaml") "website/website-build-secret.yaml" (rc/inline "website/website-build-secret.yaml") "website/website-content-volume.yaml" (rc/inline "website/website-content-volume.yaml") + "website/hashfile-volume.yaml" (rc/inline "website/hashfile-volume.yaml") (throw (js/Error. "Undefined Resource!"))))) (defn-spec generate-website-ingress pred/map-or-seq? @@ -187,7 +188,7 @@ (defn-spec generate-hashfile-volume pred/map-or-seq? [config flattened-and-reduced-config?] - (replace-common-data "website/website-content-volume.yaml" config)) + (replace-common-data "website/hashfile-volume.yaml" config)) (defn-spec generate-website-build-cron pred/map-or-seq? [config flattened-and-reduced-config?] diff --git a/src/test/cljc/dda/c4k_website/website_test.cljc b/src/test/cljc/dda/c4k_website/website_test.cljc index d798877..4989809 100644 --- a/src/test/cljc/dda/c4k_website/website_test.cljc +++ b/src/test/cljc/dda/c4k_website/website_test.cljc @@ -12,6 +12,7 @@ (st/instrument `cut/generate-nginx-deployment) (st/instrument `cut/generate-nginx-service) (st/instrument `cut/generate-website-content-volume) +(st/instrument `cut/generate-hashfile-volume) (st/instrument `cut/generate-website-ingress) (st/instrument `cut/generate-website-certificate) (st/instrument `cut/generate-website-build-cron) @@ -259,3 +260,19 @@ :fqdns ["test.de" "www.test.de" "test-it.de" "www.test-it.de"] :username "someuser" :authtoken "abedjgbasdodj"}))))) + +(deftest should-generate-hashfile-volume + (is (= {:apiVersion "v1", + :kind "PersistentVolumeClaim", + :metadata + {:name "test-io-hashfile-volume", + :namespace "default", + :labels {:app "test-io-nginx", :app.kubernetes.part-of "test-io-website"}}, + :spec {:storageClassName "local-path", :accessModes ["ReadWriteOnce"], :resources {:requests {:storage "16Mi"}}}} + (cut/generate-hashfile-volume {:unique-name "test.io", + :gitea-host "gitea.evilorg", + :gitea-repo "none", + :branchname "mablain", + :fqdns ["test.de" "www.test.de" "test-it.de" "www.test-it.de"] + :username "someuser" + :authtoken "abedjgbasdodj"})))) From 892d96284a0912223bfa244382fce612f1810045 Mon Sep 17 00:00:00 2001 From: erik Date: Thu, 8 Dec 2022 17:39:48 +0100 Subject: [PATCH 09/15] Add method to core --- src/main/cljc/dda/c4k_website/core.cljc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/cljc/dda/c4k_website/core.cljc b/src/main/cljc/dda/c4k_website/core.cljc index d4fc44b..6a4d92f 100644 --- a/src/main/cljc/dda/c4k_website/core.cljc +++ b/src/main/cljc/dda/c4k_website/core.cljc @@ -45,6 +45,7 @@ (website/generate-nginx-configmap (flatten-and-reduce-config config)) (website/generate-nginx-service (flatten-and-reduce-config config)) (website/generate-website-content-volume (flatten-and-reduce-config config)) + (website/generate-hashfile-volume (flatten-and-reduce-config config)) (website/generate-website-ingress (flatten-and-reduce-config config)) (website/generate-website-certificate (flatten-and-reduce-config config)) (website/generate-website-build-cron (flatten-and-reduce-config config)) From 21f4a6c54ee465b00681e9a03c08e9fd5cc76536 Mon Sep 17 00:00:00 2001 From: erik Date: Thu, 8 Dec 2022 18:39:33 +0100 Subject: [PATCH 10/15] [Skip-CI] Install imagemagick with image --- infrastructure/c4k-website-build/image/resources/functions.sh | 1 + infrastructure/c4k-website-build/image/resources/install.sh | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/infrastructure/c4k-website-build/image/resources/functions.sh b/infrastructure/c4k-website-build/image/resources/functions.sh index 844edc9..b899770 100644 --- a/infrastructure/c4k-website-build/image/resources/functions.sh +++ b/infrastructure/c4k-website-build/image/resources/functions.sh @@ -1,4 +1,5 @@ #!/bin/bash +# curl -s -H "Authorization: token xxxx" https://repo.prod.meissa.de/api/v1/repos/meissa-intern/meissa-io/git/commits/HEAD | jq '.sha' function get-website-data() { curl -H "Authorization: token $AUTHTOKEN" -o $SOURCEDIR/$1 $GITREPOURL diff --git a/infrastructure/c4k-website-build/image/resources/install.sh b/infrastructure/c4k-website-build/image/resources/install.sh index 9137061..d5f53f6 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 +apt install -y unzip rsync imagemagick mkdir /etc/lein/ From 99bc14d62cb2aa795529e9aa85e3514669f7f65d Mon Sep 17 00:00:00 2001 From: erik Date: Fri, 9 Dec 2022 09:23:01 +0100 Subject: [PATCH 11/15] [Skip-CI] Generate API call for commit info --- .../image/resources/entrypoint.sh | 2 +- .../image/resources/functions.sh | 2 +- src/main/cljc/dda/c4k_website/website.cljc | 18 ++++++-- .../website/website-build-secret.yaml | 3 +- .../cljc/dda/c4k_website/website_test.cljc | 41 ++++++++----------- 5 files changed, 37 insertions(+), 29 deletions(-) diff --git a/infrastructure/c4k-website-build/image/resources/entrypoint.sh b/infrastructure/c4k-website-build/image/resources/entrypoint.sh index aa4dcf5..52eff16 100755 --- a/infrastructure/c4k-website-build/image/resources/entrypoint.sh +++ b/infrastructure/c4k-website-build/image/resources/entrypoint.sh @@ -1,5 +1,5 @@ #!/bin/bash -# curl -s -H "Authorization: token d92668fff6e005582dcb09c6590982a39b2523fc" https://repo.prod.meissa.de/api/v1/repos/meissa-intern/meissa-io/git/commits/HEAD | jq '.' +# curl -s -H "Authorization: token xxxx" https://gitea.host/api/v1/repos/{owner}/{repo}/git/commits/HEAD | jq '.sha' mkdir $BUILDDIR mkdir $SOURCEDIR diff --git a/infrastructure/c4k-website-build/image/resources/functions.sh b/infrastructure/c4k-website-build/image/resources/functions.sh index b899770..e3cbcea 100644 --- a/infrastructure/c4k-website-build/image/resources/functions.sh +++ b/infrastructure/c4k-website-build/image/resources/functions.sh @@ -1,5 +1,5 @@ #!/bin/bash -# curl -s -H "Authorization: token xxxx" https://repo.prod.meissa.de/api/v1/repos/meissa-intern/meissa-io/git/commits/HEAD | jq '.sha' +# 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 diff --git a/src/main/cljc/dda/c4k_website/website.cljc b/src/main/cljc/dda/c4k_website/website.cljc index bb1d09f..f9177f0 100644 --- a/src/main/cljc/dda/c4k_website/website.cljc +++ b/src/main/cljc/dda/c4k_website/website.cljc @@ -98,6 +98,13 @@ branch string?] (str "https://" host "/api/v1/repos/" user "/" repo "/archive/" branch ".zip")) +; https://your.gitea.host/api/v1/repos///git/commits/HEAD +(defn-spec generate-gitcommiturl string? + [host pred/fqdn-string? + repo string? + user string?] + (str "https://" host "/api/v1/repos/" user "/" repo "/git/" "commits/" "HEAD")) + (defn-spec replace-all-matching-substrings-beginning-with pred/map-or-seq? [col pred/map-or-seq? value-to-partly-match string? @@ -204,10 +211,15 @@ (-> (replace-common-data "website/website-build-secret.yaml" auth) (cm/replace-all-matching-values-by-new-value "TOKEN" (b64/encode authtoken)) - (cm/replace-all-matching-values-by-new-value "URL" (b64/encode - (generate-gitrepourl + (cm/replace-all-matching-values-by-new-value "REPOURL" (b64/encode + (generate-gitrepourl gitea-host gitea-repo username - branchname)))))) + branchname))) + (cm/replace-all-matching-values-by-new-value "COMMITURL" (b64/encode + (generate-gitcommiturl + gitea-host + gitea-repo + username)))))) diff --git a/src/main/resources/website/website-build-secret.yaml b/src/main/resources/website/website-build-secret.yaml index 405eaf8..770ce10 100644 --- a/src/main/resources/website/website-build-secret.yaml +++ b/src/main/resources/website/website-build-secret.yaml @@ -6,6 +6,7 @@ metadata: app.kubernetes.part-of: NAME-website data: AUTHTOKEN: TOKEN - GITREPOURL: URL + GITREPOURL: REPOURL + GITCOMMITURL: COMMITURL \ No newline at end of file diff --git a/src/test/cljc/dda/c4k_website/website_test.cljc b/src/test/cljc/dda/c4k_website/website_test.cljc index 4989809..51facb0 100644 --- a/src/test/cljc/dda/c4k_website/website_test.cljc +++ b/src/test/cljc/dda/c4k_website/website_test.cljc @@ -214,30 +214,25 @@ :branchname "main", :unique-name "test.io"})))) + + (deftest should-generate-website-build-secret - (is (= {:name-c1 "test-io-secret", - :name-c2 "test-org-secret", - :AUTHTOKEN-c1 (b64/encode "token1"), - :AUTHTOKEN-c2 (b64/encode "token2"), - :GITREPOURL-c1 (b64/encode "https://gitlab.org/api/v1/repos/dumpty/websitebau/archive/testname.zip"), - :GITREPOURL-c2 (b64/encode "https://github.com/api/v1/repos/humpty/websitedachs/archive/testname.zip"), - :app.kubernetes.part-of-c1 "test-io-website", - :app.kubernetes.part-of-c2 "test-org-website"} - (th/map-diff (cut/generate-website-build-secret {:unique-name "test.io", - :authtoken "token1", - :gitea-host "gitlab.org", - :gitea-repo "websitebau", - :username "dumpty", - :branchname "testname", - :fqdns ["test.de" "www.test.de" "test-it.de" "www.test-it.de"]} - ) - (cut/generate-website-build-secret {:unique-name "test.org", - :authtoken "token2", - :gitea-host "github.com", - :gitea-repo "websitedachs", - :username "humpty", - :branchname "testname", - :fqdns ["test.de" "www.test.de" "test-it.de" "www.test-it.de"]}))))) + (is (= {:apiVersion "v1", + :kind "Secret", + :metadata {:name "test-io-secret", :labels {:app.kubernetes.part-of "test-io-website"}}, + :data + {:AUTHTOKEN "YWJlZGpnYmFzZG9kag==", + :GITREPOURL "aHR0cHM6Ly9naXRsYWIuZGUvYXBpL3YxL3JlcG9zL3NvbWV1c2VyL3JlcG8vYXJjaGl2ZS9tYWluLnppcA==", + :GITCOMMITURL "aHR0cHM6Ly9naXRsYWIuZGUvYXBpL3YxL3JlcG9zL3NvbWV1c2VyL3JlcG8vZ2l0L2NvbW1pdHMvSEVBRA=="}} + (cut/generate-website-build-secret {:authtoken "abedjgbasdodj", + :gitea-host "gitlab.de", + :username "someuser", + :fqdns ["test.de" "test.org" "www.test.de" "www.test.org"], + :gitea-repo "repo", + :sha256sum-output "123456789ab123cd345de script-file-name.sh", + :issuer "staging", + :branchname "main", + :unique-name "test.io"})))) (deftest should-generate-website-content-volume (is (= {:name-c1 "test-io-content-volume", From ee9e11eb042b137da66f1394565037b1a9025cc6 Mon Sep 17 00:00:00 2001 From: erik Date: Fri, 9 Dec 2022 09:50:13 +0100 Subject: [PATCH 12/15] 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 From b7b9266735abc2c361eb723795ae9054e9fab964 Mon Sep 17 00:00:00 2001 From: erik Date: Fri, 9 Dec 2022 10:49:57 +0100 Subject: [PATCH 13/15] Set up correct test for build image --- .../image/resources/entrypoint.sh | 4 +- .../c4k-website-build/test/Dockerfile | 5 +++ .../test/resources/entrypoint.sh | 36 +++++++++++++++ .../test/resources/exclude.pattern | 2 + .../test/resources/functions.sh | 45 +++++++++++++++++++ .../test/resources/install.sh | 8 ++++ .../test/resources/project.clj | 11 +++++ .../c4k-website-build/test/serverspec.edn | 7 ++- 8 files changed, 112 insertions(+), 6 deletions(-) create mode 100755 infrastructure/c4k-website-build/test/resources/entrypoint.sh create mode 100644 infrastructure/c4k-website-build/test/resources/exclude.pattern create mode 100644 infrastructure/c4k-website-build/test/resources/functions.sh create mode 100755 infrastructure/c4k-website-build/test/resources/install.sh create mode 100644 infrastructure/c4k-website-build/test/resources/project.clj diff --git a/infrastructure/c4k-website-build/image/resources/entrypoint.sh b/infrastructure/c4k-website-build/image/resources/entrypoint.sh index 871a00d..f18d5bd 100755 --- a/infrastructure/c4k-website-build/image/resources/entrypoint.sh +++ b/infrastructure/c4k-website-build/image/resources/entrypoint.sh @@ -18,8 +18,8 @@ newHash=$( get-hash-data ) if [[ $currentHash == $newHash ]] then echo "Nothing to do" - else - write-hash-data $currentHash $hashfilename + else + echo $currentHash > $HASHFILEDIR/$hashfilename echo "Downloading website data" get-website-data $filename unzip-website-data $filename diff --git a/infrastructure/c4k-website-build/test/Dockerfile b/infrastructure/c4k-website-build/test/Dockerfile index 47c3702..db96cce 100644 --- a/infrastructure/c4k-website-build/test/Dockerfile +++ b/infrastructure/c4k-website-build/test/Dockerfile @@ -1,8 +1,13 @@ FROM clojure:lein +# Prepare Entrypoint Script +ADD resources /tmp + +RUN /tmp/install.sh RUN apt update RUN apt -yqq --no-install-recommends --yes install curl default-jre-headless + RUN curl -L -o /tmp/serverspec.jar \ https://github.com/DomainDrivenArchitecture/dda-serverspec-crate/releases/download/2.0.0/dda-serverspec-standalone.jar diff --git a/infrastructure/c4k-website-build/test/resources/entrypoint.sh b/infrastructure/c4k-website-build/test/resources/entrypoint.sh new file mode 100755 index 0000000..871a00d --- /dev/null +++ b/infrastructure/c4k-website-build/test/resources/entrypoint.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +mkdir $BUILDDIR +mkdir $SOURCEDIR + +set -euo pipefail + +source /usr/local/bin/functions.sh + +filename="website.zip" +hashfilename="hashfile" + +echo "Check for new content" +touch $HASHFILEDIR/$hashfilename +currentHash=$( cat $HASHFILEDIR/$hashfilename ) +newHash=$( get-hash-data ) + +if [[ $currentHash == $newHash ]] + then + echo "Nothing to do" + 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 + echo "Building website" + build-website + echo "Moving files" + move-website-files-to-target +fi + + + + diff --git a/infrastructure/c4k-website-build/test/resources/exclude.pattern b/infrastructure/c4k-website-build/test/resources/exclude.pattern new file mode 100644 index 0000000..3978a0f --- /dev/null +++ b/infrastructure/c4k-website-build/test/resources/exclude.pattern @@ -0,0 +1,2 @@ +.git +.gitignore diff --git a/infrastructure/c4k-website-build/test/resources/functions.sh b/infrastructure/c4k-website-build/test/resources/functions.sh new file mode 100644 index 0000000..7ab68db --- /dev/null +++ b/infrastructure/c4k-website-build/test/resources/functions.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +function get-website-data() { + curl -H "Authorization: token $AUTHTOKEN" -o $SOURCEDIR/$1 $GITREPOURL +} + +function get-hash-data() { + curl -s -H "Authorization: token $AUTHTOKEN" $GITCOMMITURL | jq '.sha' +} + +function write-hash-data() { + echo $1 > $HASHFILEDIR/$2 +} + +function unzip-website-data() { + unzip $SOURCEDIR/$1 -d $BUILDDIR +} + +function execute-scripts-when-existing() { + websitedir=$(ls $BUILDDIR) + if [[ -f $BUILDDIR/$websitedir/$SCRIPTFILE ]] + then + checksum="$(sha256sum $BUILDDIR/$websitedir/$SCRIPTFILE | grep -oE "^[a-z0-9]+")" + if [[ "$SHA256SUM" == "$checksum" ]] + then + chmod +x $BUILDDIR/$websitedir/$SCRIPTFILE + (cd $BUILDDIR; dir=$(ls); cd $dir; ./$SCRIPTFILE) #make sure paths defined in scriptfile are relative to $dir + else + printf "Provided SHA256 Sum does not match calculated sum. Exiting." + printf "Calculated SHA256: $checksum" + printf "Given SHA256: $SHA256SUM" + exit 1 + fi + else + printf "No script file provided." + fi +} + +function build-website() { + (cd $BUILDDIR; dir=$(ls); cd $dir; lein run;) +} + +function move-website-files-to-target() { + (cd $BUILDDIR; dir=$(ls); cd $dir; rsync -ru --exclude-from "/etc/exclude.pattern" --delete resources/public/* $WEBSITEROOT;) +} diff --git a/infrastructure/c4k-website-build/test/resources/install.sh b/infrastructure/c4k-website-build/test/resources/install.sh new file mode 100755 index 0000000..fddcecb --- /dev/null +++ b/infrastructure/c4k-website-build/test/resources/install.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +mkdir /etc/lein/ + +install -m 0700 /tmp/entrypoint.sh / +install -m 0700 /tmp/functions.sh /usr/local/bin/ +install -m 0700 /tmp/exclude.pattern /etc/ +install -m 0700 /tmp/project.clj /etc/lein/ diff --git a/infrastructure/c4k-website-build/test/resources/project.clj b/infrastructure/c4k-website-build/test/resources/project.clj new file mode 100644 index 0000000..403046f --- /dev/null +++ b/infrastructure/c4k-website-build/test/resources/project.clj @@ -0,0 +1,11 @@ +(defproject org.domaindrivenarchitecture/c4k-website-build "0.1.1-SNAPSHOT" + :description "website c4k-build package" + :url "https://domaindrivenarchitecture.org" + :license {:name "Apache License, Version 2.0" + :url "https://www.apache.org/licenses/LICENSE-2.0.html"} + :dependencies [[org.clojure/clojure "1.9.0"] + [dda/cryogen-bootstrap "0.1.5"]] + :plugins [[lein-ring "0.12.5"]] + :main cryogen.core + :ring {:init cryogen.server/init + :handler cryogen.server/handler}) diff --git a/infrastructure/c4k-website-build/test/serverspec.edn b/infrastructure/c4k-website-build/test/serverspec.edn index 000622f..87038f9 100644 --- a/infrastructure/c4k-website-build/test/serverspec.edn +++ b/infrastructure/c4k-website-build/test/serverspec.edn @@ -1,5 +1,4 @@ -{:file [{:path "/usr/local/bin/install.sh" :mod "700"} +{:file [{:path "/entrypoint.sh" :mod "700"} {:path "/usr/local/bin/functions.sh" :mod "700"} - {:path "/usr/local/bin/exclude.pattern" :mod "700"} - {:path "/usr/local/bin/project.clj" :mod "700"} - {:path "/entrypoint.sh" :mod "700"}]} + {:path "/etc/exclude.pattern" :mod "700"} + {:path "/etc/lein/project.clj" :mod "700"}]} From 11d12bc7d0cdda88abf124328b81205c0e438e76 Mon Sep 17 00:00:00 2001 From: erik Date: Fri, 9 Dec 2022 10:49:57 +0100 Subject: [PATCH 14/15] Set up correct test for build image --- .../c4k-website-build/image/resources/entrypoint.sh | 4 ++-- infrastructure/c4k-website-build/test/Dockerfile | 2 +- infrastructure/c4k-website-build/test/serverspec.edn | 7 +++---- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/infrastructure/c4k-website-build/image/resources/entrypoint.sh b/infrastructure/c4k-website-build/image/resources/entrypoint.sh index 871a00d..f18d5bd 100755 --- a/infrastructure/c4k-website-build/image/resources/entrypoint.sh +++ b/infrastructure/c4k-website-build/image/resources/entrypoint.sh @@ -18,8 +18,8 @@ newHash=$( get-hash-data ) if [[ $currentHash == $newHash ]] then echo "Nothing to do" - else - write-hash-data $currentHash $hashfilename + else + echo $currentHash > $HASHFILEDIR/$hashfilename echo "Downloading website data" get-website-data $filename unzip-website-data $filename diff --git a/infrastructure/c4k-website-build/test/Dockerfile b/infrastructure/c4k-website-build/test/Dockerfile index 47c3702..41aadf5 100644 --- a/infrastructure/c4k-website-build/test/Dockerfile +++ b/infrastructure/c4k-website-build/test/Dockerfile @@ -1,4 +1,4 @@ -FROM clojure:lein +FROM c4k-website-build RUN apt update RUN apt -yqq --no-install-recommends --yes install curl default-jre-headless diff --git a/infrastructure/c4k-website-build/test/serverspec.edn b/infrastructure/c4k-website-build/test/serverspec.edn index 000622f..87038f9 100644 --- a/infrastructure/c4k-website-build/test/serverspec.edn +++ b/infrastructure/c4k-website-build/test/serverspec.edn @@ -1,5 +1,4 @@ -{:file [{:path "/usr/local/bin/install.sh" :mod "700"} +{:file [{:path "/entrypoint.sh" :mod "700"} {:path "/usr/local/bin/functions.sh" :mod "700"} - {:path "/usr/local/bin/exclude.pattern" :mod "700"} - {:path "/usr/local/bin/project.clj" :mod "700"} - {:path "/entrypoint.sh" :mod "700"}]} + {:path "/etc/exclude.pattern" :mod "700"} + {:path "/etc/lein/project.clj" :mod "700"}]} From acbcc4e6ab3c370eb01ab18767f3f58d81debf3f Mon Sep 17 00:00:00 2001 From: erik Date: Fri, 9 Dec 2022 12:19:38 +0100 Subject: [PATCH 15/15] [Skip-CI] Use image directly --- .../c4k-website-build/test/Dockerfile | 5 --- .../test/resources/entrypoint.sh | 36 --------------- .../test/resources/exclude.pattern | 2 - .../test/resources/functions.sh | 45 ------------------- .../test/resources/install.sh | 8 ---- .../test/resources/project.clj | 11 ----- 6 files changed, 107 deletions(-) delete mode 100755 infrastructure/c4k-website-build/test/resources/entrypoint.sh delete mode 100644 infrastructure/c4k-website-build/test/resources/exclude.pattern delete mode 100644 infrastructure/c4k-website-build/test/resources/functions.sh delete mode 100755 infrastructure/c4k-website-build/test/resources/install.sh delete mode 100644 infrastructure/c4k-website-build/test/resources/project.clj diff --git a/infrastructure/c4k-website-build/test/Dockerfile b/infrastructure/c4k-website-build/test/Dockerfile index d92d6c3..41aadf5 100644 --- a/infrastructure/c4k-website-build/test/Dockerfile +++ b/infrastructure/c4k-website-build/test/Dockerfile @@ -1,13 +1,8 @@ FROM c4k-website-build -# Prepare Entrypoint Script -ADD resources /tmp - -RUN /tmp/install.sh RUN apt update RUN apt -yqq --no-install-recommends --yes install curl default-jre-headless - RUN curl -L -o /tmp/serverspec.jar \ https://github.com/DomainDrivenArchitecture/dda-serverspec-crate/releases/download/2.0.0/dda-serverspec-standalone.jar diff --git a/infrastructure/c4k-website-build/test/resources/entrypoint.sh b/infrastructure/c4k-website-build/test/resources/entrypoint.sh deleted file mode 100755 index 871a00d..0000000 --- a/infrastructure/c4k-website-build/test/resources/entrypoint.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/bash - -mkdir $BUILDDIR -mkdir $SOURCEDIR - -set -euo pipefail - -source /usr/local/bin/functions.sh - -filename="website.zip" -hashfilename="hashfile" - -echo "Check for new content" -touch $HASHFILEDIR/$hashfilename -currentHash=$( cat $HASHFILEDIR/$hashfilename ) -newHash=$( get-hash-data ) - -if [[ $currentHash == $newHash ]] - then - echo "Nothing to do" - 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 - echo "Building website" - build-website - echo "Moving files" - move-website-files-to-target -fi - - - - diff --git a/infrastructure/c4k-website-build/test/resources/exclude.pattern b/infrastructure/c4k-website-build/test/resources/exclude.pattern deleted file mode 100644 index 3978a0f..0000000 --- a/infrastructure/c4k-website-build/test/resources/exclude.pattern +++ /dev/null @@ -1,2 +0,0 @@ -.git -.gitignore diff --git a/infrastructure/c4k-website-build/test/resources/functions.sh b/infrastructure/c4k-website-build/test/resources/functions.sh deleted file mode 100644 index 7ab68db..0000000 --- a/infrastructure/c4k-website-build/test/resources/functions.sh +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/bash - -function get-website-data() { - curl -H "Authorization: token $AUTHTOKEN" -o $SOURCEDIR/$1 $GITREPOURL -} - -function get-hash-data() { - curl -s -H "Authorization: token $AUTHTOKEN" $GITCOMMITURL | jq '.sha' -} - -function write-hash-data() { - echo $1 > $HASHFILEDIR/$2 -} - -function unzip-website-data() { - unzip $SOURCEDIR/$1 -d $BUILDDIR -} - -function execute-scripts-when-existing() { - websitedir=$(ls $BUILDDIR) - if [[ -f $BUILDDIR/$websitedir/$SCRIPTFILE ]] - then - checksum="$(sha256sum $BUILDDIR/$websitedir/$SCRIPTFILE | grep -oE "^[a-z0-9]+")" - if [[ "$SHA256SUM" == "$checksum" ]] - then - chmod +x $BUILDDIR/$websitedir/$SCRIPTFILE - (cd $BUILDDIR; dir=$(ls); cd $dir; ./$SCRIPTFILE) #make sure paths defined in scriptfile are relative to $dir - else - printf "Provided SHA256 Sum does not match calculated sum. Exiting." - printf "Calculated SHA256: $checksum" - printf "Given SHA256: $SHA256SUM" - exit 1 - fi - else - printf "No script file provided." - fi -} - -function build-website() { - (cd $BUILDDIR; dir=$(ls); cd $dir; lein run;) -} - -function move-website-files-to-target() { - (cd $BUILDDIR; dir=$(ls); cd $dir; rsync -ru --exclude-from "/etc/exclude.pattern" --delete resources/public/* $WEBSITEROOT;) -} diff --git a/infrastructure/c4k-website-build/test/resources/install.sh b/infrastructure/c4k-website-build/test/resources/install.sh deleted file mode 100755 index fddcecb..0000000 --- a/infrastructure/c4k-website-build/test/resources/install.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash - -mkdir /etc/lein/ - -install -m 0700 /tmp/entrypoint.sh / -install -m 0700 /tmp/functions.sh /usr/local/bin/ -install -m 0700 /tmp/exclude.pattern /etc/ -install -m 0700 /tmp/project.clj /etc/lein/ diff --git a/infrastructure/c4k-website-build/test/resources/project.clj b/infrastructure/c4k-website-build/test/resources/project.clj deleted file mode 100644 index 403046f..0000000 --- a/infrastructure/c4k-website-build/test/resources/project.clj +++ /dev/null @@ -1,11 +0,0 @@ -(defproject org.domaindrivenarchitecture/c4k-website-build "0.1.1-SNAPSHOT" - :description "website c4k-build package" - :url "https://domaindrivenarchitecture.org" - :license {:name "Apache License, Version 2.0" - :url "https://www.apache.org/licenses/LICENSE-2.0.html"} - :dependencies [[org.clojure/clojure "1.9.0"] - [dda/cryogen-bootstrap "0.1.5"]] - :plugins [[lein-ring "0.12.5"]] - :main cryogen.core - :ring {:init cryogen.server/init - :handler cryogen.server/handler})