From a1f24d9dfea253824550be7b89cdccc602f54618 Mon Sep 17 00:00:00 2001 From: erik Date: Tue, 24 Oct 2023 14:36:54 +0200 Subject: [PATCH 1/8] [Skip-CI] Add ToDo --- infrastructure/backup/image/resources/restore.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/infrastructure/backup/image/resources/restore.sh b/infrastructure/backup/image/resources/restore.sh index 6ed2fc0..92c16ca 100755 --- a/infrastructure/backup/image/resources/restore.sh +++ b/infrastructure/backup/image/resources/restore.sh @@ -12,13 +12,12 @@ function main() { file_env POSTGRES_USER # Restore latest snapshot into /var/backups/restore - rm -rf /var/backups/restore restore-directory '/var/backups/restore' rm -rf /var/backups/gitea/* rm -rf /var/backups/git/repositories/* - cp -r /var/backups/restore/gitea /var/backups/ - cp -r /var/backups/restore/git/repositories /var/backups/git/ + cp -r /var/backups/restore/gitea /var/backups/ #ToDo: mv instead of cp or rm -rf after + cp -r /var/backups/restore/git/repositories /var/backups/git/ #ToDo: mv instead of cp or rm -rf after # adjust file permissions for the git user chown -R 1000:1000 /var/backups From 23cf8f381a5e9c6d685bfef1ab10bc451c3bb368 Mon Sep 17 00:00:00 2001 From: Michael Jerger Date: Fri, 3 Nov 2023 11:13:23 +0100 Subject: [PATCH 2/8] fail on install error --- infrastructure/backup/image/resources/backup.sh | 2 +- infrastructure/backup/image/resources/init.sh | 2 ++ infrastructure/backup/image/resources/install.sh | 2 ++ infrastructure/backup/image/resources/restic-snapshots.sh | 2 +- infrastructure/backup/image/resources/restore.sh | 2 +- 5 files changed, 7 insertions(+), 3 deletions(-) diff --git a/infrastructure/backup/image/resources/backup.sh b/infrastructure/backup/image/resources/backup.sh index d2549fd..f4f0ce6 100755 --- a/infrastructure/backup/image/resources/backup.sh +++ b/infrastructure/backup/image/resources/backup.sh @@ -1,6 +1,6 @@ #!/bin/bash -set -o pipefail +set -eux pipefail function main() { file_env AWS_ACCESS_KEY_ID diff --git a/infrastructure/backup/image/resources/init.sh b/infrastructure/backup/image/resources/init.sh index 1f47fa5..5def4aa 100755 --- a/infrastructure/backup/image/resources/init.sh +++ b/infrastructure/backup/image/resources/init.sh @@ -1,5 +1,7 @@ #!/bin/bash +set -eux pipefail + function main() { file_env AWS_ACCESS_KEY_ID file_env AWS_SECRET_ACCESS_KEY diff --git a/infrastructure/backup/image/resources/install.sh b/infrastructure/backup/image/resources/install.sh index 1a8cbd7..b366fbf 100755 --- a/infrastructure/backup/image/resources/install.sh +++ b/infrastructure/backup/image/resources/install.sh @@ -1,5 +1,7 @@ #!/bin/bash +set -eux pipefail + apt-get update > /dev/null; install -m 0700 /tmp/entrypoint.sh / diff --git a/infrastructure/backup/image/resources/restic-snapshots.sh b/infrastructure/backup/image/resources/restic-snapshots.sh index 1d97a2c..0190e5b 100755 --- a/infrastructure/backup/image/resources/restic-snapshots.sh +++ b/infrastructure/backup/image/resources/restic-snapshots.sh @@ -1,6 +1,6 @@ #!/bin/bash -set -o pipefail +set -eux pipefail function main() { file_env AWS_ACCESS_KEY_ID diff --git a/infrastructure/backup/image/resources/restore.sh b/infrastructure/backup/image/resources/restore.sh index 92c16ca..d40772c 100755 --- a/infrastructure/backup/image/resources/restore.sh +++ b/infrastructure/backup/image/resources/restore.sh @@ -1,6 +1,6 @@ #!/bin/bash -set -Eeo pipefail +set -eux pipefail function main() { From 6921ce1e8d1ad7473e66f0df47c7ecb276bb11e2 Mon Sep 17 00:00:00 2001 From: Michael Jerger Date: Fri, 15 Dec 2023 16:24:59 +0100 Subject: [PATCH 3/8] update libs --- project.clj | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/project.clj b/project.clj index 7aa19ee..10c9072 100644 --- a/project.clj +++ b/project.clj @@ -4,8 +4,8 @@ :license {:name "Apache License, Version 2.0" :url "https://www.apache.org/licenses/LICENSE-2.0.html"} :dependencies [[org.clojure/clojure "1.11.1" :scope "provided"] - [org.clojure/tools.reader "1.3.6"] - [org.domaindrivenarchitecture/c4k-common-clj "6.0.3"] + [org.clojure/tools.reader "1.3.7"] + [org.domaindrivenarchitecture/c4k-common-clj "6.1.0"] [hickory "0.7.1"]] :target-path "target/%s/" :source-paths ["src/main/cljc" @@ -23,7 +23,7 @@ :main dda.c4k-forgejo.uberjar :uberjar-name "c4k-forgejo-standalone.jar" :dependencies [[org.clojure/tools.cli "1.0.219"] - [ch.qos.logback/logback-classic "1.4.11" + [ch.qos.logback/logback-classic "1.4.14" :exclusions [com.sun.mail/javax.mail]] [org.slf4j/jcl-over-slf4j "2.0.9"]]}} :release-tasks [["test"] From 14456407d9ef7b6c18a29766368a26c1743ad1a9 Mon Sep 17 00:00:00 2001 From: Michael Jerger Date: Fri, 15 Dec 2023 16:26:18 +0100 Subject: [PATCH 4/8] release: 3.0.6 --- infrastructure/backup/build.py | 2 +- infrastructure/federated/build.py | 2 +- package.json | 2 +- project.clj | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/infrastructure/backup/build.py b/infrastructure/backup/build.py index 674f169..c13411e 100644 --- a/infrastructure/backup/build.py +++ b/infrastructure/backup/build.py @@ -6,7 +6,7 @@ from ddadevops import * name = "c4k-forgejo" MODULE = "backup" PROJECT_ROOT_PATH = "../.." -version = "3.0.6-SNAPSHOT" +version = "3.0.6" @init diff --git a/infrastructure/federated/build.py b/infrastructure/federated/build.py index c793655..8fe6ae6 100644 --- a/infrastructure/federated/build.py +++ b/infrastructure/federated/build.py @@ -6,7 +6,7 @@ from ddadevops import * name = 'c4k-forgejo' MODULE = 'federated' PROJECT_ROOT_PATH = '../..' -version = "3.0.6-SNAPSHOT" +version = "3.0.6" @init def initialize(project): diff --git a/package.json b/package.json index 43b52db..019bbb7 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "c4k-forgejo", "description": "Generate c4k yaml for a forgejo deployment.", "author": "meissa GmbH", - "version": "3.0.6-SNAPSHOT", + "version": "3.0.6", "homepage": "https://gitlab.com/domaindrivenarchitecture/c4k-forgejo#readme", "repository": "https://www.npmjs.com/package/c4k-forgejo", "license": "APACHE2", diff --git a/project.clj b/project.clj index 10c9072..f089196 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject org.domaindrivenarchitecture/c4k-forgejo "3.0.6-SNAPSHOT" +(defproject org.domaindrivenarchitecture/c4k-forgejo "3.0.6" :description "forgejo c4k-installation package" :url "https://domaindrivenarchitecture.org" :license {:name "Apache License, Version 2.0" From 831f71f9164994cd61c10df7c94b0fa1523d03cc Mon Sep 17 00:00:00 2001 From: Michael Jerger Date: Fri, 15 Dec 2023 16:26:18 +0100 Subject: [PATCH 5/8] bump version to: 3.0.7-SNAPSHOT --- infrastructure/backup/build.py | 2 +- infrastructure/federated/build.py | 2 +- package.json | 2 +- project.clj | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/infrastructure/backup/build.py b/infrastructure/backup/build.py index c13411e..207ef81 100644 --- a/infrastructure/backup/build.py +++ b/infrastructure/backup/build.py @@ -6,7 +6,7 @@ from ddadevops import * name = "c4k-forgejo" MODULE = "backup" PROJECT_ROOT_PATH = "../.." -version = "3.0.6" +version = "3.0.7-SNAPSHOT" @init diff --git a/infrastructure/federated/build.py b/infrastructure/federated/build.py index 8fe6ae6..c120a5a 100644 --- a/infrastructure/federated/build.py +++ b/infrastructure/federated/build.py @@ -6,7 +6,7 @@ from ddadevops import * name = 'c4k-forgejo' MODULE = 'federated' PROJECT_ROOT_PATH = '../..' -version = "3.0.6" +version = "3.0.7-SNAPSHOT" @init def initialize(project): diff --git a/package.json b/package.json index 019bbb7..9b52e1c 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "c4k-forgejo", "description": "Generate c4k yaml for a forgejo deployment.", "author": "meissa GmbH", - "version": "3.0.6", + "version": "3.0.7-SNAPSHOT", "homepage": "https://gitlab.com/domaindrivenarchitecture/c4k-forgejo#readme", "repository": "https://www.npmjs.com/package/c4k-forgejo", "license": "APACHE2", diff --git a/project.clj b/project.clj index f089196..10b353b 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject org.domaindrivenarchitecture/c4k-forgejo "3.0.6" +(defproject org.domaindrivenarchitecture/c4k-forgejo "3.0.7-SNAPSHOT" :description "forgejo c4k-installation package" :url "https://domaindrivenarchitecture.org" :license {:name "Apache License, Version 2.0" From 73f98a768fd3417b99eb729c5a7c34af5d321e76 Mon Sep 17 00:00:00 2001 From: Michael Jerger Date: Fri, 15 Dec 2023 16:58:48 +0100 Subject: [PATCH 6/8] use our federated dev branch --- infrastructure/federated/image/Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/infrastructure/federated/image/Dockerfile b/infrastructure/federated/image/Dockerfile index 4a82745..92788f2 100644 --- a/infrastructure/federated/image/Dockerfile +++ b/infrastructure/federated/image/Dockerfile @@ -9,9 +9,9 @@ ARG TAGS="sqlite sqlite_unlock_notify" ENV TAGS "bindata timetzdata $TAGS" ARG CGO_EXTRA_CFLAGS -ENV FORGEJO_GIT_URL "https://codeberg.org/forgejo/forgejo.git" +ENV FORGEJO_GIT_URL "https://codeberg.org/meissa/forgejo.git" #ENV FORGEJO_GIT_URL "https://git.exozy.me/a/gitea.git" -ENV FORGEJO_BRANCH "forgejo-development" +ENV FORGEJO_BRANCH "forgejo-federated-star" #ENV FORGEJO_BRANCH "libreplanet-federation-demo" #Build deps From 7a7e05a715112a2d95824049789e5429d204b529 Mon Sep 17 00:00:00 2001 From: Michael Jerger Date: Fri, 15 Dec 2023 19:03:58 +0100 Subject: [PATCH 7/8] add test --- .../cljc/dda/c4k_forgejo/backup_test.cljc | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/test/cljc/dda/c4k_forgejo/backup_test.cljc diff --git a/src/test/cljc/dda/c4k_forgejo/backup_test.cljc b/src/test/cljc/dda/c4k_forgejo/backup_test.cljc new file mode 100644 index 0000000..af9eb55 --- /dev/null +++ b/src/test/cljc/dda/c4k_forgejo/backup_test.cljc @@ -0,0 +1,30 @@ +(ns dda.c4k-forgejo.backup-test + (:require + #?(:clj [clojure.test :refer [deftest is are testing run-tests]] + :cljs [cljs.test :refer-macros [deftest is are testing run-tests]]) + [clojure.spec.test.alpha :as st] + [dda.c4k-forgejo.backup :as cut])) + +(st/instrument `cut/generate-config) + +(deftest should-generate-backup-config + (testing "federated" + (is (= {:apiVersion "v1", + :kind "ConfigMap", + :metadata + {:name "backup-config", + :labels + #:app.kubernetes.io{:name "backup", :part-of "forgejo"}}, + :data {:restic-repository "s3:s3.amazonaws.com/backup/federated-repo"}} + (cut/generate-config + {:restic-repository "s3:s3.amazonaws.com/backup/federated-repo"})))) + (testing "non-federated" + (is (= {:apiVersion "v1", + :kind "ConfigMap", + :metadata + {:name "backup-config", + :labels + #:app.kubernetes.io{:name "backup", :part-of "forgejo"}}, + :data {:restic-repository "s3:s3.amazonaws.com/backup/repo"}} + (cut/generate-config + {:restic-repository "s3:s3.amazonaws.com/backup/repo"}))))) \ No newline at end of file From e6e63051aefad2d08b21965dcaf89998cb5b219d Mon Sep 17 00:00:00 2001 From: Michael Jerger Date: Fri, 15 Dec 2023 19:04:30 +0100 Subject: [PATCH 8/8] refactor to new commons features --- shadow-cljs.edn | 2 +- src/main/cljc/dda/c4k_forgejo/backup.cljc | 11 +- src/main/cljc/dda/c4k_forgejo/forgejo.cljc | 15 +-- .../cljc/dda/c4k_forgejo/forgejo_test.cljc | 107 +++++++++--------- 4 files changed, 60 insertions(+), 75 deletions(-) diff --git a/shadow-cljs.edn b/shadow-cljs.edn index 2a94637..bc51a31 100644 --- a/shadow-cljs.edn +++ b/shadow-cljs.edn @@ -4,7 +4,7 @@ "src/test/cljc" "src/test/cljs" "src/test/resources"] - :dependencies [[org.domaindrivenarchitecture/c4k-common-cljs "6.0.1"] + :dependencies [[org.domaindrivenarchitecture/c4k-common-cljs "6.1.0"] [hickory "0.7.1"]] :builds {:frontend {:target :browser :modules {:main {:init-fn dda.c4k-forgejo.browser/init}} diff --git a/src/main/cljc/dda/c4k_forgejo/backup.cljc b/src/main/cljc/dda/c4k_forgejo/backup.cljc index eb55172..00426e4 100644 --- a/src/main/cljc/dda/c4k_forgejo/backup.cljc +++ b/src/main/cljc/dda/c4k_forgejo/backup.cljc @@ -1,10 +1,10 @@ (ns dda.c4k-forgejo.backup (:require [clojure.spec.alpha :as s] - #?(:cljs [shadow.resource :as rc]) [dda.c4k-common.yaml :as yaml] [dda.c4k-common.base64 :as b64] - [dda.c4k-common.common :as cm])) + [dda.c4k-common.common :as cm] + #?(:cljs [dda.c4k-common.macros :refer-macros [inline-resources]]))) (s/def ::aws-access-key-id cm/bash-env-string?) (s/def ::aws-secret-access-key cm/bash-env-string?) @@ -13,12 +13,7 @@ #?(:cljs (defmethod yaml/load-resource :backup [resource-name] - (case resource-name - "backup/config.yaml" (rc/inline "backup/config.yaml") - "backup/cron.yaml" (rc/inline "backup/cron.yaml") - "backup/secret.yaml" (rc/inline "backup/secret.yaml") - "backup/backup-restore-deployment.yaml" (rc/inline "backup/backup-restore-deployment.yaml") - (throw (js/Error. "Undefined Resource!"))))) + (get (inline-resources "backup") resource-name))) (defn generate-config [my-conf] (let [{:keys [restic-repository]} my-conf] diff --git a/src/main/cljc/dda/c4k_forgejo/forgejo.cljc b/src/main/cljc/dda/c4k_forgejo/forgejo.cljc index e19261f..23b370e 100644 --- a/src/main/cljc/dda/c4k_forgejo/forgejo.cljc +++ b/src/main/cljc/dda/c4k_forgejo/forgejo.cljc @@ -2,17 +2,15 @@ (:require [clojure.spec.alpha :as s] [clojure.string :as st] - #?(:cljs [shadow.resource :as rc]) #?(:clj [orchestra.core :refer [defn-spec]] :cljs [orchestra.core :refer-macros [defn-spec]]) - #?(:clj [clojure.edn :as edn] - :cljs [cljs.reader :as edn]) [dda.c4k-common.yaml :as yaml] [dda.c4k-common.common :as cm] [dda.c4k-common.ingress :as ing] [dda.c4k-common.base64 :as b64] [dda.c4k-common.predicate :as pred] - [dda.c4k-common.postgres :as postgres])) + [dda.c4k-common.postgres :as postgres] + #?(:cljs [dda.c4k-common.macros :refer-macros [inline-resources]]))) (defn domain-list? [input] @@ -68,14 +66,7 @@ #?(:cljs (defmethod yaml/load-resource :forgejo [resource-name] - (case resource-name - "forgejo/appini-env-configmap.yaml" (rc/inline "forgejo/appini-env-configmap.yaml") - "forgejo/deployment.yaml" (rc/inline "forgejo/deployment.yaml") - "forgejo/secrets.yaml" (rc/inline "forgejo/secrets.yaml") - "forgejo/service.yaml" (rc/inline "forgejo/service.yaml") - "forgejo/service-ssh.yaml" (rc/inline "forgejo/service-ssh.yaml") - "forgejo/datavolume.yaml" (rc/inline "forgejo/datavolume.yaml") - (throw (js/Error. "Undefined Resource!"))))) + (get (inline-resources "forgejo") resource-name))) (defn generate-appini-env [config] diff --git a/src/test/cljc/dda/c4k_forgejo/forgejo_test.cljc b/src/test/cljc/dda/c4k_forgejo/forgejo_test.cljc index c074fa2..71805a3 100644 --- a/src/test/cljc/dda/c4k_forgejo/forgejo_test.cljc +++ b/src/test/cljc/dda/c4k_forgejo/forgejo_test.cljc @@ -51,62 +51,61 @@ :service-domain-whitelist "test.com,test.net" :service-noreply-address "noreply@test.com"}))))) -(deftest should-generate-non-federated-deployment - (is (= {:apiVersion "apps/v1", - :kind "Deployment", - :metadata {:name "forgejo", :namespace "default", :labels {:app "forgejo"}}, - :spec - {:replicas 1, - :selector {:matchLabels {:app "forgejo"}}, - :template - {:metadata {:name "forgejo", :labels {:app "forgejo"}}, +(deftest should-generate-deployment + (testing "non-federated" + (is (= {:apiVersion "apps/v1", + :kind "Deployment", + :metadata {:name "forgejo", :namespace "default", :labels {:app "forgejo"}}, :spec - {:containers - [{:name "forgejo", - :image "codeberg.org/forgejo/forgejo:1.19", - :imagePullPolicy "IfNotPresent", - :envFrom [{:configMapRef {:name "forgejo-env"}} {:secretRef {:name "forgejo-secrets"}}], - :volumeMounts [{:name "forgejo-data-volume", :mountPath "/data"}], - :ports [{:containerPort 22, :name "git-ssh"} {:containerPort 3000, :name "forgejo"}]}], - :volumes [{:name "forgejo-data-volume", :persistentVolumeClaim {:claimName "forgejo-data-pvc"}}]}}}} - (cut/generate-deployment - {:default-app-name "" - :deploy-federated "false" - :fqdn "test.de" - :mailer-from "" - :mailer-host "m.t.de" - :mailer-port "123" - :service-domain-whitelist "adb.de" - :service-noreply-address ""} - )))) - -(deftest should-generate-federated-deployment - (is (= {:apiVersion "apps/v1", - :kind "Deployment", - :metadata {:name "forgejo", :namespace "default", :labels {:app "forgejo"}}, - :spec - {:replicas 1, - :selector {:matchLabels {:app "forgejo"}}, - :template - {:metadata {:name "forgejo", :labels {:app "forgejo"}}, + {:replicas 1, + :selector {:matchLabels {:app "forgejo"}}, + :template + {:metadata {:name "forgejo", :labels {:app "forgejo"}}, + :spec + {:containers + [{:name "forgejo", + :image "codeberg.org/forgejo/forgejo:1.19", + :imagePullPolicy "IfNotPresent", + :envFrom [{:configMapRef {:name "forgejo-env"}} {:secretRef {:name "forgejo-secrets"}}], + :volumeMounts [{:name "forgejo-data-volume", :mountPath "/data"}], + :ports [{:containerPort 22, :name "git-ssh"} {:containerPort 3000, :name "forgejo"}]}], + :volumes [{:name "forgejo-data-volume", :persistentVolumeClaim {:claimName "forgejo-data-pvc"}}]}}}} + (cut/generate-deployment + {:default-app-name "" + :deploy-federated "false" + :fqdn "test.de" + :mailer-from "" + :mailer-host "m.t.de" + :mailer-port "123" + :service-domain-whitelist "adb.de" + :service-noreply-address ""})))) + (testing "federated-deployment" + (is (= {:apiVersion "apps/v1", + :kind "Deployment", + :metadata {:name "forgejo", :namespace "default", :labels {:app "forgejo"}}, :spec - {:containers - [{:name "forgejo", - :image "domaindrivenarchitecture/c4k-forgejo-federated:latest", - :imagePullPolicy "IfNotPresent", - :envFrom [{:configMapRef {:name "forgejo-env"}} {:secretRef {:name "forgejo-secrets"}}], - :volumeMounts [{:name "forgejo-data-volume", :mountPath "/data"}], - :ports [{:containerPort 22, :name "git-ssh"} {:containerPort 3000, :name "forgejo"}]}], - :volumes [{:name "forgejo-data-volume", :persistentVolumeClaim {:claimName "forgejo-data-pvc"}}]}}}} - (cut/generate-deployment - {:default-app-name "" - :deploy-federated "true" - :fqdn "test.de" - :mailer-from "" - :mailer-host "m.t.de" - :mailer-port "123" - :service-domain-whitelist "adb.de" - :service-noreply-address ""})))) + {:replicas 1, + :selector {:matchLabels {:app "forgejo"}}, + :template + {:metadata {:name "forgejo", :labels {:app "forgejo"}}, + :spec + {:containers + [{:name "forgejo", + :image "domaindrivenarchitecture/c4k-forgejo-federated:latest", + :imagePullPolicy "IfNotPresent", + :envFrom [{:configMapRef {:name "forgejo-env"}} {:secretRef {:name "forgejo-secrets"}}], + :volumeMounts [{:name "forgejo-data-volume", :mountPath "/data"}], + :ports [{:containerPort 22, :name "git-ssh"} {:containerPort 3000, :name "forgejo"}]}], + :volumes [{:name "forgejo-data-volume", :persistentVolumeClaim {:claimName "forgejo-data-pvc"}}]}}}} + (cut/generate-deployment + {:default-app-name "" + :deploy-federated "true" + :fqdn "test.de" + :mailer-from "" + :mailer-host "m.t.de" + :mailer-port "123" + :service-domain-whitelist "adb.de" + :service-noreply-address ""}))))) (deftest should-generate-secret (is (= {:FORGEJO__database__USER-c1 "",