2021-06-14 21:23:14 +02:00
|
|
|
|
|
|
|
import * as fs from "fs";
|
2021-10-06 17:22:52 +02:00
|
|
|
import { join as pathJoin, dirname as pathDirname, } from "path";
|
2021-06-14 21:23:14 +02:00
|
|
|
|
|
|
|
export const containerLaunchScriptBasename = "start_keycloak_testing_container.sh";
|
|
|
|
|
|
|
|
/** Files for being able to run a hot reload keycloak container */
|
|
|
|
export function generateDebugFiles(
|
|
|
|
params: {
|
2021-10-07 15:37:35 +02:00
|
|
|
keycloakVersion: "11.0.3" | "15.0.2";
|
2021-08-04 16:12:54 +02:00
|
|
|
themeName: string;
|
2021-06-14 21:23:14 +02:00
|
|
|
keycloakThemeBuildingDirPath: string;
|
|
|
|
}
|
|
|
|
) {
|
|
|
|
|
2021-10-06 17:22:52 +02:00
|
|
|
const { themeName, keycloakThemeBuildingDirPath, keycloakVersion } = params;
|
2021-06-14 21:23:14 +02:00
|
|
|
|
|
|
|
fs.writeFileSync(
|
|
|
|
pathJoin(keycloakThemeBuildingDirPath, "Dockerfile"),
|
|
|
|
Buffer.from(
|
|
|
|
[
|
2021-10-06 17:22:52 +02:00
|
|
|
`FROM jboss/keycloak:${keycloakVersion}`,
|
2021-06-14 21:23:14 +02:00
|
|
|
"",
|
|
|
|
"USER root",
|
|
|
|
"",
|
|
|
|
"WORKDIR /",
|
|
|
|
"",
|
|
|
|
"ADD configuration /opt/jboss/keycloak/standalone/configuration/",
|
|
|
|
"",
|
|
|
|
'ENTRYPOINT [ "/opt/jboss/tools/docker-entrypoint.sh" ]',
|
|
|
|
].join("\n"),
|
|
|
|
"utf8"
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2021-08-04 16:12:54 +02:00
|
|
|
const dockerImage = `${themeName}/keycloak-hot-reload`;
|
2021-06-14 21:23:14 +02:00
|
|
|
const containerName = "keycloak-testing-container";
|
|
|
|
|
|
|
|
fs.writeFileSync(
|
|
|
|
pathJoin(keycloakThemeBuildingDirPath, containerLaunchScriptBasename),
|
|
|
|
Buffer.from(
|
|
|
|
[
|
|
|
|
"#!/bin/bash",
|
|
|
|
"",
|
|
|
|
`cd ${keycloakThemeBuildingDirPath}`,
|
|
|
|
"",
|
|
|
|
`docker rm ${containerName} || true`,
|
|
|
|
"",
|
|
|
|
`docker build . -t ${dockerImage}`,
|
|
|
|
"",
|
|
|
|
"docker run \\",
|
2021-10-07 15:37:35 +02:00
|
|
|
" -p 8080:8080 \\",
|
|
|
|
` --name ${containerName} \\`,
|
|
|
|
" -e KEYCLOAK_USER=admin \\",
|
|
|
|
" -e KEYCLOAK_PASSWORD=admin \\",
|
|
|
|
" -e JAVA_OPTS=-Dkeycloak.profile=preview \\",
|
|
|
|
` -v ${pathJoin(keycloakThemeBuildingDirPath, "src", "main", "resources", "theme", themeName)
|
2021-08-04 16:12:54 +02:00
|
|
|
}:/opt/jboss/keycloak/themes/${themeName}:rw \\`,
|
2021-10-07 15:37:35 +02:00
|
|
|
` -it ${dockerImage}:latest`,
|
2021-06-14 21:23:14 +02:00
|
|
|
""
|
|
|
|
].join("\n"),
|
|
|
|
"utf8"
|
|
|
|
),
|
|
|
|
{ "mode": 0o755 }
|
|
|
|
);
|
|
|
|
|
2021-10-06 17:22:52 +02:00
|
|
|
const standaloneHaFilePath = pathJoin(keycloakThemeBuildingDirPath, "configuration", `standalone-ha.xml`);
|
2021-06-14 21:23:14 +02:00
|
|
|
|
|
|
|
try { fs.mkdirSync(pathDirname(standaloneHaFilePath)); } catch { }
|
|
|
|
|
|
|
|
fs.writeFileSync(
|
|
|
|
standaloneHaFilePath,
|
2021-10-06 17:22:52 +02:00
|
|
|
fs.readFileSync(
|
|
|
|
pathJoin(
|
|
|
|
__dirname,
|
|
|
|
`standalone-ha_${keycloakVersion}.xml`
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.toString("utf8")
|
|
|
|
.replace(
|
|
|
|
new RegExp([
|
|
|
|
"<staticMaxAge>2592000</staticMaxAge>",
|
|
|
|
"<cacheThemes>true</cacheThemes>",
|
|
|
|
"<cacheTemplates>true</cacheTemplates>"
|
|
|
|
].join("\\s*"), "g"
|
|
|
|
),
|
|
|
|
[
|
|
|
|
"<staticMaxAge>-1</staticMaxAge>",
|
|
|
|
"<cacheThemes>false</cacheThemes>",
|
|
|
|
"<cacheTemplates>false</cacheTemplates>"
|
|
|
|
].join("\n")
|
|
|
|
)
|
2021-06-14 21:23:14 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
}
|