From eaf06724e47bd3692a3f02a49f2719a4efd9822f Mon Sep 17 00:00:00 2001 From: Clemens Date: Mon, 8 Jul 2024 08:28:14 +0200 Subject: [PATCH] added option to override image-version tag --- src/main/cljc/dda/c4k_forgejo/core.cljc | 1 + src/main/cljc/dda/c4k_forgejo/forgejo.cljc | 23 +++++++---- .../cljc/dda/c4k_forgejo/forgejo_test.cljc | 39 +++++++++++++++++-- 3 files changed, 53 insertions(+), 10 deletions(-) diff --git a/src/main/cljc/dda/c4k_forgejo/core.cljc b/src/main/cljc/dda/c4k_forgejo/core.cljc index ef5c407..e190e35 100644 --- a/src/main/cljc/dda/c4k_forgejo/core.cljc +++ b/src/main/cljc/dda/c4k_forgejo/core.cljc @@ -20,6 +20,7 @@ ::forgejo/deploy-federated ::forgejo/default-app-name ::forgejo/service-domain-whitelist + ::forgejo/forgejo-image-version-overwrite ::backup/restic-repository ::mon/mon-cfg])) diff --git a/src/main/cljc/dda/c4k_forgejo/forgejo.cljc b/src/main/cljc/dda/c4k_forgejo/forgejo.cljc index 7d2a5fb..b9de1f8 100644 --- a/src/main/cljc/dda/c4k_forgejo/forgejo.cljc +++ b/src/main/cljc/dda/c4k_forgejo/forgejo.cljc @@ -38,6 +38,7 @@ (s/def ::mailer-port pred/bash-env-string?) (s/def ::service-domain-whitelist domain-list?) (s/def ::service-noreply-address string?) +(s/def ::forgejo-image-version-overwrite string?) (s/def ::mailer-user pred/bash-env-string?) (s/def ::mailer-pw pred/bash-env-string?) (s/def ::issuer pred/letsencrypt-issuer?) @@ -53,7 +54,8 @@ :opt-un [::issuer ::deploy-federated ::default-app-name - ::service-domain-whitelist])) + ::service-domain-whitelist + ::forgejo-image-version-overwrite])) (def rate-limit-config? (s/keys :req-un [::max-rate ::max-concurrent-requests])) @@ -66,8 +68,18 @@ [total] total) -(def federated-image-name "domaindrivenarchitecture/c4k-forgejo-federated:latest") -(def non-federated-image-name "codeberg.org/forgejo/forgejo:1.19") +(def federated-image-name "domaindrivenarchitecture/c4k-forgejo-federated") +(def federated-image-version "latest") +(def non-federated-image-name "codeberg.org/forgejo/forgejo") +(def non-federated-image-version "1.19") + +(defn-spec generate-image-str string? + [config config?] + (let [{:keys [deploy-federated forgejo-image-version-overwrite]} config + deploy-federated-bool (boolean-from-string deploy-federated)] + (if deploy-federated-bool + (str federated-image-name ":" (or forgejo-image-version-overwrite federated-image-version)) + (str non-federated-image-name ":" (or forgejo-image-version-overwrite non-federated-image-version))))) #?(:cljs (defmethod yaml/load-resource :forgejo [resource-name] @@ -158,10 +170,7 @@ deploy-federated-bool (boolean-from-string deploy-federated)] (-> (yaml/load-as-edn "forgejo/deployment.yaml") - (cm/replace-all-matching-values-by-new-value "IMAGE_NAME" - (if deploy-federated-bool - federated-image-name - non-federated-image-name))))) + (cm/replace-all-matching-values-by-new-value "IMAGE_NAME" (generate-image-str config))))) (defn generate-service [] diff --git a/src/test/cljc/dda/c4k_forgejo/forgejo_test.cljc b/src/test/cljc/dda/c4k_forgejo/forgejo_test.cljc index 54a6070..663793c 100644 --- a/src/test/cljc/dda/c4k_forgejo/forgejo_test.cljc +++ b/src/test/cljc/dda/c4k_forgejo/forgejo_test.cljc @@ -12,6 +12,40 @@ (st/instrument `cut/generate-ingress) (st/instrument `cut/generate-secrets) +(deftest should-generate-image-str + (testing "non-federated-image" + (is (= "codeberg.org/forgejo/forgejo:1.19" + (cut/generate-image-str {:fqdn "test.de" + :mailer-from "" + :mailer-host "m.t.de" + :mailer-port "123" + :service-noreply-address "" + :deploy-federated "false"}))) + (is (= "codeberg.org/forgejo/forgejo:1.19.3-0" + (cut/generate-image-str {:fqdn "test.de" + :mailer-from "" + :mailer-host "m.t.de" + :mailer-port "123" + :service-noreply-address "" + :deploy-federated "false" + :forgejo-image-version-overwrite "1.19.3-0"})))) + (testing "federated-image" + (is (= "domaindrivenarchitecture/c4k-forgejo-federated:latest" + (cut/generate-image-str {:fqdn "test.de" + :mailer-from "" + :mailer-host "m.t.de" + :mailer-port "123" + :service-noreply-address "" + :deploy-federated "true"}))) + (is (= "domaindrivenarchitecture/c4k-forgejo-federated:3.2.0" + (cut/generate-image-str {:fqdn "test.de" + :mailer-from "" + :mailer-host "m.t.de" + :mailer-port "123" + :service-noreply-address "" + :deploy-federated "true" + :forgejo-image-version-overwrite "3.2.0"}))))) + (deftest should-generate-appini-env (is (= {:APP_NAME-c1 "", :APP_NAME-c2 "test forgejo", @@ -35,13 +69,12 @@ :FORGEJO__service__NO_REPLY_ADDRESS-c2 "noreply@test.com"} (th/map-diff (cut/generate-appini-env {:default-app-name "" :deploy-federated "false" - :fqdn "test.de" + :fqdn "test.de" :mailer-from "" :mailer-host "m.t.de" :mailer-port "123" :service-domain-whitelist "adb.de" - :service-noreply-address "" - }) + :service-noreply-address ""}) (cut/generate-appini-env {:default-app-name "test forgejo" :deploy-federated "true" :fqdn "test.com"