From 46f0c72c3eb163ca8ee8367c1c0b62dfbe381d5e Mon Sep 17 00:00:00 2001 From: erik Date: Wed, 28 Sep 2022 14:32:41 +0200 Subject: [PATCH] [Skip-Ci] Update Docker image, cron job, tests It seems, timeout sends signals that do not stop the server process. Set the signal to SIGKILL - which also kills the function.sh process. Thus moved the last function to entrypoint.sh --- .../c4k-website-build/image/Dockerfile | 6 ++---- .../image/resources/entrypoint.sh | 16 +++++++++++----- .../image/resources/functions.sh | 15 +++++---------- src/main/cljc/dda/c4k_website/website.cljc | 8 +++++--- src/main/resources/website/nginx-deployment.yaml | 2 +- .../resources/website/website-build-cron.yaml | 7 +++++-- .../website/website-build-deployment.yaml | 5 ++++- src/test/cljc/dda/c4k_website/website_test.cljc | 10 ++++++---- 8 files changed, 39 insertions(+), 30 deletions(-) diff --git a/infrastructure/c4k-website-build/image/Dockerfile b/infrastructure/c4k-website-build/image/Dockerfile index f922c8f..270be95 100644 --- a/infrastructure/c4k-website-build/image/Dockerfile +++ b/infrastructure/c4k-website-build/image/Dockerfile @@ -3,10 +3,8 @@ FROM clojure:lein # Prepare Entrypoint Script ADD resources /tmp -ENV BUILDDIR="website" +ENV SOURCEDIR="/etc/websitesource" +ENV BUILDDIR="/etc/website" ENV WEBSITEROOT="/var/www/html/website/" RUN /tmp/install.sh -#RUN /tmp/entrypoint.sh - -# ToDo: lein not working on clojure image? \ No newline at end of file diff --git a/infrastructure/c4k-website-build/image/resources/entrypoint.sh b/infrastructure/c4k-website-build/image/resources/entrypoint.sh index 4a4da8e..858eb05 100755 --- a/infrastructure/c4k-website-build/image/resources/entrypoint.sh +++ b/infrastructure/c4k-website-build/image/resources/entrypoint.sh @@ -1,14 +1,20 @@ #!/bin/bash +mkdir $BUILDDIR +mkdir $SOURCEDIR + source /usr/local/bin/functions.sh -function main() { - get-and-unzip-website-data - build-and-extract-website - move-website-files-to-target +function move-website-files-to-target() { + (cd $BUILDDIR; dir=$(ls); cd $dir; rsync -ru --exclude-from "/etc/exclude.pattern" --delete resources/public/* $WEBSITEROOT;) } -main +echo "Downloading website" +get-and-unzip-website-data +echo "Building website" +build-and-extract-website +echo "Moving files" +move-website-files-to-target while true; do sleep 1m diff --git a/infrastructure/c4k-website-build/image/resources/functions.sh b/infrastructure/c4k-website-build/image/resources/functions.sh index db40a61..e906dea 100644 --- a/infrastructure/c4k-website-build/image/resources/functions.sh +++ b/infrastructure/c4k-website-build/image/resources/functions.sh @@ -1,17 +1,12 @@ #!/bin/bash function get-and-unzip-website-data() { - curl -H "Authorization: token $AUTHTOKEN" -O $GITREPOURL # GITREPURL = https://your.gitea.host/api/v1/repos///archive/main.zip - mkdir $BUILDDIR - unzip main.zip -D $BUILDDIR + filename="website.zip" + curl -H "Authorization: token $AUTHTOKEN" -o $SOURCEDIR/$filename $GITREPOURL # GITREPURL = https://your.gitea.host/api/v1/repos///archive/main.zip + unzip $SOURCEDIR/$filename -d $BUILDDIR } function build-and-extract-website() { - (cd $BUILDDIR; lein ring war; websiteartifactname=$(ls | grep -o *.war); unzip target/$websiteartifactname "WEB-INF/classes/public/*") -} - -# set variables from environment -# read write zugriff sicherstellen -function move-website-files-to-target() { - rsync -ru --exclude-from "/etc/exclude.pattern" --delete WEB-INF/classes/public/* $TARGETDIR + (cd $BUILDDIR; dir=$(ls); cd $dir; timeout -s SIGKILL 35s lein ring server-headless;) + # websiteartifactname=$(ls target/ | grep -Eo "*.+\.war"); unzip target/$websiteartifactname } diff --git a/src/main/cljc/dda/c4k_website/website.cljc b/src/main/cljc/dda/c4k_website/website.cljc index dd01cb6..e2b8316 100644 --- a/src/main/cljc/dda/c4k_website/website.cljc +++ b/src/main/cljc/dda/c4k_website/website.cljc @@ -28,7 +28,7 @@ (def config? (s/keys :req-un [::fqdn] :opt-un [::issuer])) -(def auth? (s/keys :req-un [::token ::url])) +(def auth? (s/keys :req-un [::authtoken ::gitrepourl])) (def vol? (s/keys :req-un [::volume-total-storage-size ::number-of-websites])) @@ -125,14 +125,16 @@ (let [{:keys [fqdn]} config] (-> (yaml/load-as-edn "website/website-build-cron.yaml") - (replace-all-matching-subvalues-in-string-start "NAME" (unique-name-from-fqdn fqdn))))) + (replace-all-matching-subvalues-in-string-start "NAME" (unique-name-from-fqdn fqdn)) + (cm/replace-all-matching-values-by-new-value "FQDN" fqdn)))) (defn-spec generate-website-build-deployment pred/map-or-seq? [config config?] (let [{:keys [fqdn]} config] (-> (yaml/load-as-edn "website/website-build-deployment.yaml") - (replace-all-matching-subvalues-in-string-start "NAME" (unique-name-from-fqdn fqdn))))) + (replace-all-matching-subvalues-in-string-start "NAME" (unique-name-from-fqdn fqdn)) + (cm/replace-all-matching-values-by-new-value "FQDN" fqdn)))) (defn-spec generate-website-build-secret pred/map-or-seq? [auth auth?] diff --git a/src/main/resources/website/nginx-deployment.yaml b/src/main/resources/website/nginx-deployment.yaml index bce23a3..5d1fbcd 100644 --- a/src/main/resources/website/nginx-deployment.yaml +++ b/src/main/resources/website/nginx-deployment.yaml @@ -44,7 +44,7 @@ spec: emptyDir: {} - name: website-content-volume persistentVolumeClaim: - claimName: NAME-content-pvc + claimName: NAME-content-volume - name: website-cert secret: secretName: NAME-cert diff --git a/src/main/resources/website/website-build-cron.yaml b/src/main/resources/website/website-build-cron.yaml index 356c82b..920c715 100644 --- a/src/main/resources/website/website-build-cron.yaml +++ b/src/main/resources/website/website-build-cron.yaml @@ -5,7 +5,7 @@ metadata: labels: app.kubernetes.part-of: website # correct name? spec: - schedule: "10 23 * * *" + schedule: "1,7,14,21,28,35,42,49,54,59 * * * *" successfulJobsHistoryLimit: 1 failedJobsHistoryLimit: 1 jobTemplate: @@ -17,6 +17,9 @@ spec: name: NAME-build-app imagePullPolicy: IfNotPresent command: ["/entrypoint.sh"] + env: + - name: HOSTADRESS + value: FQDN envFrom: - secretRef: name: NAME-secret @@ -26,5 +29,5 @@ spec: volumes: - name: content-volume persistentVolumeClaim: - claimName: NAME-content-pvc + claimName: NAME-content-volume restartPolicy: OnFailure \ No newline at end of file diff --git a/src/main/resources/website/website-build-deployment.yaml b/src/main/resources/website/website-build-deployment.yaml index a1f9831..533aaf6 100644 --- a/src/main/resources/website/website-build-deployment.yaml +++ b/src/main/resources/website/website-build-deployment.yaml @@ -21,6 +21,9 @@ spec: name: NAME-build-app imagePullPolicy: IfNotPresent command: ["/entrypoint.sh"] + env: + - name: HOSTADRESS + value: FQDN envFrom: - secretRef: name: NAME-secret @@ -30,4 +33,4 @@ spec: volumes: - name: content-volume persistentVolumeClaim: - claimName: NAME-content-pvc + claimName: NAME-content-volume diff --git a/src/test/cljc/dda/c4k_website/website_test.cljc b/src/test/cljc/dda/c4k_website/website_test.cljc index a1f4571..5edddcb 100644 --- a/src/test/cljc/dda/c4k_website/website_test.cljc +++ b/src/test/cljc/dda/c4k_website/website_test.cljc @@ -74,7 +74,7 @@ {:key "website.conf", :path "conf.d/website.conf"} {:key "mime.types", :path "mime.types"}]}} {:name "log", :emptyDir {}} - {:name "website-content-volume", :persistentVolumeClaim {:claimName "test-de-content-pvc"}} + {:name "website-content-volume", :persistentVolumeClaim {:claimName "test-de-content-volume"}} {:name "website-cert", :secret {:secretName "test-de-cert", :items [{:key "tls.crt", :path "tls.crt"} {:key "tls.key", :path "tls.key"}]}}]}}}} @@ -94,7 +94,7 @@ :kind "CronJob", :metadata {:name "test-de-build-cron", :labels {:app.kubernetes.part-of "website"}}, :spec - {:schedule "10 23 * * *", + {:schedule "1,7,14,21,28,35,42,49,54,59 * * * *", :successfulJobsHistoryLimit 1, :failedJobsHistoryLimit 1, :jobTemplate @@ -106,9 +106,10 @@ :name "test-de-build-app", :imagePullPolicy "IfNotPresent", :command ["/entrypoint.sh"], + :env [{:name "HOSTADRESS", :value "test.de"}], :envFrom [{:secretRef {:name "test-de-secret"}}], :volumeMounts [{:name "content-volume", :mountPath "/var/www/html/website"}]}], - :volumes [{:name "content-volume", :persistentVolumeClaim {:claimName "test-de-content-pvc"}}], + :volumes [{:name "content-volume", :persistentVolumeClaim {:claimName "test-de-content-volume"}}], :restartPolicy "OnFailure"}}}}}} (cut/generate-website-build-cron {:fqdn "test.de"})))) @@ -129,9 +130,10 @@ :name "test-de-build-app", :imagePullPolicy "IfNotPresent", :command ["/entrypoint.sh"], + :env [{:name "HOSTADRESS", :value "test.de"}], :envFrom [{:secretRef {:name "test-de-secret"}}], :volumeMounts [{:name "content-volume", :mountPath "/var/www/html/website"}]}], - :volumes [{:name "content-volume", :persistentVolumeClaim {:claimName "test-de-content-pvc"}}]}}}} + :volumes [{:name "content-volume", :persistentVolumeClaim {:claimName "test-de-content-volume"}}]}}}} (cut/generate-website-build-deployment {:fqdn "test.de"})))) (deftest should-generate-website-build-secret