Skip to content

Commit

Permalink
refactor: embed config file into a typescript variable and remove ini…
Browse files Browse the repository at this point in the history
…tialize_sql property
  • Loading branch information
hpp222 committed Oct 16, 2023
1 parent 492b9b6 commit e02069a
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 16 deletions.
1 change: 0 additions & 1 deletion entryPoint.txt

This file was deleted.

10 changes: 4 additions & 6 deletions src/keycloak.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import * as fs from 'fs';
import * as path from 'path';
import * as cdk from 'aws-cdk-lib';
import {
aws_certificatemanager as certmgr,
Expand Down Expand Up @@ -749,8 +747,8 @@ export class ContainerService extends Construct {

let containerPort = 8443;
let protocol = elbv2.ApplicationProtocol.HTTPS;
let entryPoint = fs.readFileSync(path.join(__dirname, '../entryPoint.txt'), 'utf8').split(',');
let workingDirectory = '/opt/keycloak';
let entryPoint = undefined;
let workingDirectory = undefined;
const image = props.containerImage ?? ecs.ContainerImage.fromRegistry(this.getKeyCloakDockerImageUri(props.keycloakVersion.version));
const isQuarkusDistribution = parseInt(props.keycloakVersion.version.split('.')[0]) > 16;
let environment: {[key: string]: string} = {
Expand Down Expand Up @@ -785,6 +783,8 @@ export class ContainerService extends Construct {
if (isQuarkusDistribution) {
containerPort = 8080;
protocol = elbv2.ApplicationProtocol.HTTP;
entryPoint = 'sh,-c,touch cache-ispn-jdbc-ping.xml && echo "<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?> <infinispan xmlns:xsi=\\"http://www.w3.org/2001/XMLSchema-instance\\" xsi:schemaLocation=\\"urn:infinispan:config:11.0 http://www.infinispan.org/schemas/infinispan-config-11.0.xsd\\" xmlns=\\"urn:infinispan:config:11.0\\"> <jgroups> <stack name=\\"jdbc-ping-tcp\\" extends=\\"tcp\\"> <JDBC_PING connection_driver=\\"com.mysql.cj.jdbc.Driver\\" connection_username=\\"\\\${env.KC_DB_USERNAME}\\" connection_password=\\"\\\${env.KC_DB_PASSWORD}\\" connection_url=\\"jdbc:mysql://\\\${env.KC_DB_URL_HOST}/\\\${env.KC_DB_URL_DATABASE}\\" info_writer_sleep_time=\\"500\\" remove_all_data_on_view_change=\\"true\\" stack.combine=\\"REPLACE\\" stack.position=\\"MPING\\" /> </stack> </jgroups> <cache-container name=\\"keycloak\\"> <transport lock-timeout=\\"60000\\" stack=\\"jdbc-ping-tcp\\"/> <local-cache name=\\"realms\\"> <encoding> <key media-type=\\"application/x-java-object\\"/> <value media-type=\\"application/x-java-object\\"/> </encoding> <memory max-count=\\"10000\\"/> </local-cache> <local-cache name=\\"users\\"> <encoding> <key media-type=\\"application/x-java-object\\"/> <value media-type=\\"application/x-java-object\\"/> </encoding> <memory max-count=\\"10000\\"/> </local-cache> <distributed-cache name=\\"sessions\\" owners=\\"3\\"> <expiration lifespan=\\"-1\\"/> </distributed-cache> <distributed-cache name=\\"authenticationSessions\\" owners=\\"3\\"> <expiration lifespan=\\"-1\\"/> </distributed-cache> <distributed-cache name=\\"offlineSessions\\" owners=\\"3\\"> <expiration lifespan=\\"-1\\"/> </distributed-cache> <distributed-cache name=\\"clientSessions\\" owners=\\"3\\"> <expiration lifespan=\\"-1\\"/> </distributed-cache> <distributed-cache name=\\"offlineClientSessions\\" owners=\\"3\\"> <expiration lifespan=\\"-1\\"/> </distributed-cache> <distributed-cache name=\\"loginFailures\\" owners=\\"3\\"> <expiration lifespan=\\"-1\\"/> </distributed-cache> <local-cache name=\\"authorization\\"> <encoding> <key media-type=\\"application/x-java-object\\"/> <value media-type=\\"application/x-java-object\\"/> </encoding> <memory max-count=\\"10000\\"/> </local-cache> <replicated-cache name=\\"work\\"> <expiration lifespan=\\"-1\\"/> </replicated-cache> <local-cache name=\\"keys\\"> <encoding> <key media-type=\\"application/x-java-object\\"/> <value media-type=\\"application/x-java-object\\"/> </encoding> <expiration max-idle=\\"3600000\\"/> <memory max-count=\\"1000\\"/> </local-cache> <distributed-cache name=\\"actionTokens\\" owners=\\"3\\"> <encoding> <key media-type=\\"application/x-java-object\\"/> <value media-type=\\"application/x-java-object\\"/> </encoding> <expiration max-idle=\\"-1\\" lifespan=\\"-1\\" interval=\\"300000\\"/> <memory max-count=\\"-1\\"/> </distributed-cache> </cache-container></infinispan>" > cache-ispn-jdbc-ping.xml && cp cache-ispn-jdbc-ping.xml /opt/keycloak/conf/cache-ispn-jdbc-ping.xml && /opt/keycloak/bin/kc.sh build && /opt/keycloak/bin/kc.sh start'.split(',');
workingDirectory = '/opt/keycloak';
environment = {
KC_DB: 'mysql',
KC_DB_URL_DATABASE: 'keycloak',
Expand All @@ -794,9 +794,7 @@ export class ContainerService extends Construct {
KC_HOSTNAME: props.hostname!,
KC_HOSTNAME_STRICT_BACKCHANNEL: 'true',
KC_PROXY: 'edge',
INITIALIZE_SQL: 'CREATE TABLE IF NOT EXISTS JGROUPSPING (own_addr varchar(200) NOT NULL, cluster_name varchar(200) NOT NULL, ping_data VARBINARY(255), constraint PK_JGROUPSPING PRIMARY KEY (own_addr, cluster_name));',
KC_CACHE_CONFIG_FILE: 'cache-ispn-jdbc-ping.xml',

};
secrets = {
KC_DB_PASSWORD: ecs.Secret.fromSecretsManager(props.database.secret, 'password'),
Expand Down
6 changes: 1 addition & 5 deletions test/__snapshots__/integ.snapshot.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions test/cluster-quarkus.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,10 +421,6 @@ test('with env', () => {
Name: 'KC_PROXY',
Value: 'edge',
},
{
Name: 'INITIALIZE_SQL',
Value: 'CREATE TABLE IF NOT EXISTS JGROUPSPING (own_addr varchar(200) NOT NULL, cluster_name varchar(200) NOT NULL, ping_data VARBINARY(255), constraint PK_JGROUPSPING PRIMARY KEY (own_addr, cluster_name));',
},
{
Name: 'KC_CACHE_CONFIG_FILE',
Value: 'cache-ispn-jdbc-ping.xml',
Expand Down

0 comments on commit e02069a

Please sign in to comment.