From 7882946b891295e9f6083ebb348e95075177cb61 Mon Sep 17 00:00:00 2001 From: Edwin Steiner Date: Wed, 17 Apr 2024 10:15:58 +0200 Subject: [PATCH] Module `helm` added for Kubernetes deployments. --- .gitignore | 3 + README.md | 1 + helm/pom.xml | 75 +++++++++++++++++++ .../keycloak-custom-chart/Chart.yaml | 8 ++ .../keycloak-custom-chart/values.yaml | 71 ++++++++++++++++++ helm/src/main/resources/Chart.yaml | 8 ++ helm/src/main/resources/values.yaml | 71 ++++++++++++++++++ pom.xml | 55 ++++++++++++-- 8 files changed, 284 insertions(+), 8 deletions(-) create mode 100644 helm/pom.xml create mode 100644 helm/src/generated/keycloak-custom-chart/Chart.yaml create mode 100644 helm/src/generated/keycloak-custom-chart/values.yaml create mode 100644 helm/src/main/resources/Chart.yaml create mode 100644 helm/src/main/resources/values.yaml diff --git a/.gitignore b/.gitignore index 43fbbb4..9336078 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,6 @@ release.properties # Postgres data /docker-compose/postgres/volume/ + +Chart.lock +helm/src/generated/**/*.tgz \ No newline at end of file diff --git a/README.md b/README.md index f4acf5d..50c61d3 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ This project is based on the [custom Keycloak template](https://github.com/inven - `container`: creates the custom docker image - `docker-compose`: provides a sample for launching the custom docker image - `extensions`: provides samples for Keycloak SPI implementations +- `helm`: provides a sample for installing the custom container image in Kubernetes using the Codecentric Helm Chart - `server`: provides a Keycloak installation for local development & testing - `themes`: provides samples for custom themes diff --git a/helm/pom.xml b/helm/pom.xml new file mode 100644 index 0000000..9e9f9d9 --- /dev/null +++ b/helm/pom.xml @@ -0,0 +1,75 @@ + + + 4.0.0 + + + parent + com.inventage.keycloak.custom + 1.0.0-SNAPSHOT + + + helm + helm + + + ${project.basedir}/src/generated/keycloak-custom-chart + + + docker-registry.inventage.com:10121 + + + + + + maven-resources-plugin + + + with-substitution + + copy-resources + + generate-resources + + ${chart.directory} + + + src/main/resources + true + + + + + + + + + io.kokuwa.maven + helm-maven-plugin + + + ${project.build.directory}/**/charts/**/charts/portal-lib + + ${chart.directory} + + + + default-cli + + false + false + keycloak-custom + + + ${chart.directory}/values.yaml + + + + + + + + + + \ No newline at end of file diff --git a/helm/src/generated/keycloak-custom-chart/Chart.yaml b/helm/src/generated/keycloak-custom-chart/Chart.yaml new file mode 100644 index 0000000..a9998e1 --- /dev/null +++ b/helm/src/generated/keycloak-custom-chart/Chart.yaml @@ -0,0 +1,8 @@ +name: keycloak-custom-chart +version: 1.0.0-SNAPSHOT +apiVersion: v2 + +dependencies: + - name: keycloakx + version: 2.3.0 + repository: "https://codecentric.github.io/helm-charts" diff --git a/helm/src/generated/keycloak-custom-chart/values.yaml b/helm/src/generated/keycloak-custom-chart/values.yaml new file mode 100644 index 0000000..9a37187 --- /dev/null +++ b/helm/src/generated/keycloak-custom-chart/values.yaml @@ -0,0 +1,71 @@ +keycloakx: + # This is an example configuration, for production grade configuration see the Keycloak documentation. + # See https://www.keycloak.org/server/configuration + # See https://www.keycloak.org/server/all-config + command: + - "/opt/keycloak/bin/kc-with-setup.sh" + - "--verbose" + - "start" + - "--http-enabled=true" + - "--http-port=8080" + - "--hostname-strict=false" + - "--hostname-strict-https=false" + - "--spi-events-listener-jboss-logging-success-level=info" + - "--spi-events-listener-jboss-logging-error-level=warn" + + image: + # The custom image repository + repository: docker-registry.inventage.com:10094/com.inventage.keycloak.custom.container + # Overrides the Keycloak image tag whose default is the chart appVersion + tag: 1.0.0-SNAPSHOT + + http: + relativePath: "/" + + extraEnv: | + - name: KEYCLOAK_ADMIN + valueFrom: + secretKeyRef: + name: {{ include "keycloak.fullname" . }}-admin-creds + key: user + - name: KEYCLOAK_ADMIN_PASSWORD + valueFrom: + secretKeyRef: + name: {{ include "keycloak.fullname" . }}-admin-creds + key: password + - name: JAVA_OPTS_APPEND + value: >- + -Djava.awt.headless=true + -Djgroups.dns.query={{ include "keycloak.fullname" . }}-headless + + dbchecker: + enabled: true + + database: + vendor: postgres + hostname: postgres-postgresql + port: 5432 + username: keycloak + password: keycloak + database: keycloak + + secrets: + admin-creds: + annotations: + my-test-annotation: Test secret for {{ include "keycloak.fullname" . }} + stringData: + user: admin + password: secret + + securityContext: + # See https://github.com/keycloak/keycloak/issues/11286 + # readOnlyRootFilesystem: true + allowPrivilegeEscalation: false + capabilities: + drop: + - ALL + + serviceAccount: + automountServiceAccountToken: "false" + imagePullSecrets: + - name: keycloak-custom diff --git a/helm/src/main/resources/Chart.yaml b/helm/src/main/resources/Chart.yaml new file mode 100644 index 0000000..6631c20 --- /dev/null +++ b/helm/src/main/resources/Chart.yaml @@ -0,0 +1,8 @@ +name: keycloak-custom-chart +version: ${project.version} +apiVersion: v2 + +dependencies: + - name: keycloakx + version: 2.3.0 + repository: "https://codecentric.github.io/helm-charts" diff --git a/helm/src/main/resources/values.yaml b/helm/src/main/resources/values.yaml new file mode 100644 index 0000000..47bbf60 --- /dev/null +++ b/helm/src/main/resources/values.yaml @@ -0,0 +1,71 @@ +keycloakx: + # This is an example configuration, for production grade configuration see the Keycloak documentation. + # See https://www.keycloak.org/server/configuration + # See https://www.keycloak.org/server/all-config + command: + - "/opt/keycloak/bin/kc-with-setup.sh" + - "--verbose" + - "start" + - "--http-enabled=true" + - "--http-port=8080" + - "--hostname-strict=false" + - "--hostname-strict-https=false" + - "--spi-events-listener-jboss-logging-success-level=info" + - "--spi-events-listener-jboss-logging-error-level=warn" + + image: + # The custom image repository + repository: ${docker.registry}${docker.image.name} + # Overrides the Keycloak image tag whose default is the chart appVersion + tag: ${project.version} + + http: + relativePath: "/" + + extraEnv: | + - name: KEYCLOAK_ADMIN + valueFrom: + secretKeyRef: + name: {{ include "keycloak.fullname" . }}-admin-creds + key: user + - name: KEYCLOAK_ADMIN_PASSWORD + valueFrom: + secretKeyRef: + name: {{ include "keycloak.fullname" . }}-admin-creds + key: password + - name: JAVA_OPTS_APPEND + value: >- + -Djava.awt.headless=true + -Djgroups.dns.query={{ include "keycloak.fullname" . }}-headless + + dbchecker: + enabled: true + + database: + vendor: postgres + hostname: postgres-postgresql + port: 5432 + username: keycloak + password: keycloak + database: keycloak + + secrets: + admin-creds: + annotations: + my-test-annotation: Test secret for {{ include "keycloak.fullname" . }} + stringData: + user: admin + password: secret + + securityContext: + # See https://github.com/keycloak/keycloak/issues/11286 + # readOnlyRootFilesystem: true + allowPrivilegeEscalation: false + capabilities: + drop: + - ALL + + serviceAccount: + automountServiceAccountToken: "false" + imagePullSecrets: + - name: keycloak-custom diff --git a/pom.xml b/pom.xml index 780bc9d..9134e06 100644 --- a/pom.xml +++ b/pom.xml @@ -16,6 +16,7 @@ themes container docker-compose + helm @@ -26,7 +27,7 @@ ../../server/${keycloak.dir}/providers ../server/${keycloak.dir}/themes docker-registry.inventage.com:10094/ - ${project.groupId}.${project.artifactId} + com.inventage.keycloak.custom.container ${project.build.outputDirectory} true override @@ -82,13 +83,6 @@ ${testcontainers-keycloak.version} test - - - org.junit.jupiter - junit-jupiter-engine - ${junit-jupiter-engine.version} - test - org.testcontainers junit-jupiter @@ -234,6 +228,51 @@ + + + io.kokuwa.maven + helm-maven-plugin + 6.13.0 + true + + ${project.version} + ${project.basedir}/helm/target/chart + false + true + false + true + + ghcr + ghcr.io/keycloak-competence-center + NEXUS + ${env.GITHUB_ACTOR} + ${env.GITHUB_TOKEN} + + + ghcr + ghcr.io/keycloak-competence-center + NEXUS + ${env.GITHUB_ACTOR} + ${env.GITHUB_TOKEN} + + + + + default-upload + none + + + upload + + init + lint + package + push + + deploy + + +