From dda4ecb1fb13f12ec49d8afaf56967d07644a22f Mon Sep 17 00:00:00 2001 From: patdyn Date: Thu, 4 Jul 2024 10:47:18 +0200 Subject: [PATCH 1/9] Implement inline resources --- project.clj | 2 +- shadow-cljs.edn | 2 +- src/main/cljc/dda/c4k_keycloak/keycloak.cljc | 8 ++------ 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/project.clj b/project.clj index b8c66e1..f0c3083 100644 --- a/project.clj +++ b/project.clj @@ -5,7 +5,7 @@ :url "https://www.apache.org/licenses/LICENSE-2.0.html"} :dependencies [[org.clojure/clojure "1.11.1"] [org.clojure/tools.reader "1.3.6"] - [org.domaindrivenarchitecture/c4k-common-clj "6.0.1"]] + [org.domaindrivenarchitecture/c4k-common-clj "6.1.0"]] :target-path "target/%s/" :source-paths ["src/main/cljc" "src/main/clj"] diff --git a/shadow-cljs.edn b/shadow-cljs.edn index e3293f3..d98ed25 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-keycloak.browser/init}} diff --git a/src/main/cljc/dda/c4k_keycloak/keycloak.cljc b/src/main/cljc/dda/c4k_keycloak/keycloak.cljc index 9a5a208..3378846 100644 --- a/src/main/cljc/dda/c4k_keycloak/keycloak.cljc +++ b/src/main/cljc/dda/c4k_keycloak/keycloak.cljc @@ -1,7 +1,7 @@ (ns dda.c4k-keycloak.keycloak (:require [clojure.spec.alpha :as s] - #?(:cljs [shadow.resource :as rc]) + #?(:cljs [dda.c4k-common.macros :refer-macros [inline-resources]]) #?(:clj [orchestra.core :refer [defn-spec]] :cljs [orchestra.core :refer-macros [defn-spec]]) [dda.c4k-common.yaml :as yaml] @@ -23,11 +23,7 @@ #?(:cljs (defmethod yaml/load-resource :keycloak [resource-name] - (case resource-name - "keycloak/deployment.yaml" (rc/inline "keycloak/deployment.yaml") - "keycloak/secret.yaml" (rc/inline "keycloak/secret.yaml") - "keycloak/service.yaml" (rc/inline "keycloak/service.yaml") - (throw (js/Error. "Undefined Resource!"))))) + (get (inline-resources "keycloak") resource-name))) (defn-spec generate-ingress cp/map-or-seq? [config config?] From af1b305bd556821597f83eb1e4418845ac64b19b Mon Sep 17 00:00:00 2001 From: patdyn Date: Thu, 4 Jul 2024 11:18:14 +0200 Subject: [PATCH 2/9] Add build.py --- build.py | 235 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 235 insertions(+) create mode 100644 build.py diff --git a/build.py b/build.py new file mode 100644 index 0000000..f272f14 --- /dev/null +++ b/build.py @@ -0,0 +1,235 @@ +from os import environ +from subprocess import run +from pybuilder.core import init, task +from ddadevops import * + +default_task = "dev" +name = 'c4k-keycloak' +MODULE = 'not-used' +PROJECT_ROOT_PATH = '.' + +@init +def initialize(project): + project.build_depends_on("ddadevops>=4.7.0") + + input = { + "name": name, + "module": MODULE, + "stage": "notused", + "project_root_path": PROJECT_ROOT_PATH, + "build_types": [], + "mixin_types": ["RELEASE"], + "release_primary_build_file": "project.clj", + "release_secondary_build_files": [ + "package.json", + "infrastructure/backup/build.py", + "infrastructure/federated/build.py", + ], + "release_artifact_server_url": "https://repo.prod.meissa.de", + "release_organisation": "meissa", + "release_repository_name": name, + "release_artifacts": [ + "target/graalvm/" + name, + "target/uberjar/" + name + "-standalone.jar", + "target/frontend-build/" + name + ".js", + ], + } + + build = ReleaseMixin(project, input) + build.initialize_build_dir() + + +@task +def test_clj(project): + run("lein test", shell=True, check=True) + + +@task +def test_cljs(project): + run("shadow-cljs compile test", shell=True, check=True) + run("node target/node-tests.js", shell=True, check=True) + + +@task +def test_schema(project): + run("lein uberjar", shell=True, check=True) + run( + "java -jar target/uberjar/c4k-keycloak-standalone.jar " + + "src/test/resources/keycloak-test/valid-config.yaml " + + "src/test/resources/keycloak-test/valid-auth.yaml | " + + """kubeconform --kubernetes-version 1.23.0 --strict --skip "Certificate,Middleware" -""", + shell=True, + check=True, + ) + + +@task +def report_frontend(project): + run("mkdir -p target/frontend-build", shell=True, check=True) + run( + "shadow-cljs run shadow.cljs.build-report frontend target/frontend-build/build-report.html", + shell=True, + check=True, + ) + + +@task +def package_frontend(project): + run("mkdir -p target/frontend-build", shell=True, check=True) + run("shadow-cljs release frontend", shell=True, check=True) + run( + "cp public/js/main.js target/frontend-build/" + project.name + ".js", + shell=True, + check=True, + ) + run( + "sha256sum target/frontend-build/c4k-keycloak.js > target/frontend-build/" + project.name + ".js.sha256", + shell=True, + check=True, + ) + run( + "sha512sum target/frontend-build/c4k-keycloak.js > target/frontend-build/" + project.name + ".js.sha512", + shell=True, + check=True, + ) + + +@task +def package_uberjar(project): + run( + "sha256sum target/uberjar/c4k-keycloak-standalone.jar > target/uberjar/" + project.name + "-standalone.jar.sha256", + shell=True, + check=True, + ) + run( + "sha512sum target/uberjar/c4k-keycloak-standalone.jar > target/uberjar/" + project.name + "-standalone.jar.sha512", + shell=True, + check=True, + ) + + +@task +def package_native(project): + run( + "mkdir -p target/graalvm", + shell=True, + check=True, + ) + run( + "native-image " + + "--native-image-info " + + "--report-unsupported-elements-at-runtime " + + "--no-server " + + "--no-fallback " + + "--features=clj_easy.graal_build_time.InitClojureClasses " + + "-jar target/uberjar/" + project.name + "-standalone.jar " + + "-march=compatibility " + + "-H:IncludeResources=.*.yaml " + + "-H:IncludeResources=logback.xml " + + "-H:Log=registerResource:verbose " + + "-H:Name=target/graalvm/" + project.name + "", + shell=True, + check=True, + ) + run( + "sha256sum target/graalvm/c4k-keycloak > target/graalvm/" + project.name + ".sha256", + shell=True, + check=True, + ) + run( + "sha512sum target/graalvm/c4k-keycloak > target/graalvm/" + project.name + ".sha512", + shell=True, + check=True, + ) + + +@task +def inst(project): + run( + "lein uberjar", + shell=True, + check=True, + ) + package_native(project) + run( + "sudo install -m=755 target/uberjar/" + project.name + "-standalone.jar /usr/local/bin/" + project.name + "-standalone.jar", + shell=True, + check=True, + ) + run( + "sudo install -m=755 target/graalvm/" + project.name + " /usr/local/bin/" + project.name + "", + shell=True, + check=True, + ) + + +@task +def upload_clj(project): + run("lein deploy", shell=True, check=True) + + +@task +def lint(project): + #run( + # "lein eastwood", + # shell=True, + # check=True, + #) + run( + "lein ancient check", + shell=True, + check=True, + ) + + +@task +def patch(project): + linttest(project, "PATCH") + release(project) + + +@task +def minor(project): + linttest(project, "MINOR") + release(project) + + +@task +def major(project): + linttest(project, "MAJOR") + release(project) + + +@task +def dev(project): + linttest(project, "NONE") + + +@task +def prepare(project): + build = get_devops_build(project) + build.prepare_release() + + +@task +def tag(project): + build = get_devops_build(project) + build.tag_bump_and_push_release() + +@task +def publish_artifacts(project): + build = get_devops_build(project) + build.publish_artifacts() + +def release(project): + prepare(project) + tag(project) + + +def linttest(project, release_type): + build = get_devops_build(project) + build.update_release_type(release_type) + test_clj(project) + test_cljs(project) + test_schema(project) + lint(project) From 0293fea409f90b4745c815292a1eeeef71589614 Mon Sep 17 00:00:00 2001 From: patdyn Date: Thu, 4 Jul 2024 12:11:39 +0200 Subject: [PATCH 3/9] Update CI for native-image --- .gitlab-ci.yml | 94 +++++++++++++++++++------------------------------- 1 file changed, 36 insertions(+), 58 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 86e5cfa..cadce1a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -5,7 +5,7 @@ stages: - upload .cljs-job: &cljs - image: domaindrivenarchitecture/shadow-cljs + image: "domaindrivenarchitecture/ddadevops-clj-cljs:4.11.3" cache: key: ${CI_COMMIT_REF_SLUG} paths: @@ -13,38 +13,38 @@ stages: - .shadow-cljs/ - .m2 before_script: - - echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/.npmrc - - npm install + - export RELEASE_ARTIFACT_TOKEN=$MEISSA_REPO_BUERO_RW + - echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/.npmrc + - npm install .clj-uploadjob: &clj - image: domaindrivenarchitecture/lein + image: "domaindrivenarchitecture/ddadevops-clj:4.11.3" cache: key: ${CI_COMMIT_REF_SLUG} paths: - .m2 before_script: - - mkdir -p /root/.lein - - echo "{:auth {:repository-auth {#\"clojars\" {:username \"${CLOJARS_USER}\" :password \"${CLOJARS_TOKEN_DOMAINDRIVENARCHITECTURE}\" }}}}" > ~/.lein/profiles.clj - -test-cljs: - <<: *cljs - stage: build_and_test - script: - - shadow-cljs compile test - - node target/node-tests.js + - export RELEASE_ARTIFACT_TOKEN=$MEISSA_REPO_BUERO_RW + - mkdir -p /root/.lein + - echo "{:auth {:repository-auth {#\"clojars\" {:username \"${CLOJARS_USER}\" :password \"${CLOJARS_TOKEN_DOMAINDRIVENARCHITECTURE}\" }}}}" > ~/.lein/profiles.clj test-clj: <<: *clj stage: build_and_test script: - - lein test + - pyb test_clj + +test-cljs: + <<: *cljs + stage: build_and_test + script: + - pyb test_cljs test-schema: <<: *clj stage: build_and_test script: - - lein uberjar - - java -jar target/uberjar/c4k-keycloak-standalone.jar src/test/resources/keycloak-test/valid-config.yaml src/test/resources/keycloak-test/valid-auth.yaml | kubeconform --kubernetes-version 1.19.0 --strict --skip Certificate - + - pyb test_schema artifacts: paths: - target/uberjar @@ -53,8 +53,7 @@ report-frontend: <<: *cljs stage: package script: - - mkdir -p target/frontend-build - - shadow-cljs run shadow.cljs.build-report frontend target/frontend-build/build-report.html + - pyb report_frontend artifacts: paths: - target/frontend-build/build-report.html @@ -63,11 +62,7 @@ package-frontend: <<: *cljs stage: package script: - - mkdir -p target/frontend-build - - shadow-cljs release frontend - - cp public/js/main.js target/frontend-build/c4k-keycloak.js - - sha256sum target/frontend-build/c4k-keycloak.js > target/frontend-build/c4k-keycloak.js.sha256 - - sha512sum target/frontend-build/c4k-keycloak.js > target/frontend-build/c4k-keycloak.js.sha512 + - pyb package_frontend artifacts: paths: - target/frontend-build @@ -76,47 +71,30 @@ package-uberjar: <<: *clj stage: package script: - - sha256sum target/uberjar/c4k-keycloak-standalone.jar > target/uberjar/c4k-keycloak-standalone.jar.sha256 - - sha512sum target/uberjar/c4k-keycloak-standalone.jar > target/uberjar/c4k-keycloak-standalone.jar.sha512 + - pyb package_uberjar artifacts: paths: - target/uberjar -sast: - variables: - SAST_EXCLUDED_ANALYZERS: - bandit, brakeman, flawfinder, gosec, kubesec, phpcs-security-audit, - pmd-apex, security-code-scan, sobelow, spotbugs - stage: security - before_script: - - mkdir -p builds && cp -r target/ builds/ -include: - - template: Security/SAST.gitlab-ci.yml - -upload-clj-release: +package-native: <<: *clj - stage: upload - rules: - - if: '$CI_COMMIT_TAG != null' + stage: package script: - - lein deploy - -release: - image: registry.gitlab.com/gitlab-org/release-cli:latest - stage: upload - rules: - - if: '$CI_COMMIT_TAG != null' + - pyb package_native artifacts: paths: - - target/uberjar - - target/frontend-build + - target/graalvm + +release-to-clojars: + <<: *clj + <<: *tag_only + stage: upload script: - - apk --no-cache add curl - - | - release-cli create --name "Release $CI_COMMIT_TAG" --tag-name $CI_COMMIT_TAG \ - --assets-link "{\"name\":\"c4k-keycloak-standalone.jar\",\"url\":\"https://gitlab.com/domaindrivenarchitecture/c4k-keycloak/-/jobs/${CI_JOB_ID}/artifacts/file/target/uberjar/c4k-keycloak-standalone.jar\"}" \ - --assets-link "{\"name\":\"c4k-keycloak-standalone.jar.sha256\",\"url\":\"https://gitlab.com/domaindrivenarchitecture/c4k-keycloak/-/jobs/${CI_JOB_ID}/artifacts/file/target/uberjar/c4k-keycloak-standalone.jar.sha256\"}" \ - --assets-link "{\"name\":\"c4k-keycloak-standalone.jar.sha512\",\"url\":\"https://gitlab.com/domaindrivenarchitecture/c4k-keycloak/-/jobs/${CI_JOB_ID}/artifacts/file/target/uberjar/c4k-keycloak-standalone.jar.sha512\"}" \ - --assets-link "{\"name\":\"c4k-keycloak.js\",\"url\":\"https://gitlab.com/domaindrivenarchitecture/c4k-keycloak/-/jobs/${CI_JOB_ID}/artifacts/file/target/frontend-build/c4k-keycloak.js\"}" \ - --assets-link "{\"name\":\"c4k-keycloak.js.sha256\",\"url\":\"https://gitlab.com/domaindrivenarchitecture/c4k-keycloak/-/jobs/${CI_JOB_ID}/artifacts/file/target/frontend-build/c4k-keycloak.js.sha256\"}" \ - --assets-link "{\"name\":\"c4k-keycloak.js.sha512\",\"url\":\"https://gitlab.com/domaindrivenarchitecture/c4k-keycloak/-/jobs/${CI_JOB_ID}/artifacts/file/target/frontend-build/c4k-keycloak.js.sha512\"}" \ + - pyb upload_clj + +release-to-forgejo: + <<: *clj + <<: *tag_only + stage: upload + script: + - pyb publish_artifacts \ No newline at end of file From 94192a3e4292b0c076b7d1349605468b80f0666b Mon Sep 17 00:00:00 2001 From: patdyn Date: Thu, 4 Jul 2024 12:13:07 +0200 Subject: [PATCH 4/9] Update deps and docs for native image --- doc/Development.md | 43 +++++++++++------------ project.clj | 23 ++++-------- shadow-cljs.edn | 2 +- src/main/clj/dda/c4k_keycloak/uberjar.clj | 2 ++ 4 files changed, 29 insertions(+), 41 deletions(-) diff --git a/doc/Development.md b/doc/Development.md index bcb7a0a..c8e10ed 100644 --- a/doc/Development.md +++ b/doc/Development.md @@ -3,13 +3,13 @@ ## clj setup ### install leiningen -``` +```bash sudo apt install leiningen ``` or manually using Instructions on https://leiningen.org/#install ### install vscode + extensions -``` +```bash sudo snap install code ``` or with packages from https://code.visualstudio.com/Download @@ -18,7 +18,7 @@ install extension "Calva: Clojure & ClojureScript Interactive Programming" ## cljs / js-dev setup -``` +```bash sudo apt install npm sudo npm install -g npx @@ -32,47 +32,44 @@ npx shadow-cljs compile test ### create frontend script -``` +```bash npx shadow-cljs release frontend ``` ## graalvm-setup -``` -curl -LO https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-21.0.0.2/graalvm-ce-java11-linux-amd64-21.0.0.2.tar.gz +```bash +curl -LO https://github.com/graalvm/graalvm-ce-builds/releases/download/jdk-21.0.2/graalvm-community-jdk-21.0.2_linux-x64_bin.tar.gz # unpack -tar -xzf graalvm-ce-java11-linux-amd64-21.0.0.2.tar.gz +tar -xzf graalvm-community-jdk-21.0.2_linux-x64_bin.tar.gz -sudo mv graalvm-ce-java11-21.0.0.2 /usr/lib/jvm/ -sudo ln -s /usr/lib/jvm/graalvm-ce-java11-21.0.0.2 /usr/lib/jvm/graalvm -sudo ln -s /usr/lib/jvm/graalvm/bin/gu /usr/local/bin -sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/graalvm/bin/java 2 +sudo mv graalvm-community-openjdk-21.0.2+13.1 /usr/lib/jvm/ +sudo ln -s /usr/lib/jvm/graalvm-community-openjdk-21.0.2+13.1 /usr/lib/jvm/graalvm-21 +sudo ln -s /usr/lib/jvm/graalvm-21/bin/gu /usr/local/bin +sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/graalvm-21/bin/java 2 sudo update-alternatives --config java - -# install native-image in graalvm-ce-java11-linux-amd64-21.0.0.2/bin -sudo gu install native-image -sudo ln -s /usr/lib/jvm/graalvm/bin/native-image /usr/local/bin +sudo ln -s /usr/lib/jvm/graalvm-21/bin/native-image /usr/local/bin # deps sudo apt-get install build-essential libz-dev zlib1g-dev # build -cd ~/repo/dda/c4k-keycloak +cd ~/repo/c4k/c4k-keycloak lein uberjar mkdir -p target/graalvm lein native # execute -./target/graalvm/c4k-keycloak -h -./target/graalvm/c4k-keycloak src/test/resources/valid-config.edn src/test/resources/valid-auth.edn -./target/graalvm/c4k-keycloak src/test/resources/invalid-config.edn src/test/resources/invalid-auth.edn +./target/graalvm/c4k-cloud -h +./target/graalvm/c4k-cloud src/test/resources/valid-config.edn src/test/resources/valid-auth.edn +./target/graalvm/c4k-cloud src/test/resources/invalid-config.edn src/test/resources/invalid-auth.edn ``` ## c4k-setup ### install kubectl -``` +```bash sudo -i curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - echo "deb http://apt.kubernetes.io/ kubernetes-xenial main" \ @@ -83,7 +80,7 @@ kubectl completion bash >> /etc/bash_completion.d/kubernetes ### install kubeconform -``` +```bash curl -Lo /tmp/kubeconform.tar.gz https://github.com/yannh/kubeconform/releases/download/v0.4.7/kubeconform-linux-amd64.tar.gz tar -xf /tmp/kubeconform.tar.gz sudo cp kubeconform /usr/local/bin @@ -91,7 +88,7 @@ sudo cp kubeconform /usr/local/bin ### remote access to c4k -``` +```bash scp -r root@devops.test.meissa-gmbh.de:/home/c4k/.kube ~/ ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@devops.test.meissa-gmbh.de -L 8002:localhost:8002 -L 6443:192.168.5.1:6443 @@ -104,7 +101,7 @@ kubectl get pods ### deploy keycloak -``` +```bash java -jar target/uberjar/c4k-keycloak-standalone.jar valid-config.edn valid-auth.edn | kubeconform --kubernetes-version 1.19.0 --strict --skip Certificate - java -jar target/uberjar/c4k-keycloak-standalone.jar valid-config.edn my-auth.edn | kubectl apply -f - ``` diff --git a/project.clj b/project.clj index f0c3083..adb1e48 100644 --- a/project.clj +++ b/project.clj @@ -5,7 +5,7 @@ :url "https://www.apache.org/licenses/LICENSE-2.0.html"} :dependencies [[org.clojure/clojure "1.11.1"] [org.clojure/tools.reader "1.3.6"] - [org.domaindrivenarchitecture/c4k-common-clj "6.1.0"]] + [org.domaindrivenarchitecture/c4k-common-clj "6.1.3"]] :target-path "target/%s/" :source-paths ["src/main/cljc" "src/main/clj"] @@ -21,25 +21,14 @@ :uberjar {:aot :all :main dda.c4k-keycloak.uberjar :uberjar-name "c4k-keycloak-standalone.jar" - :dependencies [[org.clojure/tools.cli "1.0.214"] - [ch.qos.logback/logback-classic "1.4.5" + :dependencies [[org.clojure/tools.cli "1.0.219"] + [ch.qos.logback/logback-classic "1.4.14" :exclusions [com.sun.mail/javax.mail]] - [org.slf4j/jcl-over-slf4j "2.0.6"]]}} + [org.slf4j/jcl-over-slf4j "2.0.12"] + [com.github.clj-easy/graal-build-time "1.0.5"]]}} :release-tasks [["test"] ["vcs" "assert-committed"] ["change" "version" "leiningen.release/bump-version" "release"] ["vcs" "commit"] ["vcs" "tag" "--no-sign"] - ["change" "version" "leiningen.release/bump-version"]] - :aliases {"native" ["shell" - "native-image" - "--report-unsupported-elements-at-runtime" - "--initialize-at-build-time" - "-jar" "target/uberjar/c4k-keycloak-standalone.jar" - "-H:ResourceConfigurationFiles=graalvm-resource-config.json" - "-H:Log=registerResource" - "-H:Name=target/graalvm/${:name}"] - "inst" ["shell" - "sh" - "-c" - "lein uberjar && sudo install -m=755 target/uberjar/c4k-keycloak-standalone.jar /usr/local/bin/c4k-keycloak-standalone.jar"]}) + ["change" "version" "leiningen.release/bump-version"]]) diff --git a/shadow-cljs.edn b/shadow-cljs.edn index d98ed25..565406d 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.1.0"] + :dependencies [[org.domaindrivenarchitecture/c4k-common-cljs "6.1.3"] [hickory "0.7.1"]] :builds {:frontend {:target :browser :modules {:main {:init-fn dda.c4k-keycloak.browser/init}} diff --git a/src/main/clj/dda/c4k_keycloak/uberjar.clj b/src/main/clj/dda/c4k_keycloak/uberjar.clj index 8f829fa..b785be6 100644 --- a/src/main/clj/dda/c4k_keycloak/uberjar.clj +++ b/src/main/clj/dda/c4k_keycloak/uberjar.clj @@ -4,6 +4,8 @@ [dda.c4k-common.uberjar :as uberjar] [dda.c4k-keycloak.core :as core])) +(set! *warn-on-reflection* true) + (defn -main [& cmd-args] (uberjar/main-common "c4k-keycloak" From e838fdda7afe226c2bf7a4c516b8d7b32a5077a2 Mon Sep 17 00:00:00 2001 From: patdyn Date: Thu, 4 Jul 2024 12:13:41 +0200 Subject: [PATCH 5/9] Unlock experimental and update gitignore --- .gitignore | 1 + build.py | 1 + 2 files changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 37433f7..91791ca 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ target/ .lein-repl-history .lein-failures pom.* +reports/* # cljs .shadow-cljs diff --git a/build.py b/build.py index f272f14..a478684 100644 --- a/build.py +++ b/build.py @@ -124,6 +124,7 @@ def package_native(project): "--features=clj_easy.graal_build_time.InitClojureClasses " + "-jar target/uberjar/" + project.name + "-standalone.jar " + "-march=compatibility " + + "-H:+UnlockExperimentalVMOptions " + "-H:IncludeResources=.*.yaml " + "-H:IncludeResources=logback.xml " + "-H:Log=registerResource:verbose " + From f4bf41d374ec94ddb4f28d1a2dc6766a166b9004 Mon Sep 17 00:00:00 2001 From: patdyn Date: Thu, 4 Jul 2024 12:24:57 +0200 Subject: [PATCH 6/9] Add tag_only --- .gitlab-ci.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index cadce1a..9846f69 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -28,6 +28,12 @@ stages: - mkdir -p /root/.lein - echo "{:auth {:repository-auth {#\"clojars\" {:username \"${CLOJARS_USER}\" :password \"${CLOJARS_TOKEN_DOMAINDRIVENARCHITECTURE}\" }}}}" > ~/.lein/profiles.clj +.tag_only: &tag_only + rules: + - if: '$CI_PIPELINE_SOURCE == "merge_request_event"' + when: never + - if: '$CI_COMMIT_TAG =~ /^[0-9]+\.[0-9]+\.[0-9]+$/' + test-clj: <<: *clj stage: build_and_test From 3639f3d5e6d5b364822a05b3d5d569bbc556a68b Mon Sep 17 00:00:00 2001 From: patdyn Date: Thu, 4 Jul 2024 14:33:53 +0200 Subject: [PATCH 7/9] Add namespaces Also Update postgres usage --- src/main/cljc/dda/c4k_keycloak/core.cljc | 21 +++++++++++-------- src/main/resources/keycloak/deployment.yaml | 2 +- src/main/resources/keycloak/secret.yaml | 1 + src/main/resources/keycloak/service.yaml | 1 + .../cljc/dda/c4k_keycloak/keycloak_test.cljc | 4 ++-- 5 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/main/cljc/dda/c4k_keycloak/core.cljc b/src/main/cljc/dda/c4k_keycloak/core.cljc index 2f1f181..ce1c22b 100644 --- a/src/main/cljc/dda/c4k_keycloak/core.cljc +++ b/src/main/cljc/dda/c4k_keycloak/core.cljc @@ -8,7 +8,8 @@ [dda.c4k-common.monitoring :as mon] [dda.c4k-common.yaml :as yaml] [dda.c4k-common.postgres :as postgres] - [dda.c4k-keycloak.keycloak :as kc])) + [dda.c4k-keycloak.keycloak :as kc] + [dda.c4k-common.namespace :as ns])) (def default-storage-class :local-path) @@ -29,15 +30,17 @@ (filter #(not (nil? %)) (cm/concat-vec - [(postgres/generate-config {:postgres-size :2gb :db-name "keycloak"}) - (postgres/generate-secret auth) - (postgres/generate-pvc {:pv-storage-size-gb 30 - :pvc-storage-class-name default-storage-class}) - (postgres/generate-deployment :postgres-image "postgres:14") - (postgres/generate-service) - (kc/generate-secret auth) + (ns/generate (merge {:namespace "keycloak"} config)) + (postgres/generate (merge {:postgres-image "postgres:14" + :postgres-size :2gb + :db-name "keycloak" + :pv-storage-size-gb 30 + :pvc-storage-class-name default-storage-class + :namespace "keycloak"}) + auth) + [(kc/generate-secret auth) (kc/generate-service) (kc/generate-deployment config)] - (kc/generate-ingress config) + (kc/generate-ingress (merge {:namespace "keycloak"} config)) (when (:contains? config :mon-cfg) (mon/generate (:mon-cfg config) (:mon-auth auth))))))) diff --git a/src/main/resources/keycloak/deployment.yaml b/src/main/resources/keycloak/deployment.yaml index 4860375..f662cc2 100644 --- a/src/main/resources/keycloak/deployment.yaml +++ b/src/main/resources/keycloak/deployment.yaml @@ -2,7 +2,7 @@ apiVersion: apps/v1 kind: Deployment metadata: name: keycloak - namespace: default + namespace: keycloak labels: app: keycloak spec: diff --git a/src/main/resources/keycloak/secret.yaml b/src/main/resources/keycloak/secret.yaml index 43d0adc..a58bb8a 100644 --- a/src/main/resources/keycloak/secret.yaml +++ b/src/main/resources/keycloak/secret.yaml @@ -2,6 +2,7 @@ apiVersion: v1 kind: Secret metadata: name: keycloak-secret + namespace: keycloak type: Opaque data: keycloak-user: admin diff --git a/src/main/resources/keycloak/service.yaml b/src/main/resources/keycloak/service.yaml index 182b331..5926555 100644 --- a/src/main/resources/keycloak/service.yaml +++ b/src/main/resources/keycloak/service.yaml @@ -4,6 +4,7 @@ metadata: name: keycloak labels: service: keycloak + namespace: keycloak spec: ports: - name: "http" diff --git a/src/test/cljc/dda/c4k_keycloak/keycloak_test.cljc b/src/test/cljc/dda/c4k_keycloak/keycloak_test.cljc index 81f5682..d47adc1 100644 --- a/src/test/cljc/dda/c4k_keycloak/keycloak_test.cljc +++ b/src/test/cljc/dda/c4k_keycloak/keycloak_test.cljc @@ -10,7 +10,7 @@ (deftest should-generate-secret (is (= {:apiVersion "v1" :kind "Secret" - :metadata {:name "keycloak-secret"} + :metadata {:name "keycloak-secret", :namespace "keycloak"} :type "Opaque" :data {:keycloak-user "dXNlcg==" @@ -21,7 +21,7 @@ (is (= {:apiVersion "apps/v1", :kind "Deployment", :metadata - {:name "keycloak", :namespace "default", :labels {:app "keycloak"}}, + {:name "keycloak", :namespace "keycloak", :labels {:app "keycloak"}}, :spec {:replicas 1, :selector {:matchLabels {:app "keycloak"}}, From b5afdc0959fc411945aaa745c6476a15b6f7696e Mon Sep 17 00:00:00 2001 From: patdyn Date: Thu, 4 Jul 2024 14:43:33 +0200 Subject: [PATCH 8/9] Update deps --- project.clj | 2 +- shadow-cljs.edn | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/project.clj b/project.clj index adb1e48..cf4da4a 100644 --- a/project.clj +++ b/project.clj @@ -5,7 +5,7 @@ :url "https://www.apache.org/licenses/LICENSE-2.0.html"} :dependencies [[org.clojure/clojure "1.11.1"] [org.clojure/tools.reader "1.3.6"] - [org.domaindrivenarchitecture/c4k-common-clj "6.1.3"]] + [org.domaindrivenarchitecture/c4k-common-clj "6.3.1"]] :target-path "target/%s/" :source-paths ["src/main/cljc" "src/main/clj"] diff --git a/shadow-cljs.edn b/shadow-cljs.edn index 565406d..328ce8f 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.1.3"] + :dependencies [[org.domaindrivenarchitecture/c4k-common-cljs "6.3.1"] [hickory "0.7.1"]] :builds {:frontend {:target :browser :modules {:main {:init-fn dda.c4k-keycloak.browser/init}} From 85f44ea8d1f2155e6439589cf8dc81f7bef42ec8 Mon Sep 17 00:00:00 2001 From: patdyn Date: Thu, 4 Jul 2024 14:43:46 +0200 Subject: [PATCH 9/9] Add test task --- build.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/build.py b/build.py index a478684..0611cb6 100644 --- a/build.py +++ b/build.py @@ -40,18 +40,18 @@ def initialize(project): @task -def test_clj(project): +def test_clj(): run("lein test", shell=True, check=True) @task -def test_cljs(project): +def test_cljs(): run("shadow-cljs compile test", shell=True, check=True) run("node target/node-tests.js", shell=True, check=True) @task -def test_schema(project): +def test_schema(): run("lein uberjar", shell=True, check=True) run( "java -jar target/uberjar/c4k-keycloak-standalone.jar " @@ -62,6 +62,11 @@ def test_schema(project): check=True, ) +@task +def test(): + test_clj() + test_cljs() + test_schema() @task def report_frontend(project):