Skip to content

Commit b71100b

Browse files
committed
add containerized keycloak.
1 parent b2098f9 commit b71100b

10 files changed

+1709
-0
lines changed

.env_sample

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Data directory
2+
DATA_DIR=./data
3+
4+
# Postgres config
5+
POSTGRES_PORT=5432
6+
KEYCLOAK_DB_USER=keycloak
7+
KEYCLOAK_DB_PASSWORD=password
8+
9+
# Keycloak config
10+
KEYCLOAK_PORT=8080
11+
12+
# pgAdmin config
13+
PGADMIN_PORT=5050

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Ignore data directory
2+
data/
3+
4+
# Env file
5+
.env

Dockerfile

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
FROM quay.io/keycloak/keycloak:22.0.1 as builder
2+
3+
COPY --chown=keycloak:keycloak config/providers /opt/keycloak/providers/
4+
5+
WORKDIR /opt/keycloak
6+
7+
# For demonstration purposes only, please make sure to use proper certificates in production instead
8+
RUN keytool -genkeypair -storepass password -storetype PKCS12 -keyalg RSA -keysize 2048 -dname "CN=server" -alias server -ext "SAN:c=DNS:localhost,IP:127.0.0.1" -keystore conf/server.keystore
9+
RUN /opt/keycloak/bin/kc.sh build
10+
11+
12+
FROM quay.io/keycloak/keycloak:22.0
13+
COPY --from=builder /opt/keycloak/ /opt/keycloak/
14+
15+
# Enable health and metrics support
16+
ENV KC_HEALTH_ENABLED=true
17+
ENV KC_METRICS_ENABLED=true
18+
19+
# Uncomment this line to install custom themes (it should point to the right directory)
20+
# COPY config/themes/custom /opt/keycloak/themes/custom
21+
22+
COPY config/jdbc/cache-ispn-jdbc-ping.xml /opt/keycloak/conf/cache-ispn-jdbc-ping.xml
23+
ENV KC_CACHE_CONFIG_FILE=cache-ispn-jdbc-ping.xml
24+
25+
ENTRYPOINT ["/opt/keycloak/bin/kc.sh"]

config/jdbc/cache-ispn-jdbc-ping.xml

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Copyright 2019 Red Hat, Inc. and/or its affiliates
4+
~ and other contributors as indicated by the @author tags.
5+
~
6+
~ Licensed under the Apache License, Version 2.0 (the "License");
7+
~ you may not use this file except in compliance with the License.
8+
~ You may obtain a copy of the License at
9+
~
10+
~ http://www.apache.org/licenses/LICENSE-2.0
11+
~
12+
~ Unless required by applicable law or agreed to in writing, software
13+
~ distributed under the License is distributed on an "AS IS" BASIS,
14+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
~ See the License for the specific language governing permissions and
16+
~ limitations under the License.
17+
-->
18+
19+
<infinispan
20+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
21+
xsi:schemaLocation="urn:infinispan:config:14.0 http://www.infinispan.org/schemas/infinispan-config-14.0.xsd"
22+
xmlns="urn:infinispan:config:14.0">
23+
<jgroups>
24+
<stack name="postgres-jdbc-ping-tcp" extends="tcp">
25+
<TCP external_addr="${env.JGROUPS_DISCOVERY_EXTERNAL_IP:127.0.0.1}" />
26+
<JDBC_PING connection_driver="org.postgresql.Driver"
27+
connection_username="${env.KC_DB_USERNAME}" connection_password="${env.KC_DB_PASSWORD}"
28+
connection_url="${env.KC_DB_URL}"
29+
initialize_sql="CREATE SCHEMA IF NOT EXISTS ${env.KC_DB_SCHEMA:public}; CREATE TABLE IF NOT EXISTS ${env.KC_DB_SCHEMA:public}.JGROUPSPING (own_addr varchar(200) NOT NULL, cluster_name varchar(200) NOT NULL, bind_addr varchar(200) NOT NULL, updated timestamp default current_timestamp, ping_data BYTEA, constraint PK_JGROUPSPING PRIMARY KEY (own_addr, cluster_name));"
30+
insert_single_sql="INSERT INTO ${env.KC_DB_SCHEMA:public}.JGROUPSPING (own_addr, cluster_name, bind_addr, updated, ping_data) values (?, ?, '${env.JGROUPS_DISCOVERY_EXTERNAL_IP:127.0.0.1}', NOW(), ?);"
31+
delete_single_sql="DELETE FROM ${env.KC_DB_SCHEMA:public}.JGROUPSPING WHERE own_addr=? AND cluster_name=?;"
32+
select_all_pingdata_sql="SELECT ping_data, own_addr, cluster_name FROM ${env.KC_DB_SCHEMA:public}.JGROUPSPING WHERE cluster_name=?"
33+
info_writer_sleep_time="500"
34+
remove_all_data_on_view_change="true"
35+
stack.combine="REPLACE"
36+
stack.position="MPING" />
37+
</stack>
38+
</jgroups>
39+
<cache-container name="keycloak">
40+
<transport lock-timeout="60000" stack="${env.KC_DB}-jdbc-ping-tcp"/>
41+
<local-cache name="realms">
42+
<encoding>
43+
<key media-type="application/x-java-object"/>
44+
<value media-type="application/x-java-object"/>
45+
</encoding>
46+
<memory max-count="10000"/>
47+
</local-cache>
48+
<local-cache name="users">
49+
<encoding>
50+
<key media-type="application/x-java-object"/>
51+
<value media-type="application/x-java-object"/>
52+
</encoding>
53+
<memory max-count="10000"/>
54+
</local-cache>
55+
<distributed-cache name="sessions" owners="2">
56+
<expiration lifespan="-1"/>
57+
</distributed-cache>
58+
<distributed-cache name="authenticationSessions" owners="2">
59+
<expiration lifespan="-1"/>
60+
</distributed-cache>
61+
<distributed-cache name="offlineSessions" owners="2">
62+
<expiration lifespan="-1"/>
63+
</distributed-cache>
64+
<distributed-cache name="clientSessions" owners="2">
65+
<expiration lifespan="-1"/>
66+
</distributed-cache>
67+
<distributed-cache name="offlineClientSessions" owners="2">
68+
<expiration lifespan="-1"/>
69+
</distributed-cache>
70+
<distributed-cache name="loginFailures" owners="2">
71+
<expiration lifespan="-1"/>
72+
</distributed-cache>
73+
<local-cache name="authorization">
74+
<encoding>
75+
<key media-type="application/x-java-object"/>
76+
<value media-type="application/x-java-object"/>
77+
</encoding>
78+
<memory max-count="10000"/>
79+
</local-cache>
80+
<replicated-cache name="work">
81+
<expiration lifespan="-1"/>
82+
</replicated-cache>
83+
<local-cache name="keys">
84+
<encoding>
85+
<key media-type="application/x-java-object"/>
86+
<value media-type="application/x-java-object"/>
87+
</encoding>
88+
<expiration max-idle="3600000"/>
89+
<memory max-count="1000"/>
90+
</local-cache>
91+
<distributed-cache name="actionTokens" owners="2">
92+
<encoding>
93+
<key media-type="application/x-java-object"/>
94+
<value media-type="application/x-java-object"/>
95+
</encoding>
96+
<expiration max-idle="-1" lifespan="-1" interval="300000"/>
97+
<memory max-count="-1"/>
98+
</distributed-cache>
99+
</cache-container>
100+
</infinispan>
Binary file not shown.

0 commit comments

Comments
 (0)