From efa7cb23c736894ead4316899fefbcdb36e539b6 Mon Sep 17 00:00:00 2001
From: erik <erik.seiert@meissa-gmbh.de>
Date: Tue, 16 May 2023 10:02:47 +0200
Subject: [PATCH 01/29] WIP implement image name replacement

---
 src/main/cljc/dda/c4k_forgejo/forgejo.cljc | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/src/main/cljc/dda/c4k_forgejo/forgejo.cljc b/src/main/cljc/dda/c4k_forgejo/forgejo.cljc
index 5367550..2be5d6f 100644
--- a/src/main/cljc/dda/c4k_forgejo/forgejo.cljc
+++ b/src/main/cljc/dda/c4k_forgejo/forgejo.cljc
@@ -21,6 +21,7 @@
    (pred/string-of-separated-by? pred/fqdn-string? #"," input)))
 
 (s/def ::default-app-name string?)
+(s/def ::forgejo-image-name string?)
 (s/def ::fqdn pred/fqdn-string?)
 (s/def ::mailer-from pred/bash-env-string?)
 (s/def ::mailer-host pred/bash-env-string?)
@@ -34,11 +35,12 @@
 
 (def config-defaults {:issuer "staging"})
 
-(def config? (s/keys :req-un [::fqdn 
-                              ::mailer-from 
+(def config? (s/keys :req-un [::fqdn
+                              ::mailer-from
                               ::mailer-host
                               ::mailer-port
-                              ::service-noreply-address]
+                              ::service-noreply-address
+                              ::deploy-federated]
                      :opt-un [::issuer 
                               ::default-app-name 
                               ::service-domain-whitelist]))
@@ -117,8 +119,10 @@
      (yaml/load-as-edn "forgejo/datavolume.yaml")
      (cm/replace-all-matching-values-by-new-value "DATASTORAGESIZE" (str (str data-storage-size) "Gi")))))
 
-(defn generate-deployment
-  []
+(defn-spec generate-deployment pred/map-or-seq?
+  [config config?]
+  (let [{:key [deploy-federated]} config
+        deploy-federated-bool ()])
   (yaml/load-as-edn "forgejo/deployment.yaml"))
 
 (defn generate-service

From 92451aab04c00e5e1fded06d1a133ef744b22266 Mon Sep 17 00:00:00 2001
From: erik <erik.seiert@meissa-gmbh.de>
Date: Tue, 16 May 2023 10:06:13 +0200
Subject: [PATCH 02/29] Update with deploy-federated

---
 src/test/resources/forgejo-test/valid-config.yaml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/test/resources/forgejo-test/valid-config.yaml b/src/test/resources/forgejo-test/valid-config.yaml
index 1badecb..d847ff9 100644
--- a/src/test/resources/forgejo-test/valid-config.yaml
+++ b/src/test/resources/forgejo-test/valid-config.yaml
@@ -8,6 +8,7 @@ service-whitelist-domains: "test.de"
 service-noreply-address: "noreply@test.de"
 volume-total-storage-size: 6
 restic-repository: "repo-path"
+deploy-federated: "false"
 mon-cfg: 
   grafana-cloud-url: "url-for-your-prom-remote-write-endpoint"
   cluster-name: "forgejo"

From bbc9f0aa81ae4e2c7c2e3193926138f5ba84268c Mon Sep 17 00:00:00 2001
From: Mirco <mirco.zachmann@meissa.de>
Date: Tue, 16 May 2023 10:37:45 +0200
Subject: [PATCH 03/29] deploy-federated-bool

---
 src/main/resources/forgejo/deployment.yaml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/main/resources/forgejo/deployment.yaml b/src/main/resources/forgejo/deployment.yaml
index 110ec43..4b1a5f1 100644
--- a/src/main/resources/forgejo/deployment.yaml
+++ b/src/main/resources/forgejo/deployment.yaml
@@ -18,7 +18,7 @@ spec:
     spec:
       containers:
         - name: forgejo
-          image: codeberg.org/forgejo/forgejo:1.19
+          image: IMAGE_NAME #codeberg.org/forgejo/forgejo:1.19
           imagePullPolicy: IfNotPresent
           # config settings
           envFrom:

From 4f81802717223bb62cf4143ea2e01d658d5e6350 Mon Sep 17 00:00:00 2001
From: Mirco <mirco.zachmann@meissa.de>
Date: Tue, 16 May 2023 10:40:33 +0200
Subject: [PATCH 04/29] [skip-ci] changes deploy-federated

---
 src/main/cljc/dda/c4k_forgejo/forgejo.cljc | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/main/cljc/dda/c4k_forgejo/forgejo.cljc b/src/main/cljc/dda/c4k_forgejo/forgejo.cljc
index 2be5d6f..ae342ed 100644
--- a/src/main/cljc/dda/c4k_forgejo/forgejo.cljc
+++ b/src/main/cljc/dda/c4k_forgejo/forgejo.cljc
@@ -122,8 +122,9 @@
 (defn-spec generate-deployment pred/map-or-seq?
   [config config?]
   (let [{:key [deploy-federated]} config
-        deploy-federated-bool ()])
-  (yaml/load-as-edn "forgejo/deployment.yaml"))
+        deploy-federated-bool (boolean (Boolean/valueOf deploy-federated))])
+  (->
+   (yaml/load-as-edn "forgejo/deployment.yaml")))
 
 (defn generate-service
   []

From 546e13ef9e8c32c2a7125a2a17702b548d35c6dd Mon Sep 17 00:00:00 2001
From: erik <erik.seiert@meissa-gmbh.de>
Date: Tue, 16 May 2023 11:06:20 +0200
Subject: [PATCH 05/29] [skip-ci] implement optional fed

---
 src/main/cljc/dda/c4k_forgejo/forgejo.cljc | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/src/main/cljc/dda/c4k_forgejo/forgejo.cljc b/src/main/cljc/dda/c4k_forgejo/forgejo.cljc
index ae342ed..476b949 100644
--- a/src/main/cljc/dda/c4k_forgejo/forgejo.cljc
+++ b/src/main/cljc/dda/c4k_forgejo/forgejo.cljc
@@ -53,7 +53,6 @@
   [total]
   total)
 
-
 #?(:cljs
    (defmethod yaml/load-resource :forgejo [resource-name]
      (case resource-name
@@ -121,10 +120,13 @@
 
 (defn-spec generate-deployment pred/map-or-seq?
   [config config?]
-  (let [{:key [deploy-federated]} config
-        deploy-federated-bool (boolean (Boolean/valueOf deploy-federated))])
-  (->
-   (yaml/load-as-edn "forgejo/deployment.yaml")))
+  (let [{:keys [deploy-federated]} config
+        deploy-federated-bool (boolean (Boolean/valueOf deploy-federated))]
+    (->
+     (yaml/load-as-edn "forgejo/deployment.yaml")
+     #(if deploy-federated-bool
+       (cm/replace-all-matching-values-by-new-value % "IMAGE_NAME" federated-image-name)
+       (cm/replace-all-matching-values-by-new-value %"IMAGE_NAME" default-name)))))
 
 (defn generate-service
   []

From f16a94a346f626991b79d476158824680e5fd0d6 Mon Sep 17 00:00:00 2001
From: erik <erik.seiert@meissa-gmbh.de>
Date: Tue, 16 May 2023 11:07:36 +0200
Subject: [PATCH 06/29] [skip-ci] add todos

---
 src/main/cljc/dda/c4k_forgejo/forgejo.cljc | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/main/cljc/dda/c4k_forgejo/forgejo.cljc b/src/main/cljc/dda/c4k_forgejo/forgejo.cljc
index 476b949..0a011dd 100644
--- a/src/main/cljc/dda/c4k_forgejo/forgejo.cljc
+++ b/src/main/cljc/dda/c4k_forgejo/forgejo.cljc
@@ -117,7 +117,8 @@
     (->     
      (yaml/load-as-edn "forgejo/datavolume.yaml")
      (cm/replace-all-matching-values-by-new-value "DATASTORAGESIZE" (str (str data-storage-size) "Gi")))))
