diff --git a/src/bin/build-keycloak-theme/generateDebugFiles/generateDebugFiles.ts b/src/bin/build-keycloak-theme/generateDebugFiles/generateDebugFiles.ts new file mode 100644 index 00000000..5e93b189 --- /dev/null +++ b/src/bin/build-keycloak-theme/generateDebugFiles/generateDebugFiles.ts @@ -0,0 +1,74 @@ + +import * as fs from "fs"; +import { join as pathJoin, dirname as pathDirname, basename as pathBasename } from "path"; + +export const containerLaunchScriptBasename = "start_keycloak_testing_container.sh"; + +/** Files for being able to run a hot reload keycloak container */ +export function generateDebugFiles( + params: { + packageJsonName: string; + keycloakThemeBuildingDirPath: string; + } +) { + + const { packageJsonName, keycloakThemeBuildingDirPath } = params; + + fs.writeFileSync( + pathJoin(keycloakThemeBuildingDirPath, "Dockerfile"), + Buffer.from( + [ + "FROM jboss/keycloak:11.0.3", + "", + "USER root", + "", + "WORKDIR /", + "", + "ADD configuration /opt/jboss/keycloak/standalone/configuration/", + "", + 'ENTRYPOINT [ "/opt/jboss/tools/docker-entrypoint.sh" ]', + ].join("\n"), + "utf8" + ) + ); + + const dockerImage = `${packageJsonName}/keycloak-hot-reload`; + 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 \\", + " -p 8080:8080 \\", + ` --name ${containerName} \\`, + " -e KEYCLOAK_USER=admin \\", + " -e KEYCLOAK_PASSWORD=admin \\", + ` -v ${pathJoin(keycloakThemeBuildingDirPath, "src", "main", "resources", "theme", packageJsonName) + }:/opt/jboss/keycloak/themes/${packageJsonName}:rw \\`, + ` -it ${dockerImage}:latest`, + "" + ].join("\n"), + "utf8" + ), + { "mode": 0o755 } + ); + + const standaloneHaFilePath = pathJoin(keycloakThemeBuildingDirPath, "configuration", "standalone-ha.xml"); + + try { fs.mkdirSync(pathDirname(standaloneHaFilePath)); } catch { } + + fs.writeFileSync( + standaloneHaFilePath, + fs.readFileSync(pathJoin(__dirname, pathBasename(standaloneHaFilePath))) + ); + +} \ No newline at end of file diff --git a/src/bin/build-keycloak-theme/generateDebugFiles/index.ts b/src/bin/build-keycloak-theme/generateDebugFiles/index.ts index 5e93b189..3115f415 100644 --- a/src/bin/build-keycloak-theme/generateDebugFiles/index.ts +++ b/src/bin/build-keycloak-theme/generateDebugFiles/index.ts @@ -1,74 +1 @@ - -import * as fs from "fs"; -import { join as pathJoin, dirname as pathDirname, basename as pathBasename } from "path"; - -export const containerLaunchScriptBasename = "start_keycloak_testing_container.sh"; - -/** Files for being able to run a hot reload keycloak container */ -export function generateDebugFiles( - params: { - packageJsonName: string; - keycloakThemeBuildingDirPath: string; - } -) { - - const { packageJsonName, keycloakThemeBuildingDirPath } = params; - - fs.writeFileSync( - pathJoin(keycloakThemeBuildingDirPath, "Dockerfile"), - Buffer.from( - [ - "FROM jboss/keycloak:11.0.3", - "", - "USER root", - "", - "WORKDIR /", - "", - "ADD configuration /opt/jboss/keycloak/standalone/configuration/", - "", - 'ENTRYPOINT [ "/opt/jboss/tools/docker-entrypoint.sh" ]', - ].join("\n"), - "utf8" - ) - ); - - const dockerImage = `${packageJsonName}/keycloak-hot-reload`; - 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 \\", - " -p 8080:8080 \\", - ` --name ${containerName} \\`, - " -e KEYCLOAK_USER=admin \\", - " -e KEYCLOAK_PASSWORD=admin \\", - ` -v ${pathJoin(keycloakThemeBuildingDirPath, "src", "main", "resources", "theme", packageJsonName) - }:/opt/jboss/keycloak/themes/${packageJsonName}:rw \\`, - ` -it ${dockerImage}:latest`, - "" - ].join("\n"), - "utf8" - ), - { "mode": 0o755 } - ); - - const standaloneHaFilePath = pathJoin(keycloakThemeBuildingDirPath, "configuration", "standalone-ha.xml"); - - try { fs.mkdirSync(pathDirname(standaloneHaFilePath)); } catch { } - - fs.writeFileSync( - standaloneHaFilePath, - fs.readFileSync(pathJoin(__dirname, pathBasename(standaloneHaFilePath))) - ); - -} \ No newline at end of file +export * from "./generateDebugFiles"; \ No newline at end of file diff --git a/src/bin/install-builtin-keycloak-themes.ts b/src/bin/install-builtin-keycloak-themes.ts index 9d5d06ea..625a4cff 100644 --- a/src/bin/install-builtin-keycloak-themes.ts +++ b/src/bin/install-builtin-keycloak-themes.ts @@ -1,6 +1,6 @@ #!/usr/bin/env node -import { keycloakThemeBuildingDirPath } from "./build-keycloak-theme/build-keycloak-theme"; +import { keycloakThemeBuildingDirPath } from "./build-keycloak-theme"; import { downloadAndUnzip } from "./tools/downloadAndUnzip"; import { join as pathJoin } from "path";