From 287d6d31c569aef90c0c37545a345191749307ba Mon Sep 17 00:00:00 2001 From: erik Date: Tue, 8 Nov 2022 16:23:10 +0100 Subject: [PATCH] Add initial build job so websites get build early --- README.md | 2 +- src/main/cljc/dda/c4k_website/core.cljc | 1 + src/main/cljc/dda/c4k_website/website.cljc | 9 +++++++ .../website/website-initial-build-job.yaml | 26 +++++++++++++++++++ .../cljc/dda/c4k_website/website_test.cljc | 25 ++++++++++++++++++ 5 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 src/main/resources/website/website-initial-build-job.yaml diff --git a/README.md b/README.md index af61d63..5749416 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # convention 4 kubernetes: c4k-website -[![Clojars Project](https://img.shields.io/clojars/v/org.domaindrivenarchitecture/c4k-gitea.svg)](https://clojars.org/org.domaindrivenarchitecture/c4k-website) [![pipeline status](https://gitlab.com/domaindrivenarchitecture/c4k-website/badges/master/pipeline.svg)](https://gitlab.com/domaindrivenarchitecture/c4k-website/-/commits/main) +[![Clojars Project](https://img.shields.io/clojars/v/org.domaindrivenarchitecture/c4k-website.svg)](https://clojars.org/org.domaindrivenarchitecture/c4k-website) [![pipeline status](https://gitlab.com/domaindrivenarchitecture/c4k-website/badges/master/pipeline.svg)](https://gitlab.com/domaindrivenarchitecture/c4k-website/-/commits/main) [DeltaChat chat over e-mail](mailto:buero@meissa-gmbh.de?subject=community-chat) | [team@social.meissa-gmbh.de team@social.meissa-gmbh.de](https://social.meissa-gmbh.de/@team) | [Website & Blog](https://domaindrivenarchitecture.org) diff --git a/src/main/cljc/dda/c4k_website/core.cljc b/src/main/cljc/dda/c4k_website/core.cljc index 3d3c70b..511d196 100644 --- a/src/main/cljc/dda/c4k_website/core.cljc +++ b/src/main/cljc/dda/c4k_website/core.cljc @@ -49,6 +49,7 @@ (website/generate-website-https-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)) + (website/generate-website-initial-build-job (flatten-and-reduce-config config)) (website/generate-website-build-secret (flatten-and-reduce-config config))))))) (defn k8s-objects [config] diff --git a/src/main/cljc/dda/c4k_website/website.cljc b/src/main/cljc/dda/c4k_website/website.cljc index 8d3a4e5..31dbf69 100644 --- a/src/main/cljc/dda/c4k_website/website.cljc +++ b/src/main/cljc/dda/c4k_website/website.cljc @@ -91,6 +91,7 @@ "website/nginx-deployment.yaml" (rc/inline "website/nginx-deployment.yaml") "website/nginx-service.yaml" (rc/inline "website/nginx-service.yaml") "website/website-build-cron.yaml" (rc/inline "website/website-build-cron.yaml") + "website/website-initial-build-job.yaml" (rc/inline "website/website-initial-build-job.yaml") "website/website-build-deployment.yaml" (rc/inline "website/website-build-deployment.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") @@ -170,6 +171,14 @@ (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))))) +(defn-spec generate-website-initial-build-job pred/map-or-seq? + [config flattened-and-reduced-config?] + (let [{:keys [unique-name]} config] + (-> + (yaml/load-as-edn "website/website-initial-build-job.yaml") + (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))))) + (defn-spec generate-website-build-deployment pred/map-or-seq? [config flattened-and-reduced-config?] (let [{:keys [unique-name]} config] diff --git a/src/main/resources/website/website-initial-build-job.yaml b/src/main/resources/website/website-initial-build-job.yaml new file mode 100644 index 0000000..a66d461 --- /dev/null +++ b/src/main/resources/website/website-initial-build-job.yaml @@ -0,0 +1,26 @@ +apiVersion: batch/v1 +kind: Job +metadata: + name: NAME-initial-build-job + labels: + app.kubernetes.part-of: NAME-website +spec: + template: + spec: + containers: + - image: domaindrivenarchitecture/c4k-website-build + name: NAME-build-app + imagePullPolicy: IfNotPresent + command: ["/entrypoint.sh"] + envFrom: + - secretRef: + name: NAME-secret + volumeMounts: + - name: content-volume + mountPath: /var/www/html/website + volumes: + - name: content-volume + persistentVolumeClaim: + claimName: NAME-content-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 2f87f1c..33bba0e 100644 --- a/src/test/cljc/dda/c4k_website/website_test.cljc +++ b/src/test/cljc/dda/c4k_website/website_test.cljc @@ -200,6 +200,31 @@ :username "someuser" :authtoken "abedjgbasdodj"})))) +(deftest should-generate-website-initial-build-job + (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"}}], + :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 {:unique-name "test.io", + :fqdns ["test.de" "test.org" "www.test.de" "www.test.org"], + :gitea-host "gitlab.de", + :gitea-repo "repo", + :branchname "main", + :username "someuser", + :authtoken "abedjgbasdodj", + :issuer "staging"})))) + (deftest should-generate-website-build-secret (is (= {:name-c1 "test-io-secret", :name-c2 "test-org-secret",