commit bf4b3d3eb4dc1e8fb3fcb3738bfe9d8807131552 Author: Sebastian Hugentobler Date: Sun Aug 22 14:30:25 2021 +0200 initial commit diff --git a/.gitignore b/.gitignore new file mode 100755 index 0000000..af0faab --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*~ +.DS_Store +*.swp diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..5a2305b --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,12 @@ +variables: + IMAGE_NAME: thallian/keycloak +build: + stage: build + script: + - docker login -u $DOCKER_USER -p $DOCKER_PASSWORD $DOCKER_REGISTRY + - docker build -t $IMAGE_NAME:$CI_COMMIT_SHA . + - docker build -t $IMAGE_NAME:$CI_COMMIT_REF_NAME . + - docker build -t $IMAGE_NAME:latest . + - docker push $IMAGE_NAME:$CI_COMMIT_SHA + - docker push $IMAGE_NAME:$CI_COMMIT_REF_NAME + - docker push $IMAGE_NAME:latest diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..bc91c4b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,22 @@ +FROM alpine:3.14 AS builder + +ENV VERSION=15.0.2 +ENV SHA256_SUM=1915e33b3789eb426fda06676e39b9ddf3a7b563e1e2381a92a02da814dad047 + +RUN wget "https://github.com/keycloak/keycloak/releases/download/$VERSION/keycloak-$VERSION.tar.gz" +RUN echo "$SHA256_SUM keycloak-$VERSION.tar.gz" | sha256sum -c - || exit 1 +RUN mkdir -p /keycloak +RUN tar xvf keycloak-$VERSION.tar.gz -C /keycloak --strip 1 + +FROM thallian/confd-env:latest + +RUN addgroup -g 2222 keycloak +RUN adduser -h /home/keycloak -u 2222 -D -G keycloak keycloak + +RUN apk add --no-cache \ + openjdk11-jre-headless + +COPY --from=builder --chown=keycloak:keycloak /keycloak /home/keycloak/server + +ADD /rootfs / + diff --git a/README.md b/README.md new file mode 100644 index 0000000..85d1f31 --- /dev/null +++ b/README.md @@ -0,0 +1,19 @@ +[Keycloak](https://www.keycloak.org/) server with postgre backend. + +# Environment Variables +## ADMIN_PASSWORD +Password for the admin user. + +## DB_URL +Database url in jdbc form (https://jdbc.postgresql.org/documentation/80/connect.html). + +## DB_USER +- default: keycloak +Database user. + +## DB_PASSWORD +Password for the database user. + +# Ports +- 8080 + diff --git a/rootfs/etc/confd/conf.d/stanalone.xml.toml b/rootfs/etc/confd/conf.d/stanalone.xml.toml new file mode 100644 index 0000000..191cc30 --- /dev/null +++ b/rootfs/etc/confd/conf.d/stanalone.xml.toml @@ -0,0 +1,6 @@ +[template] +src = "standalone.xml.tmpl" +dest = "/home/keycloak/server/standalone/configuration/standalone.xml" +uid = 2222 +gid = 2222 +mode = "0640" diff --git a/rootfs/etc/confd/templates/standalone.xml.tmpl b/rootfs/etc/confd/templates/standalone.xml.tmpl new file mode 100644 index 0000000..96905ad --- /dev/null +++ b/rootfs/etc/confd/templates/standalone.xml.tmpl @@ -0,0 +1,618 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE + h2 + + sa + sa + + + + {{ getenv "DB_URL" }} + postgresql + + {{ getenv "DB_USER" "keycloak" }} + {{ getenv "DB_PASSWORD" }} + + + + + org.postgresql.xa.PGXADataSource + + + org.h2.jdbcx.JdbcDataSource + + + + + + + + + false + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + auth + + + classpath:${jboss.home.dir}/providers/* + + + master + 900 + + 2592000 + true + true + ${jboss.home.dir}/themes + + + + + + + + + + + + + jpa + + + basic + + + + + + + + + + + + + + + + + + + default + + + + + + + + ${keycloak.jta.lookup.provider:jboss} + + + + + + + + + + + ${keycloak.x509cert.lookup.provider:default} + + + + default + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/rootfs/etc/cont-init.d/admin-user b/rootfs/etc/cont-init.d/admin-user new file mode 100644 index 0000000..8ab7fa9 --- /dev/null +++ b/rootfs/etc/cont-init.d/admin-user @@ -0,0 +1,3 @@ +#!/usr/bin/with-contenv sh + s6-setuidgid keycloak /home/keycloak/server/bin/add-user-keycloak.sh -r master -u admin -p $ADMIN_PASSWORD + diff --git a/rootfs/etc/services.d/keycloak/run b/rootfs/etc/services.d/keycloak/run new file mode 100644 index 0000000..a2f0a5f --- /dev/null +++ b/rootfs/etc/services.d/keycloak/run @@ -0,0 +1,3 @@ +#!/usr/bin/with-contenv sh + +s6-setuidgid keycloak /home/keycloak/server/bin/standalone.sh -b 0.0.0.0 diff --git a/rootfs/home/keycloak/server/modules/system/layers/keycloak/org/postgresql/module.xml b/rootfs/home/keycloak/server/modules/system/layers/keycloak/org/postgresql/module.xml new file mode 100644 index 0000000..8a622cd --- /dev/null +++ b/rootfs/home/keycloak/server/modules/system/layers/keycloak/org/postgresql/module.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/rootfs/home/keycloak/server/modules/system/layers/keycloak/org/postgresql/postgresql-42.2.23.jar b/rootfs/home/keycloak/server/modules/system/layers/keycloak/org/postgresql/postgresql-42.2.23.jar new file mode 100644 index 0000000..00ad52e Binary files /dev/null and b/rootfs/home/keycloak/server/modules/system/layers/keycloak/org/postgresql/postgresql-42.2.23.jar differ