2021-06-14 21:23:14 +02:00
|
|
|
import * as fs from "fs";
|
2021-10-11 21:35:40 +02:00
|
|
|
import { join as pathJoin, dirname as pathDirname } from "path";
|
2022-01-20 02:52:31 +01:00
|
|
|
import type { KeycloakVersion } from "../../KeycloakVersion";
|
2022-04-07 01:35:19 +02:00
|
|
|
import { getIsM1 } from "../../tools/isM1";
|
2021-06-14 21:23:14 +02:00
|
|
|
|
2021-10-12 00:26:29 +02:00
|
|
|
export const containerLaunchScriptBasename = "start_keycloak_testing_container.sh";
|
2021-06-14 21:23:14 +02:00
|
|
|
|
|
|
|
/** Files for being able to run a hot reload keycloak container */
|
2022-01-20 02:52:31 +01:00
|
|
|
export function generateDebugFiles(params: { keycloakVersion: KeycloakVersion; themeName: string; 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(
|
|
|
|
[
|
2022-04-07 01:35:19 +02:00
|
|
|
`FROM ${
|
|
|
|
getIsM1()
|
|
|
|
? "eduardosanzb/keycloak@sha256:b1f5bc674eaff6f4e7b37808b9863440310ff93c282fc9bff812377be48bf519"
|
|
|
|
: `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"),
|
2021-10-11 21:35:40 +02:00
|
|
|
"utf8",
|
|
|
|
),
|
2021-06-14 21:23:14 +02:00
|
|
|
);
|
|
|
|
|
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 \\",
|
2021-10-11 21:35:40 +02:00
|
|
|
` -v ${pathJoin(
|
|
|
|
keycloakThemeBuildingDirPath,
|
|
|
|
"src",
|
|
|
|
"main",
|
|
|
|
"resources",
|
|
|
|
"theme",
|
|
|
|
themeName,
|
|
|
|
)}:/opt/jboss/keycloak/themes/${themeName}:rw \\`,
|
2021-10-07 15:37:35 +02:00
|
|
|
` -it ${dockerImage}:latest`,
|
2021-10-11 21:35:40 +02:00
|
|
|
"",
|
2021-06-14 21:23:14 +02:00
|
|
|
].join("\n"),
|
2021-10-11 21:35:40 +02:00
|
|
|
"utf8",
|
2021-06-14 21:23:14 +02:00
|
|
|
),
|
2021-10-11 21:35:40 +02:00
|
|
|
{ "mode": 0o755 },
|
2021-06-14 21:23:14 +02:00
|
|
|
);
|
|
|
|
|
2021-10-12 00:26:29 +02:00
|
|
|
const standaloneHaFilePath = pathJoin(keycloakThemeBuildingDirPath, "configuration", `standalone-ha.xml`);
|
2021-06-14 21:23:14 +02:00
|
|
|
|
2021-10-11 21:35:40 +02:00
|
|
|
try {
|
|
|
|
fs.mkdirSync(pathDirname(standaloneHaFilePath));
|
|
|
|
} catch {}
|
2021-06-14 21:23:14 +02:00
|
|
|
|
|
|
|
fs.writeFileSync(
|
|
|
|
standaloneHaFilePath,
|
2021-10-11 21:35:40 +02:00
|
|
|
fs
|
2021-10-12 00:26:29 +02:00
|
|
|
.readFileSync(pathJoin(__dirname, `standalone-ha_${keycloakVersion}.xml`))
|
2021-10-06 17:22:52 +02:00
|
|
|
.toString("utf8")
|
|
|
|
.replace(
|
2021-10-11 21:35:40 +02:00
|
|
|
new RegExp(
|
2021-10-12 00:26:29 +02:00
|
|
|
["<staticMaxAge>2592000</staticMaxAge>", "<cacheThemes>true</cacheThemes>", "<cacheTemplates>true</cacheTemplates>"].join("\\s*"),
|
2021-10-11 21:35:40 +02:00
|
|
|
"g",
|
2021-10-06 17:22:52 +02:00
|
|
|
),
|
2021-10-12 00:26:29 +02:00
|
|
|
["<staticMaxAge>-1</staticMaxAge>", "<cacheThemes>false</cacheThemes>", "<cacheTemplates>false</cacheTemplates>"].join("\n"),
|
2021-10-11 21:35:40 +02:00
|
|
|
),
|
2021-06-14 21:23:14 +02:00
|
|
|
);
|
2021-10-11 21:35:40 +02:00
|
|
|
}
|