-
+; ToDo: Need to add  federated-image-name to config? Or hardcode?
+; ToDo: Need to add  default image-name to config? Or hardcode?
 (defn-spec generate-deployment pred/map-or-seq?
   [config config?]
   (let [{:keys [deploy-federated]} config

From 502abe750b698fdc64e2c4a89500a9535355d13c Mon Sep 17 00:00:00 2001
From: Mirco <mirco.zachmann@meissa.de>
Date: Wed, 24 May 2023 09:50:39 +0200
Subject: [PATCH 07/29] [Skip-ci] WIP dockerimage

---
 infrastructure/docker-federated/build.py      | 52 ++++++++++++++
 .../docker-federated/image/Dockerfile         | 70 +++++++++++++++++++
 src/main/resources/forgejo/deployment.yaml    |  2 +-
 3 files changed, 123 insertions(+), 1 deletion(-)
 create mode 100644 infrastructure/docker-federated/build.py
 create mode 100644 infrastructure/docker-federated/image/Dockerfile

diff --git a/infrastructure/docker-federated/build.py b/infrastructure/docker-federated/build.py
new file mode 100644
index 0000000..9919c53
--- /dev/null
+++ b/infrastructure/docker-federated/build.py
@@ -0,0 +1,52 @@
+from os import environ
+from pybuilder.core import task, init
+from ddadevops import *
+import logging
+
+name = 'c4k-forgejo-fed'
+MODULE = 'docker'
+PROJECT_ROOT_PATH = '../..'
+
+class MyBuild(DevopsDockerBuild):
+    pass
+
+@init
+def initialize(project):
+    project.build_depends_on('ddadevops>=0.12.4')
+    stage = 'prod'
+    dockerhub_user = environ.get('DOCKERHUB_USER')
+    if not dockerhub_user:
+        dockerhub_user = gopass_field_from_path('meissa/web/docker.com', 'login')
+    dockerhub_password = environ.get('DOCKERHUB_PASSWORD')
+    if not dockerhub_password:
+        dockerhub_password = gopass_password_from_path('meissa/web/docker.com')
+    tag = environ.get('CI_COMMIT_TAG')
+    if not tag:
+        tag = get_tag_from_latest_commit()
+    config = create_devops_docker_build_config(
+        stage, PROJECT_ROOT_PATH, MODULE, dockerhub_user, dockerhub_password, docker_publish_tag=tag)
+    build = MyBuild(project, config)
+    build.initialize_build_dir()
+
+
+@task
+def image(project):
+    build = get_devops_build(project)
+    build.image()
+
+@task
+def drun(project):
+    build = get_devops_build(project)
+    build.drun()
+
+@task
+def publish(project):
+    build = get_devops_build(project)
+    build.dockerhub_login()
+    build.dockerhub_publish()
+
+@task
+def test(project):
+    build = get_devops_build(project)
+    build.test()
+
diff --git a/infrastructure/docker-federated/image/Dockerfile b/infrastructure/docker-federated/image/Dockerfile
new file mode 100644
index 0000000..99ab1f9
--- /dev/null
+++ b/infrastructure/docker-federated/image/Dockerfile
@@ -0,0 +1,70 @@
+#Build stage
+FROM docker.io/library/golang:1.20-alpine3.17 AS build-env
+
+ARG GOPROXY
+ENV GOPROXY ${GOPROXY:-direct}
+
+ARG GITEA_VERSION
+ARG TAGS="sqlite sqlite_unlock_notify"
+ENV TAGS "bindata timetzdata $TAGS"
+ARG CGO_EXTRA_CFLAGS
+
+#Build deps
+RUN apk --no-cache add build-base git nodejs npm
+
+#Setup repo
+COPY . ${GOPATH}/src/code.gitea.io/gitea
+WORKDIR ${GOPATH}/src/code.gitea.io/gitea
+
+#Checkout version if set
+RUN if [ -n "${GITEA_VERSION}" ]; then git checkout "${GITEA_VERSION}"; fi \
+ && make clean-all build
+
+# Begin env-to-ini build
+RUN go build contrib/environment-to-ini/environment-to-ini.go
+
+FROM docker.io/library/alpine:3.17
+LABEL maintainer="contact@forgejo.org"
+
+EXPOSE 22 3000
+
+RUN apk --no-cache add \
+    bash \
+    ca-certificates \
+    curl \
+    gettext \
+    git \
+    linux-pam \
+    openssh \
+    s6 \
+    sqlite \
+    su-exec \
+    gnupg
+
+RUN addgroup \
+    -S -g 1000 \
+    git && \
+  adduser \
+    -S -H -D \
+    -h /data/git \
+    -s /bin/bash \
+    -u 1000 \
+    -G git \
+    git && \
+  echo "git:*" | chpasswd -e
+
+ENV USER git
+ENV GITEA_CUSTOM /data/gitea
+
+VOLUME ["/data"]
+
+ENTRYPOINT ["/usr/bin/entrypoint"]
+CMD ["/bin/s6-svscan", "/etc/s6"]
+
+COPY docker/root /
+COPY --from=build-env /go/src/code.gitea.io/gitea/gitea /app/gitea/gitea
+COPY --from=build-env /go/src/code.gitea.io/gitea/environment-to-ini /usr/local/bin/environment-to-ini
+COPY --from=build-env /go/src/code.gitea.io/gitea/contrib/autocompletion/bash_autocomplete /etc/profile.d/gitea_bash_autocomplete.sh
+RUN chmod 755 /usr/bin/entrypoint /app/gitea/gitea /usr/local/bin/gitea /usr/local/bin/environment-to-ini
+RUN chmod 755 /etc/s6/gitea/* /etc/s6/openssh/* /etc/s6/.s6-svscan/*
+RUN chmod 644 /etc/profile.d/gitea_bash_autocomplete.sh
diff --git a/src/main/resources/forgejo/deployment.yaml b/src/main/resources/forgejo/deployment.yaml
index 4b1a5f1..93fa1ef 100644
--- a/src/main/resources/forgejo/deployment.yaml
+++ b/src/main/resources/forgejo/deployment.yaml
@@ -18,7 +18,7 @@ spec:
     spec:
       containers:
         - name: forgejo
-          image: IMAGE_NAME #codeberg.org/forgejo/forgejo:1.19
+          image: codeberg.org/meissa/forgejo:federated-latest #codeberg.org/forgejo/forgejo:1.19
           imagePullPolicy: IfNotPresent
           # config settings
           envFrom:

From d188cd236dc58d8d69fdaf2b060efa145ae5be42 Mon Sep 17 00:00:00 2001
From: erik <erik.seiert@meissa-gmbh.de>
Date: Wed, 24 May 2023 10:44:52 +0200
Subject: [PATCH 08/29] [skip-ci] WIP docker image

---
 infrastructure/docker-federated/image/Dockerfile | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/infrastructure/docker-federated/image/Dockerfile b/infrastructure/docker-federated/image/Dockerfile
index 99ab1f9..606fa88 100644
--- a/infrastructure/docker-federated/image/Dockerfile
+++ b/infrastructure/docker-federated/image/Dockerfile
@@ -9,11 +9,16 @@ ARG TAGS="sqlite sqlite_unlock_notify"
 ENV TAGS "bindata timetzdata $TAGS"
 ARG CGO_EXTRA_CFLAGS
 
+ARG FORGEJO_GIT_URL="https://codeberg.org/forgejo/forgejo.git"
+ARG FORGEJO_BRANCH="forgejo-federation"
+ARG FORGEJO_FOLDER="forgejo-fed"
+
 #Build deps
 RUN apk --no-cache add build-base git nodejs npm
 
 #Setup repo
-COPY . ${GOPATH}/src/code.gitea.io/gitea
+RUN git clone --single-branch --branch FORGEJO_BRANCH FORGEJO_GIT_URL FORGEJO_FOLDER
+COPY FORGEJO_FOLDER/* ${GOPATH}/src/code.gitea.io/gitea
 WORKDIR ${GOPATH}/src/code.gitea.io/gitea
 
 #Checkout version if set

From 47e168063b4d253eec745193a4736ed1046fd0bf Mon Sep 17 00:00:00 2001
From: erik <erik.seiert@meissa-gmbh.de>
Date: Wed, 24 May 2023 10:52:46 +0200
Subject: [PATCH 09/29] [skip-ci] Add clarifying comment

---
 infrastructure/docker-federated/image/Dockerfile | 1 +
 1 file changed, 1 insertion(+)

diff --git a/infrastructure/docker-federated/image/Dockerfile b/infrastructure/docker-federated/image/Dockerfile
index 606fa88..ace4fb6 100644
--- a/infrastructure/docker-federated/image/Dockerfile
+++ b/infrastructure/docker-federated/image/Dockerfile
@@ -28,6 +28,7 @@ RUN if [ -n "${GITEA_VERSION}" ]; then git checkout "${GITEA_VERSION}"; fi \
 # Begin env-to-ini build
 RUN go build contrib/environment-to-ini/environment-to-ini.go
 
+# Run stage
 FROM docker.io/library/alpine:3.17
 LABEL maintainer="contact@forgejo.org"
 

From 1c42e87f24286b00b0348ceaea9a7769270fb9a7 Mon Sep 17 00:00:00 2001
From: erik <erik.seiert@meissa-gmbh.de>
Date: Wed, 24 May 2023 10:53:02 +0200
Subject: [PATCH 10/29] [skip-ci] resource folder

---
 infrastructure/docker-federated/image/resources/install.sh | 4 ++++
 1 file changed, 4 insertions(+)
 create mode 100755 infrastructure/docker-federated/image/resources/install.sh

diff --git a/infrastructure/docker-federated/image/resources/install.sh b/infrastructure/docker-federated/image/resources/install.sh
new file mode 100755
index 0000000..1937557
--- /dev/null
+++ b/infrastructure/docker-federated/image/resources/install.sh
@@ -0,0 +1,4 @@
+#!/bin/bash
+install -m 0700 /tmp/entrypoint.sh /
+install -m 0700 /tmp/functions.sh /usr/local/bin/
+

From fe7d3ac2271d1a5a0788cdf2c3da697867816a70 Mon Sep 17 00:00:00 2001
From: Mirco <mirco.zachmann@meissa.de>
Date: Wed, 24 May 2023 11:42:11 +0200
Subject: [PATCH 11/29] [skip-ci] Define ENV vars and COPY PATH ../docker/root

---
 .../docker-federated/image/Dockerfile         | 21 ++++++++++---------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/infrastructure/docker-federated/image/Dockerfile b/infrastructure/docker-federated/image/Dockerfile
index ace4fb6..4dc288c 100644
--- a/infrastructure/docker-federated/image/Dockerfile
+++ b/infrastructure/docker-federated/image/Dockerfile
@@ -1,29 +1,30 @@
 #Build stage
-FROM docker.io/library/golang:1.20-alpine3.17 AS build-env
+FROM docker.io/library/golang:1.20.4-alpine3.18 AS build-env
 
 ARG GOPROXY
 ENV GOPROXY ${GOPROXY:-direct}
 
-ARG GITEA_VERSION
+#ARG GITEA_VERSION
 ARG TAGS="sqlite sqlite_unlock_notify"
 ENV TAGS "bindata timetzdata $TAGS"
 ARG CGO_EXTRA_CFLAGS
 
-ARG FORGEJO_GIT_URL="https://codeberg.org/forgejo/forgejo.git"
-ARG FORGEJO_BRANCH="forgejo-federation"
-ARG FORGEJO_FOLDER="forgejo-fed"
+ENV FORGEJO_GIT_URL "https://codeberg.org/forgejo/forgejo.git"
+ENV FORGEJO_BRANCH "forgejo-federation"
+#ENV FORGEJO_FOLDER "forgejo-fed"
 
 #Build deps
 RUN apk --no-cache add build-base git nodejs npm
 
 #Setup repo
-RUN git clone --single-branch --branch FORGEJO_BRANCH FORGEJO_GIT_URL FORGEJO_FOLDER
-COPY FORGEJO_FOLDER/* ${GOPATH}/src/code.gitea.io/gitea
+RUN git clone --single-branch --branch ${FORGEJO_BRANCH} ${FORGEJO_GIT_URL} ${GOPATH}/src/code.gitea.io/gitea 
+#${FORGEJO_FOLDER}
+#COPY ${FORGEJO_FOLDER} ${GOPATH}/src/code.gitea.io/gitea
 WORKDIR ${GOPATH}/src/code.gitea.io/gitea
 
 #Checkout version if set
-RUN if [ -n "${GITEA_VERSION}" ]; then git checkout "${GITEA_VERSION}"; fi \
- && make clean-all build
+#RUN if [ -n "${GITEA_VERSION}" ]; then git checkout "${GITEA_VERSION}"; fi \
+RUN make clean-all build
 
 # Begin env-to-ini build
 RUN go build contrib/environment-to-ini/environment-to-ini.go
@@ -67,7 +68,7 @@ VOLUME ["/data"]
 ENTRYPOINT ["/usr/bin/entrypoint"]
 CMD ["/bin/s6-svscan", "/etc/s6"]
 
-COPY docker/root /
+COPY --from=build-env /go/src/code.gitea.io/gitea/docker/root /
 COPY --from=build-env /go/src/code.gitea.io/gitea/gitea /app/gitea/gitea
 COPY --from=build-env /go/src/code.gitea.io/gitea/environment-to-ini /usr/local/bin/environment-to-ini
 COPY --from=build-env /go/src/code.gitea.io/gitea/contrib/autocompletion/bash_autocomplete /etc/profile.d/gitea_bash_autocomplete.sh

From 2af76f85579f58a6ee35c74e24f6136a295ec201 Mon Sep 17 00:00:00 2001
From: Mirco <mirco.zachmann@meissa.de>
Date: Tue, 30 May 2023 08:47:59 +0200
Subject: [PATCH 12/29] [skip-ci] use ci to publish docker image

---
 .gitlab-ci.yml                           | 8 ++++++++
 infrastructure/docker-federated/build.py | 2 +-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 6f746f2..747366c 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -114,3 +114,11 @@ release:
         --assets-link "{\"name\":\"c4k-forgejo.js\",\"url\":\"https://gitlab.com/domaindrivenarchitecture/c4k-forgejo/-/jobs/${CI_JOB_ID}/artifacts/file/target/frontend-build/c4k-forgejo.js\"}" \
         --assets-link "{\"name\":\"c4k-forgejo.js.sha256\",\"url\":\"https://gitlab.com/domaindrivenarchitecture/c4k-forgejo/-/jobs/${CI_JOB_ID}/artifacts/file/target/frontend-build/c4k-forgejo.js.sha256\"}" \
         --assets-link "{\"name\":\"c4k-forgejo.js.sha512\",\"url\":\"https://gitlab.com/domaindrivenarchitecture/c4k-forgejo/-/jobs/${CI_JOB_ID}/artifacts/file/target/frontend-build/c4k-forgejo.js.sha512\"}" \
+
+forgejo-image-test-publish:
+  image: domaindrivenarchitecture/devops-build:latest
+  stage: image
+  rules:
+    - if: '$CI_COMMIT_TAG != null'
+  script:
+    - cd infrastructure/docker-federated && pyb image test publish
\ No newline at end of file
diff --git a/infrastructure/docker-federated/build.py b/infrastructure/docker-federated/build.py
index 9919c53..89be081 100644
--- a/infrastructure/docker-federated/build.py
+++ b/infrastructure/docker-federated/build.py
@@ -12,7 +12,7 @@ class MyBuild(DevopsDockerBuild):
 
 @init
 def initialize(project):
-    project.build_depends_on('ddadevops>=0.12.4')
+    project.build_depends_on('ddadevops>=0.15.5')
     stage = 'prod'
     dockerhub_user = environ.get('DOCKERHUB_USER')
     if not dockerhub_user:

From b689d520ce065800042eac29a14644b0f45d8f3f Mon Sep 17 00:00:00 2001
From: Michael Jerger <michael.jerger@meissa-gmbh.de>
Date: Tue, 30 May 2023 09:20:58 +0200
Subject: [PATCH 13/29] wrote tests upfront

---
 src/main/cljc/dda/c4k_forgejo/core.cljc          |  2 +-
 src/main/cljc/dda/c4k_forgejo/forgejo.cljc       | 16 +++++-----------
 src/main/resources/forgejo/deployment.yaml       |  2 +-
 src/test/cljc/dda/c4k_forgejo/forgejo_test.cljc  | 14 ++++++++++++--
 .../resources/forgejo-test/valid-config.yaml     |  2 +-
 5 files changed, 20 insertions(+), 16 deletions(-)

diff --git a/src/main/cljc/dda/c4k_forgejo/core.cljc b/src/main/cljc/dda/c4k_forgejo/core.cljc
index d63b477..1dad792 100644
--- a/src/main/cljc/dda/c4k_forgejo/core.cljc
+++ b/src/main/cljc/dda/c4k_forgejo/core.cljc
@@ -43,7 +43,7 @@
                    (postgres/generate-deployment {:postgres-image "postgres:14"
                                                   :postgres-size :2gb})
                    (postgres/generate-service)
-                   (forgejo/generate-deployment)
+                   (forgejo/generate-deployment config)
                    (forgejo/generate-service)
                    (forgejo/generate-service-ssh)                   
                    (forgejo/generate-data-volume config)
diff --git a/src/main/cljc/dda/c4k_forgejo/forgejo.cljc b/src/main/cljc/dda/c4k_forgejo/forgejo.cljc
index 0a011dd..48028d1 100644
--- a/src/main/cljc/dda/c4k_forgejo/forgejo.cljc
+++ b/src/main/cljc/dda/c4k_forgejo/forgejo.cljc
@@ -21,7 +21,7 @@
    (pred/string-of-separated-by? pred/fqdn-string? #"," input)))
 
 (s/def ::default-app-name string?)
-(s/def ::forgejo-image-name string?)
+(s/def ::federated boolean?)
 (s/def ::fqdn pred/fqdn-string?)
 (s/def ::mailer-from pred/bash-env-string?)
 (s/def ::mailer-host pred/bash-env-string?)
@@ -39,11 +39,11 @@
                               ::mailer-from
                               ::mailer-host
                               ::mailer-port
-                              ::service-noreply-address
-                              ::deploy-federated]
+                              ::service-noreply-address]
                      :opt-un [::issuer 
                               ::default-app-name 
-                              ::service-domain-whitelist]))
+                              ::service-domain-whitelist
+                              ::federated]))
 
 (def auth? (s/keys :req-un [::postgres/postgres-db-user ::postgres/postgres-db-password ::mailer-user ::mailer-pw]))
 
@@ -121,13 +121,7 @@
 ; ToDo: Need to add  default image-name to config? Or hardcode?
 (defn-spec generate-deployment pred/map-or-seq?
   [config config?]
-  (let [{:keys [deploy-federated]} config
-        deploy-federated-bool (boolean (Boolean/valueOf deploy-federated))]
-    (->
-     (yaml/load-as-edn "forgejo/deployment.yaml")
-     #(if deploy-federated-bool
-       (cm/replace-all-matching-values-by-new-value % "IMAGE_NAME" federated-image-name)
-       (cm/replace-all-matching-values-by-new-value %"IMAGE_NAME" default-name)))))
+  (yaml/load-as-edn "forgejo/deployment.yaml"))
 
 (defn generate-service
   []
diff --git a/src/main/resources/forgejo/deployment.yaml b/src/main/resources/forgejo/deployment.yaml
index 93fa1ef..110ec43 100644
--- a/src/main/resources/forgejo/deployment.yaml
+++ b/src/main/resources/forgejo/deployment.yaml
@@ -18,7 +18,7 @@ spec:
     spec:
       containers:
         - name: forgejo
-          image: codeberg.org/meissa/forgejo:federated-latest #codeberg.org/forgejo/forgejo:1.19
+          image: codeberg.org/forgejo/forgejo:1.19
           imagePullPolicy: IfNotPresent
           # config settings
           envFrom:
diff --git a/src/test/cljc/dda/c4k_forgejo/forgejo_test.cljc b/src/test/cljc/dda/c4k_forgejo/forgejo_test.cljc
index ef03fa6..1887e1a 100644
--- a/src/test/cljc/dda/c4k_forgejo/forgejo_test.cljc
+++ b/src/test/cljc/dda/c4k_forgejo/forgejo_test.cljc
@@ -29,7 +29,9 @@
           :FORGEJO__service__EMAIL_DOMAIN_WHITELIST-c1 "adb.de",
           :FORGEJO__service__EMAIL_DOMAIN_WHITELIST-c2 "test.com,test.net",
           :FORGEJO__service__NO_REPLY_ADDRESS-c1 "",
-          :FORGEJO__service__NO_REPLY_ADDRESS-c2 "noreply@test.com"}
+          :FORGEJO__service__NO_REPLY_ADDRESS-c2 "noreply@test.com"
+          :FORGEJO__federation__ENABLED-c1 "true"
+          :FORGEJO__federation__ENABLED-c2 "false"}
          (th/map-diff (cut/generate-appini-env {:default-app-name ""
                                                 :fqdn "test.de"                                                
                                                 :mailer-from ""
@@ -37,6 +39,7 @@
                                                 :mailer-port "123"
                                                 :service-domain-whitelist "adb.de"
                                                 :service-noreply-address ""
+                                                :federated true
                                                 })
                       (cut/generate-appini-env {:default-app-name "test forgejo"
                                                 :fqdn "test.com"                                                 
@@ -45,6 +48,7 @@
                                                 :mailer-port "456"
                                                 :service-domain-whitelist "test.com,test.net"
                                                 :service-noreply-address "noreply@test.com"
+                                                :federated false
                                                 })))))
 
 (deftest should-generate-secret
@@ -69,4 +73,10 @@
   (is (= {:storage-c1 "1Gi",
           :storage-c2 "15Gi"}
          (th/map-diff (cut/generate-data-volume {:volume-total-storage-size 1})
-                      (cut/generate-data-volume {:volume-total-storage-size 15})))))
\ No newline at end of file
+                      (cut/generate-data-volume {:volume-total-storage-size 15})))))
+
+(deftest should-generate-deployment
+  (is (= {:image-c1 "codeberg.org/forgejo/forgejo:1.19",
+          :image-c2 "domaindrivenarchitecture/c4k-forgejo-fed"}
+         (th/map-diff (cut/generate-deployment {:federated false})
+                      (cut/generate-deployment {:federated true})))))
\ No newline at end of file
diff --git a/src/test/resources/forgejo-test/valid-config.yaml b/src/test/resources/forgejo-test/valid-config.yaml
index d847ff9..a16d121 100644
--- a/src/test/resources/forgejo-test/valid-config.yaml
+++ b/src/test/resources/forgejo-test/valid-config.yaml
@@ -8,7 +8,7 @@ service-whitelist-domains: "test.de"
 service-noreply-address: "noreply@test.de"
 volume-total-storage-size: 6
 restic-repository: "repo-path"
-deploy-federated: "false"
+federated: false
 mon-cfg: 
   grafana-cloud-url: "url-for-your-prom-remote-write-endpoint"
   cluster-name: "forgejo"

From 75d34278938dd0f30fd498756e43a611198f2bd7 Mon Sep 17 00:00:00 2001
From: Mirco <mirco.zachmann@meissa.de>
Date: Thu, 1 Jun 2023 12:15:45 +0200
Subject: [PATCH 14/29] Add severspec test, rm resources

---
 infrastructure/docker-federated/build.py               |  1 -
 infrastructure/docker-federated/image/Dockerfile       |  7 ++-----
 .../docker-federated/image/resources/install.sh        |  4 ----
 infrastructure/docker-federated/test/Dockerfile        | 10 ++++++++++
 infrastructure/docker-federated/test/serverspec.edn    |  8 ++++++++
 5 files changed, 20 insertions(+), 10 deletions(-)
 delete mode 100755 infrastructure/docker-federated/image/resources/install.sh
 create mode 100644 infrastructure/docker-federated/test/Dockerfile
 create mode 100644 infrastructure/docker-federated/test/serverspec.edn

diff --git a/infrastructure/docker-federated/build.py b/infrastructure/docker-federated/build.py
index 89be081..6b3cf58 100644
--- a/infrastructure/docker-federated/build.py
+++ b/infrastructure/docker-federated/build.py
@@ -49,4 +49,3 @@ def publish(project):
 def test(project):
     build = get_devops_build(project)
     build.test()
-
diff --git a/infrastructure/docker-federated/image/Dockerfile b/infrastructure/docker-federated/image/Dockerfile
index 4dc288c..bf2e710 100644
--- a/infrastructure/docker-federated/image/Dockerfile
+++ b/infrastructure/docker-federated/image/Dockerfile
@@ -11,26 +11,23 @@ ARG CGO_EXTRA_CFLAGS
 
 ENV FORGEJO_GIT_URL "https://codeberg.org/forgejo/forgejo.git"
 ENV FORGEJO_BRANCH "forgejo-federation"
-#ENV FORGEJO_FOLDER "forgejo-fed"
 
 #Build deps
 RUN apk --no-cache add build-base git nodejs npm
 
 #Setup repo
 RUN git clone --single-branch --branch ${FORGEJO_BRANCH} ${FORGEJO_GIT_URL} ${GOPATH}/src/code.gitea.io/gitea 
-#${FORGEJO_FOLDER}
-#COPY ${FORGEJO_FOLDER} ${GOPATH}/src/code.gitea.io/gitea
+
 WORKDIR ${GOPATH}/src/code.gitea.io/gitea
 
 #Checkout version if set
-#RUN if [ -n "${GITEA_VERSION}" ]; then git checkout "${GITEA_VERSION}"; fi \
 RUN make clean-all build
 
 # Begin env-to-ini build
 RUN go build contrib/environment-to-ini/environment-to-ini.go
 
 # Run stage
-FROM docker.io/library/alpine:3.17
+FROM docker.io/library/alpine:3.18
 LABEL maintainer="contact@forgejo.org"
 
 EXPOSE 22 3000
diff --git a/infrastructure/docker-federated/image/resources/install.sh b/infrastructure/docker-federated/image/resources/install.sh
deleted file mode 100755
index 1937557..0000000
--- a/infrastructure/docker-federated/image/resources/install.sh
+++ /dev/null
@@ -1,4 +0,0 @@
-#!/bin/bash
-install -m 0700 /tmp/entrypoint.sh /
-install -m 0700 /tmp/functions.sh /usr/local/bin/
-
diff --git a/infrastructure/docker-federated/test/Dockerfile b/infrastructure/docker-federated/test/Dockerfile
new file mode 100644
index 0000000..10de78a
--- /dev/null
+++ b/infrastructure/docker-federated/test/Dockerfile
@@ -0,0 +1,10 @@
+FROM c4k-forgejo-fed
+
+RUN apk --no-cache add openjdk11-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
+
+COPY serverspec.edn /tmp/serverspec.edn
+
+RUN java -jar /tmp/serverspec.jar /tmp/serverspec.edn -v
diff --git a/infrastructure/docker-federated/test/serverspec.edn b/infrastructure/docker-federated/test/serverspec.edn
new file mode 100644
index 0000000..7c95886
--- /dev/null
+++ b/infrastructure/docker-federated/test/serverspec.edn
@@ -0,0 +1,8 @@
+{:file [{:path "/usr/bin/entrypoint" :mod "755"}
+        {:path "/app/gitea/gitea" :mod "755"}
+        {:path "/usr/local/bin/gitea" :mod "755"}
+        {:path "/usr/local/bin/environment-to-ini" :mod "755"}
+        {:path "/etc/s6/gitea/" :mod "755"}
+        {:path "/etc/s6/openssh/" :mod "755"}
+        {:path "/etc/s6/.s6-svscan/" :mod "755"}
+        {:path "/etc/profile.d/gitea_bash_autocomplete.sh" :mod "644"}]}

From 0f626a040dc8cc4ca2f25d680942eb54e5768e8f Mon Sep 17 00:00:00 2001
From: Mirco <mirco.zachmann@meissa.de>
Date: Thu, 1 Jun 2023 20:27:56 +0200
Subject: [PATCH 15/29] One failure remaining in Testdriven Design; Decision if
 federated true/false in forgejo.cljc not working

---
 src/main/cljc/dda/c4k_forgejo/forgejo.cljc    | 19 ++++++++++++++-----
 .../forgejo/appini-env-configmap.yaml         |  2 +-
 2 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/src/main/cljc/dda/c4k_forgejo/forgejo.cljc b/src/main/cljc/dda/c4k_forgejo/forgejo.cljc
index 48028d1..cd3becc 100644
--- a/src/main/cljc/dda/c4k_forgejo/forgejo.cljc
+++ b/src/main/cljc/dda/c4k_forgejo/forgejo.cljc
@@ -72,9 +72,11 @@
                 mailer-host
                 mailer-port
                 service-domain-whitelist
-                service-noreply-address]
+                service-noreply-address
+                federated]
          :or {default-app-name "forgejo instance"
-              service-domain-whitelist fqdn}}
+              service-domain-whitelist fqdn
+              federated false}}
         config]
     (->
      (yaml/load-as-edn "forgejo/appini-env-configmap.yaml")
@@ -85,7 +87,8 @@
      (cm/replace-all-matching-values-by-new-value "MAILERHOST" mailer-host)
      (cm/replace-all-matching-values-by-new-value "MAILERPORT" mailer-port)
      (cm/replace-all-matching-values-by-new-value "WHITELISTDOMAINS" service-domain-whitelist)
-     (cm/replace-all-matching-values-by-new-value "NOREPLY" service-noreply-address))))
+     (cm/replace-all-matching-values-by-new-value "NOREPLY" service-noreply-address)
+     (cm/replace-all-matching-values-by-new-value "FEDERATED" (str federated)))))
 
 (defn generate-secrets
   [auth]
@@ -120,8 +123,14 @@
 ; ToDo: Need to add  federated-image-name to config? Or hardcode?
 ; ToDo: Need to add  default image-name to config? Or hardcode?
 (defn-spec generate-deployment pred/map-or-seq?
-  [config config?]
-  (yaml/load-as-edn "forgejo/deployment.yaml"))
+  [config]
+   (let [{:keys [federated]} config]
+
+         ; TODO: if 
+     if (= federated true)
+     (->
+      (yaml/load-as-edn "forgejo/deployment.yaml")
+      (cm/replace-all-matching-values-by-new-value "codeberg.org/forgejo/forgejo:1.19" "domaindrivenarchitecture/c4k-forgejo-fed"))))
 
 (defn generate-service
   []
diff --git a/src/main/resources/forgejo/appini-env-configmap.yaml b/src/main/resources/forgejo/appini-env-configmap.yaml
index 632d02a..c9d8c33 100644
--- a/src/main/resources/forgejo/appini-env-configmap.yaml
+++ b/src/main/resources/forgejo/appini-env-configmap.yaml
@@ -24,7 +24,7 @@ data:
   RUN_USER: git
 
   #[federation]
-  FORGEJO__federation__ENABLED: "true"
+  FORGEJO__federation__ENABLED: FEDERATED
   
   #[indexer]
   FORGEJO__indexer__ISSUE_INDEXER_PATH: /data/gitea/indexers/issues.bleve

From 01cbdea137ee15d01ec8003717d1dcad2ff12992 Mon Sep 17 00:00:00 2001
From: erik <erik.seiert@meissa-gmbh.de>
Date: Wed, 7 Jun 2023 11:26:56 +0200
Subject: [PATCH 16/29] require image name

---
 src/main/cljc/dda/c4k_forgejo/forgejo.cljc | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/main/cljc/dda/c4k_forgejo/forgejo.cljc b/src/main/cljc/dda/c4k_forgejo/forgejo.cljc
index 0a011dd..88ac2b3 100644
--- a/src/main/cljc/dda/c4k_forgejo/forgejo.cljc
+++ b/src/main/cljc/dda/c4k_forgejo/forgejo.cljc
@@ -36,6 +36,7 @@
 (def config-defaults {:issuer "staging"})
 
 (def config? (s/keys :req-un [::fqdn
+                              ::forgejo-image-name
                               ::mailer-from
                               ::mailer-host
                               ::mailer-port

From 9881f8ded571e14546b11db3752e084defcc7fb7 Mon Sep 17 00:00:00 2001
From: erik <erik.seiert@meissa-gmbh.de>
Date: Wed, 7 Jun 2023 11:27:31 +0200
Subject: [PATCH 17/29] hardcode image names

---
 src/main/cljc/dda/c4k_forgejo/forgejo.cljc | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/main/cljc/dda/c4k_forgejo/forgejo.cljc b/src/main/cljc/dda/c4k_forgejo/forgejo.cljc
index 88ac2b3..1ec99e8 100644
--- a/src/main/cljc/dda/c4k_forgejo/forgejo.cljc
+++ b/src/main/cljc/dda/c4k_forgejo/forgejo.cljc
@@ -54,6 +54,9 @@
   [total]
   total)
 
+(def federated-image-name "codeberg.org/meissa/forgejo:federated-latest")
+(def non-federated-image-name "codeberg.org/forgejo/forgejo:1.19")
+
 #?(:cljs
    (defmethod yaml/load-resource :forgejo [resource-name]
      (case resource-name

From 61ad6c289fd6d20a17ef29a12c706d6d3296d972 Mon Sep 17 00:00:00 2001
From: erik <erik.seiert@meissa-gmbh.de>
Date: Wed, 7 Jun 2023 11:28:16 +0200
Subject: [PATCH 18/29] Update appini generation

---
 src/main/cljc/dda/c4k_forgejo/forgejo.cljc | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/main/cljc/dda/c4k_forgejo/forgejo.cljc b/src/main/cljc/dda/c4k_forgejo/forgejo.cljc
index 1ec99e8..ab90e8e 100644
--- a/src/main/cljc/dda/c4k_forgejo/forgejo.cljc
+++ b/src/main/cljc/dda/c4k_forgejo/forgejo.cljc
@@ -71,6 +71,7 @@
 (defn generate-appini-env
   [config]
   (let [{:keys [default-app-name
+                deploy-federated
                 fqdn
                 mailer-from
                 mailer-host
@@ -78,8 +79,8 @@
                 service-domain-whitelist
                 service-noreply-address]
          :or {default-app-name "forgejo instance"
-              service-domain-whitelist fqdn}}
-        config]
+              service-domain-whitelist fqdn}} config
+        deploy-federated-bool (boolean (Boolean/valueOf deploy-federated))]
     (->
      (yaml/load-as-edn "forgejo/appini-env-configmap.yaml")
      (cm/replace-all-matching-values-by-new-value "APPNAME" default-app-name)
@@ -89,7 +90,10 @@
      (cm/replace-all-matching-values-by-new-value "MAILERHOST" mailer-host)
      (cm/replace-all-matching-values-by-new-value "MAILERPORT" mailer-port)
      (cm/replace-all-matching-values-by-new-value "WHITELISTDOMAINS" service-domain-whitelist)
-     (cm/replace-all-matching-values-by-new-value "NOREPLY" service-noreply-address))))
+     (cm/replace-all-matching-values-by-new-value "NOREPLY" service-noreply-address)
+     #(if deploy-federated-bool
+        (cm/replace-all-matching-values-by-new-value % "IS_FEDERATED" "true")
+        (cm/replace-all-matching-values-by-new-value % "IS_FEDERATED" "false")))))
 
 (defn generate-secrets
   [auth]

From 8f020a8d70ae19d3c66e302e443ebb9faeecccb2 Mon Sep 17 00:00:00 2001
From: erik <erik.seiert@meissa-gmbh.de>
Date: Wed, 7 Jun 2023 11:28:50 +0200
Subject: [PATCH 19/29] remove todos, update format

---
 src/main/cljc/dda/c4k_forgejo/forgejo.cljc | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/src/main/cljc/dda/c4k_forgejo/forgejo.cljc b/src/main/cljc/dda/c4k_forgejo/forgejo.cljc
index ab90e8e..d64e589 100644
--- a/src/main/cljc/dda/c4k_forgejo/forgejo.cljc
+++ b/src/main/cljc/dda/c4k_forgejo/forgejo.cljc
@@ -125,8 +125,7 @@
     (->     
      (yaml/load-as-edn "forgejo/datavolume.yaml")
      (cm/replace-all-matching-values-by-new-value "DATASTORAGESIZE" (str (str data-storage-size) "Gi")))))
-; ToDo: Need to add  federated-image-name to config? Or hardcode?
-; ToDo: Need to add  default image-name to config? Or hardcode?
+
 (defn-spec generate-deployment pred/map-or-seq?
   [config config?]
   (let [{:keys [deploy-federated]} config
@@ -135,7 +134,7 @@
      (yaml/load-as-edn "forgejo/deployment.yaml")
      #(if deploy-federated-bool
        (cm/replace-all-matching-values-by-new-value % "IMAGE_NAME" federated-image-name)
-       (cm/replace-all-matching-values-by-new-value %"IMAGE_NAME" default-name)))))
+       (cm/replace-all-matching-values-by-new-value % "IMAGE_NAME" non-federated-image-name)))))
 
 (defn generate-service
   []

From 4f6cb38101bf705a347bb446fee4e089891c34ac Mon Sep 17 00:00:00 2001
From: erik <erik.seiert@meissa-gmbh.de>
Date: Wed, 7 Jun 2023 11:29:06 +0200
Subject: [PATCH 20/29] update resources

---
 src/main/resources/forgejo/appini-env-configmap.yaml | 2 +-
 src/main/resources/forgejo/deployment.yaml           | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/main/resources/forgejo/appini-env-configmap.yaml b/src/main/resources/forgejo/appini-env-configmap.yaml
index 632d02a..68db912 100644
--- a/src/main/resources/forgejo/appini-env-configmap.yaml
+++ b/src/main/resources/forgejo/appini-env-configmap.yaml
@@ -24,7 +24,7 @@ data:
   RUN_USER: git
 
   #[federation]
-  FORGEJO__federation__ENABLED: "true"
+  FORGEJO__federation__ENABLED: IS_FEDERATED # ToDo: set false, in main too
   
   #[indexer]
   FORGEJO__indexer__ISSUE_INDEXER_PATH: /data/gitea/indexers/issues.bleve
diff --git a/src/main/resources/forgejo/deployment.yaml b/src/main/resources/forgejo/deployment.yaml
index 93fa1ef..81d5dcb 100644
--- a/src/main/resources/forgejo/deployment.yaml
+++ b/src/main/resources/forgejo/deployment.yaml
@@ -18,7 +18,7 @@ spec:
     spec:
       containers:
         - name: forgejo
-          image: codeberg.org/meissa/forgejo:federated-latest #codeberg.org/forgejo/forgejo:1.19
+          image: IMAGE_NAME
           imagePullPolicy: IfNotPresent
           # config settings
           envFrom:

From 4c7549c10c9edfd2aa0ac13f3bd052fd00f2a34a Mon Sep 17 00:00:00 2001
From: erik <erik.seiert@meissa-gmbh.de>
Date: Wed, 7 Jun 2023 11:38:47 +0200
Subject: [PATCH 21/29] Make replacing simpler

---
 src/main/cljc/dda/c4k_forgejo/forgejo.cljc | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/src/main/cljc/dda/c4k_forgejo/forgejo.cljc b/src/main/cljc/dda/c4k_forgejo/forgejo.cljc
index d64e589..0150326 100644
--- a/src/main/cljc/dda/c4k_forgejo/forgejo.cljc
+++ b/src/main/cljc/dda/c4k_forgejo/forgejo.cljc
@@ -91,9 +91,10 @@
      (cm/replace-all-matching-values-by-new-value "MAILERPORT" mailer-port)
      (cm/replace-all-matching-values-by-new-value "WHITELISTDOMAINS" service-domain-whitelist)
      (cm/replace-all-matching-values-by-new-value "NOREPLY" service-noreply-address)
-     #(if deploy-federated-bool
-        (cm/replace-all-matching-values-by-new-value % "IS_FEDERATED" "true")
-        (cm/replace-all-matching-values-by-new-value % "IS_FEDERATED" "false")))))
+     (cm/replace-all-matching-values-by-new-value "IS_FEDERATED" 
+                                                  (if deploy-federated-bool
+                                                    "true"
+                                                    "false")))))
 
 (defn generate-secrets
   [auth]
@@ -132,9 +133,10 @@
         deploy-federated-bool (boolean (Boolean/valueOf deploy-federated))]
     (->
      (yaml/load-as-edn "forgejo/deployment.yaml")
-     #(if deploy-federated-bool
-       (cm/replace-all-matching-values-by-new-value % "IMAGE_NAME" federated-image-name)
-       (cm/replace-all-matching-values-by-new-value % "IMAGE_NAME" non-federated-image-name)))))
+     (cm/replace-all-matching-values-by-new-value "IMAGE_NAME" 
+                                                  (if deploy-federated-bool
+                                                    federated-image-name
+                                                    non-federated-image-name)))))
 
 (defn generate-service
   []

From 9d99de13eb82ce315c0dcbf3d9e70bbabf6b063d Mon Sep 17 00:00:00 2001
From: erik <erik.seiert@meissa-gmbh.de>
Date: Wed, 7 Jun 2023 12:15:48 +0200
Subject: [PATCH 22/29] Use deploy-federated key with custom pred

---
 src/main/cljc/dda/c4k_forgejo/forgejo.cljc | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/src/main/cljc/dda/c4k_forgejo/forgejo.cljc b/src/main/cljc/dda/c4k_forgejo/forgejo.cljc
index 0150326..5d411b7 100644
--- a/src/main/cljc/dda/c4k_forgejo/forgejo.cljc
+++ b/src/main/cljc/dda/c4k_forgejo/forgejo.cljc
@@ -20,9 +20,15 @@
    (st/blank? input)
    (pred/string-of-separated-by? pred/fqdn-string? #"," input)))
 
+(defn boolean-string?
+  [input]
+  (and
+   (string? input)
+   (boolean? (Boolean/valueOf input))))
+
 (s/def ::default-app-name string?)
-(s/def ::forgejo-image-name string?)
 (s/def ::fqdn pred/fqdn-string?)
+(s/def ::deploy-federated boolean-string?)
 (s/def ::mailer-from pred/bash-env-string?)
 (s/def ::mailer-host pred/bash-env-string?)
 (s/def ::mailer-port pred/bash-env-string?)
@@ -35,8 +41,7 @@
 
 (def config-defaults {:issuer "staging"})
 
-(def config? (s/keys :req-un [::fqdn
-                              ::forgejo-image-name
+(def config? (s/keys :req-un [::fqdn                              
                               ::mailer-from
                               ::mailer-host
                               ::mailer-port

From 572ddb9747522ecff870aa28aaac167fc9e88be9 Mon Sep 17 00:00:00 2001
From: erik <erik.seiert@meissa-gmbh.de>
Date: Wed, 7 Jun 2023 12:16:15 +0200
Subject: [PATCH 23/29] Update tests

---
 .../cljc/dda/c4k_forgejo/forgejo_test.cljc    | 62 +++++++++++++++++++
 1 file changed, 62 insertions(+)

diff --git a/src/test/cljc/dda/c4k_forgejo/forgejo_test.cljc b/src/test/cljc/dda/c4k_forgejo/forgejo_test.cljc
index ef03fa6..a068e00 100644
--- a/src/test/cljc/dda/c4k_forgejo/forgejo_test.cljc
+++ b/src/test/cljc/dda/c4k_forgejo/forgejo_test.cljc
@@ -7,6 +7,7 @@
    [dda.c4k-common.base64 :as b64]
    [dda.c4k-forgejo.forgejo :as cut]))
 
+(st/instrument `cut/generate-deployment)
 (st/instrument `cut/generate-appini-env)
 (st/instrument `cut/generate-ingress)
 (st/instrument `cut/generate-secrets)
@@ -14,6 +15,8 @@
 (deftest should-generate-appini-env
   (is (= {:APP_NAME-c1 "",
           :APP_NAME-c2 "test forgejo",
+          :FORGEJO__federation__ENABLED-c1 "false",
+          :FORGEJO__federation__ENABLED-c2 "true",
           :FORGEJO__mailer__FROM-c1 "",
           :FORGEJO__mailer__FROM-c2 "test@test.com",
           :FORGEJO__mailer__SMTP_ADDR-c1 "m.t.de",
@@ -31,6 +34,7 @@
           :FORGEJO__service__NO_REPLY_ADDRESS-c1 "",
           :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"                                                
                                                 :mailer-from ""
                                                 :mailer-host "m.t.de"
@@ -39,6 +43,7 @@
                                                 :service-noreply-address ""
                                                 })
                       (cut/generate-appini-env {:default-app-name "test forgejo"
+                                                :deploy-federated "true"
                                                 :fqdn "test.com"                                                 
                                                 :mailer-from "test@test.com"
                                                 :mailer-host "mail.test.com"
@@ -47,6 +52,63 @@
                                                 :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"}},
+            :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"}},
+            :spec
+            {:containers
+             [{:name "forgejo",
+               :image "codeberg.org/meissa/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 "",
           :FORGEJO__database__USER-c2 (b64/encode "pg-user"),

From 8016e041aacd00e235e807e552cd368d14b7e5a0 Mon Sep 17 00:00:00 2001
From: erik <erik.seiert@meissa-gmbh.de>
Date: Wed, 7 Jun 2023 12:34:39 +0200
Subject: [PATCH 24/29] Add arg to generate-deployment

---
 src/main/cljc/dda/c4k_forgejo/core.cljc | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/main/cljc/dda/c4k_forgejo/core.cljc b/src/main/cljc/dda/c4k_forgejo/core.cljc
index d63b477..e9ddd7f 100644
--- a/src/main/cljc/dda/c4k_forgejo/core.cljc
+++ b/src/main/cljc/dda/c4k_forgejo/core.cljc
@@ -11,6 +11,7 @@
 (def config-defaults {:issuer "staging"})
 
 (def config? (s/keys :req-un [::forgejo/fqdn 
+                              ::forgejo/deploy-federated
                               ::forgejo/mailer-from 
                               ::forgejo/mailer-host 
                               ::forgejo/mailer-port
@@ -43,7 +44,7 @@
                    (postgres/generate-deployment {:postgres-image "postgres:14"
                                                   :postgres-size :2gb})
                    (postgres/generate-service)
-                   (forgejo/generate-deployment)
+                   (forgejo/generate-deployment config)
                    (forgejo/generate-service)
                    (forgejo/generate-service-ssh)                   
                    (forgejo/generate-data-volume config)

From 746d1da6851a44160b61573faca5ff757b38d68a Mon Sep 17 00:00:00 2001
From: erik <erik.seiert@meissa-gmbh.de>
Date: Wed, 7 Jun 2023 12:37:27 +0200
Subject: [PATCH 25/29] Use up to date automation script

---
 copy-and-build-dda-io.sh => build-and-move-frontend.sh | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
 rename copy-and-build-dda-io.sh => build-and-move-frontend.sh (60%)

diff --git a/copy-and-build-dda-io.sh b/build-and-move-frontend.sh
similarity index 60%
rename from copy-and-build-dda-io.sh
rename to build-and-move-frontend.sh
index fbdc37a..25ace30 100644
--- a/copy-and-build-dda-io.sh
+++ b/build-and-move-frontend.sh
@@ -7,11 +7,17 @@ set -o errexit
 set -eo pipefail
 
 # dirs
-srcDir="/home/$USER/"
+srcDir="/home/$USER/repo/c4k/c4k-forgejo/public/js/"
 srcName="main.js"
-targetDir="/home/$USER/"
+targetDir="/home/$USER/repo/website/dda-io/content/templates/js/"
 targetName="c4k-forgejo.js"
 
+echo "build test"
+shadow-cljs compile test
+
+echo "test"
+node target/node-tests.js
+
 echo "build"
 shadow-cljs compile frontend
 

From fe97bbea291f15ccc2a57033ee0705978b9ecf9c Mon Sep 17 00:00:00 2001
From: erik <erik.seiert@meissa-gmbh.de>
Date: Wed, 7 Jun 2023 12:55:54 +0200
Subject: [PATCH 26/29] Implement boolean-from-string

---
 src/main/cljc/dda/c4k_forgejo/forgejo.cljc | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/src/main/cljc/dda/c4k_forgejo/forgejo.cljc b/src/main/cljc/dda/c4k_forgejo/forgejo.cljc
index 5d411b7..531e5eb 100644
--- a/src/main/cljc/dda/c4k_forgejo/forgejo.cljc
+++ b/src/main/cljc/dda/c4k_forgejo/forgejo.cljc
@@ -20,11 +20,17 @@
    (st/blank? input)
    (pred/string-of-separated-by? pred/fqdn-string? #"," input)))
 
+(defn boolean-from-string [input]
+  (cond
+    (= input "true") true
+    (= input "false") false
+    :else nil))
+
 (defn boolean-string?
   [input]
   (and
    (string? input)
-   (boolean? (Boolean/valueOf input))))
+   (boolean? (boolean-from-string input))))
 
 (s/def ::default-app-name string?)
 (s/def ::fqdn pred/fqdn-string?)
@@ -85,7 +91,7 @@
                 service-noreply-address]
          :or {default-app-name "forgejo instance"
               service-domain-whitelist fqdn}} config
-        deploy-federated-bool (boolean (Boolean/valueOf deploy-federated))]
+        deploy-federated-bool (boolean-from-string deploy-federated)]
     (->
      (yaml/load-as-edn "forgejo/appini-env-configmap.yaml")
      (cm/replace-all-matching-values-by-new-value "APPNAME" default-app-name)
@@ -135,7 +141,7 @@
 (defn-spec generate-deployment pred/map-or-seq?
   [config config?]
   (let [{:keys [deploy-federated]} config
-        deploy-federated-bool (boolean (Boolean/valueOf deploy-federated))]
+        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" 

From 8dda6fb152f25d842ec2399d12360f3d2232a685 Mon Sep 17 00:00:00 2001
From: erik <erik.seiert@meissa-gmbh.de>
Date: Wed, 7 Jun 2023 13:18:32 +0200
Subject: [PATCH 27/29] Make messages clearer

---
 build-and-move-frontend.sh | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/build-and-move-frontend.sh b/build-and-move-frontend.sh
index 25ace30..48d5f56 100644
--- a/build-and-move-frontend.sh
+++ b/build-and-move-frontend.sh
@@ -10,7 +10,7 @@ set -eo pipefail
 srcDir="/home/$USER/repo/c4k/c4k-forgejo/public/js/"
 srcName="main.js"
 targetDir="/home/$USER/repo/website/dda-io/content/templates/js/"
-targetName="c4k-forgejo.js"
+targetName="c4k-gitea.js"
 
 echo "build test"
 shadow-cljs compile test
@@ -18,11 +18,11 @@ shadow-cljs compile test
 echo "test"
 node target/node-tests.js
 
-echo "build"
+echo "build frontend"
 shadow-cljs compile frontend
 
 echo "move and rename file"
 cp $srcDir$srcName $targetDir$targetName
 
-echo "build"
+echo "run"
 (cd $targetDir; lein ring server)

From 3c30c69cea80a3046a12c648b9fd3c7e044ca5a1 Mon Sep 17 00:00:00 2001
From: erik <erik.seiert@meissa-gmbh.de>
Date: Wed, 7 Jun 2023 13:19:00 +0200
Subject: [PATCH 28/29] Update frontend

---
 src/main/cljs/dda/c4k_forgejo/browser.cljs | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/src/main/cljs/dda/c4k_forgejo/browser.cljs b/src/main/cljs/dda/c4k_forgejo/browser.cljs
index 910e99c..e5b5696 100644
--- a/src/main/cljs/dda/c4k_forgejo/browser.cljs
+++ b/src/main/cljs/dda/c4k_forgejo/browser.cljs
@@ -30,8 +30,10 @@
        "domain"
        (cm/concat-vec
         (br/generate-input-field "fqdn" "Your fqdn:" "repo.test.de")
+        (br/generate-input-field "deploy-federated" "Deploy a federated version of forgejo:" "false")
         (br/generate-input-field "mailer-from" "Your mailer email address:" "test@test.de")
-        (br/generate-input-field "mailer-host-port" "Your mailer host with port:" "test.de:123")
+        (br/generate-input-field "mailer-host" "Your mailer host:" "test.de")
+        (br/generate-input-field "mailer-port" "Your mailer port:" "123")
         (br/generate-input-field "service-noreply-address" "Your noreply domain:" "test.de")
         (br/generate-input-field "issuer" "(Optional) Your issuer prod/staging:" "")
         (br/generate-input-field "app-name" "(Optional) Your app name:" "")
@@ -66,8 +68,10 @@
         domain-whitelist (br/get-content-from-element "domain-whitelist" :optional true)]
     (merge
      {:fqdn (br/get-content-from-element "fqdn")
+      :deploy-federated (br/get-content-from-element "deploy-federated")
       :mailer-from (br/get-content-from-element "mailer-from")
-      :mailer-host-port (br/get-content-from-element "mailer-host-port")
+      :mailer-host (br/get-content-from-element "mailer-host")
+      :mailer-port (br/get-content-from-element "mailer-port")
       :service-noreply-address (br/get-content-from-element "service-noreply-address")
       :volume-total-storage-size (br/get-content-from-element "volume-total-storage-size" :deserializer js/parseInt)}     
      (when (not (st/blank? issuer))
@@ -80,8 +84,10 @@
 
 (defn validate-all! []
   (br/validate! "fqdn" ::forgejo/fqdn)
+  (br/validate! "deploy-federated" ::forgejo/deploy-federated)
   (br/validate! "mailer-from" ::forgejo/mailer-from)
-  (br/validate! "mailer-host-port" ::forgejo/mailer-host-port)
+  (br/validate! "mailer-host" ::forgejo/mailer-host)
+  (br/validate! "mailer-port" ::forgejo/mailer-port)
   (br/validate! "service-noreply-address" ::forgejo/service-noreply-address)
   (br/validate! "issuer" ::forgejo/issuer :optional true)
   (br/validate! "app-name" ::forgejo/default-app-name :optional true)
@@ -108,8 +114,10 @@
                                    core/k8s-objects)
                                (br/set-output!)))))
   (add-validate-listener "fqdn")
+  (add-validate-listener "deploy-federated")
   (add-validate-listener "mailer-from")
-  (add-validate-listener "mailer-host-port")
+  (add-validate-listener "mailer-host")
+  (add-validate-listener "mailer-port")
   (add-validate-listener "service-noreply-address")
   (add-validate-listener "app-name")
   (add-validate-listener "domain-whitelist")  

From da7bf16b9a4d86fcd68093cd324a3e0aaa9cc24e Mon Sep 17 00:00:00 2001
From: erik <erik.seiert@meissa-gmbh.de>
Date: Wed, 7 Jun 2023 13:21:16 +0200
Subject: [PATCH 29/29] Remove ToDo

---
 src/main/resources/forgejo/appini-env-configmap.yaml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/main/resources/forgejo/appini-env-configmap.yaml b/src/main/resources/forgejo/appini-env-configmap.yaml
index 68db912..935de1c 100644
--- a/src/main/resources/forgejo/appini-env-configmap.yaml
+++ b/src/main/resources/forgejo/appini-env-configmap.yaml
@@ -24,7 +24,7 @@ data:
   RUN_USER: git
 
   #[federation]
-  FORGEJO__federation__ENABLED: IS_FEDERATED # ToDo: set false, in main too
+  FORGEJO__federation__ENABLED: IS_FEDERATED
   
   #[indexer]
   FORGEJO__indexer__ISSUE_INDEXER_PATH: /data/gitea/indexers/issues.bleve