2022-04-09 20:17:20 +02:00
|
|
|
import * as fs from "fs";
|
2023-11-28 12:17:16 +01:00
|
|
|
import { join as pathJoin, relative as pathRelative, basename as pathBasename } from "path";
|
2022-08-16 14:41:06 +07:00
|
|
|
import { assert } from "tsafe/assert";
|
2024-01-30 06:38:26 +01:00
|
|
|
import type { BuildOptions } from "./buildOptions";
|
2024-05-14 04:57:38 +02:00
|
|
|
import { accountV1ThemeName } from "../constants";
|
2022-08-16 14:41:06 +07:00
|
|
|
|
|
|
|
export type BuildOptionsLike = {
|
2023-09-04 00:25:36 +02:00
|
|
|
keycloakifyBuildDirPath: string;
|
2024-05-14 04:57:38 +02:00
|
|
|
themeNames: string[];
|
2022-08-16 14:41:06 +07:00
|
|
|
};
|
|
|
|
|
2024-05-13 00:40:16 +02:00
|
|
|
assert<BuildOptions extends BuildOptionsLike ? true : false>();
|
2022-04-09 20:17:20 +02:00
|
|
|
|
|
|
|
generateStartKeycloakTestingContainer.basename = "start_keycloak_testing_container.sh";
|
|
|
|
|
|
|
|
const containerName = "keycloak-testing-container";
|
2024-05-12 19:16:59 +02:00
|
|
|
const keycloakVersion = "24.0.4";
|
2022-04-09 20:17:20 +02:00
|
|
|
|
|
|
|
/** Files for being able to run a hot reload keycloak container */
|
2024-05-14 04:57:38 +02:00
|
|
|
export function generateStartKeycloakTestingContainer(params: {
|
|
|
|
jarFilePath: string;
|
|
|
|
doesImplementAccountTheme: boolean;
|
|
|
|
buildOptions: BuildOptionsLike;
|
|
|
|
}) {
|
|
|
|
const { jarFilePath, doesImplementAccountTheme, buildOptions } = params;
|
2023-09-04 00:25:36 +02:00
|
|
|
|
|
|
|
const themeRelativeDirPath = pathJoin("src", "main", "resources", "theme");
|
2022-04-09 20:17:20 +02:00
|
|
|
|
|
|
|
fs.writeFileSync(
|
2023-09-04 00:25:36 +02:00
|
|
|
pathJoin(buildOptions.keycloakifyBuildDirPath, generateStartKeycloakTestingContainer.basename),
|
2022-04-09 20:17:20 +02:00
|
|
|
Buffer.from(
|
|
|
|
[
|
2023-01-22 17:28:27 -08:00
|
|
|
"#!/usr/bin/env bash",
|
2022-04-09 20:17:20 +02:00
|
|
|
"",
|
|
|
|
`docker rm ${containerName} || true`,
|
|
|
|
"",
|
2023-09-04 00:25:36 +02:00
|
|
|
`cd "${buildOptions.keycloakifyBuildDirPath}"`,
|
2022-04-09 20:17:20 +02:00
|
|
|
"",
|
|
|
|
"docker run \\",
|
|
|
|
" -p 8080:8080 \\",
|
|
|
|
` --name ${containerName} \\`,
|
|
|
|
" -e KEYCLOAK_ADMIN=admin \\",
|
|
|
|
" -e KEYCLOAK_ADMIN_PASSWORD=admin \\",
|
2023-11-28 12:17:16 +01:00
|
|
|
` -v "${pathJoin(
|
|
|
|
"$(pwd)",
|
|
|
|
pathRelative(buildOptions.keycloakifyBuildDirPath, jarFilePath)
|
|
|
|
)}":"/opt/keycloak/providers/${pathBasename(jarFilePath)}" \\`,
|
2024-05-14 04:57:38 +02:00
|
|
|
[...(doesImplementAccountTheme ? [accountV1ThemeName] : []), ...buildOptions.themeNames].map(
|
|
|
|
themeName =>
|
|
|
|
` -v "${pathJoin("$(pwd)", themeRelativeDirPath, themeName).replace(/\\/g, "/")}":"/opt/keycloak/themes/${themeName}":rw \\`
|
|
|
|
),
|
2022-04-09 20:17:20 +02:00
|
|
|
` -it quay.io/keycloak/keycloak:${keycloakVersion} \\`,
|
2024-05-14 01:47:08 +02:00
|
|
|
` start-dev`,
|
2022-08-20 11:44:48 +07:00
|
|
|
""
|
2022-04-09 20:17:20 +02:00
|
|
|
].join("\n"),
|
2022-08-20 11:44:48 +07:00
|
|
|
"utf8"
|
2022-04-09 20:17:20 +02:00
|
|
|
),
|
2022-08-20 11:44:48 +07:00
|
|
|
{ "mode": 0o755 }
|
2022-04-09 20:17:20 +02:00
|
|
|
);
|
|
|
|
}
|