2022-04-09 20:17:20 +02:00
|
|
|
import * as fs from "fs";
|
|
|
|
import { join as pathJoin } from "path";
|
2022-08-16 14:41:06 +07:00
|
|
|
import { assert } from "tsafe/assert";
|
2023-09-03 07:14:57 +02:00
|
|
|
import { Reflect } from "tsafe/Reflect";
|
2022-08-16 14:41:06 +07:00
|
|
|
import type { BuildOptions } from "./BuildOptions";
|
|
|
|
|
|
|
|
export type BuildOptionsLike = {
|
|
|
|
themeName: string;
|
2023-06-08 23:09:14 +02:00
|
|
|
extraThemeNames: string[];
|
2022-08-16 14:41:06 +07:00
|
|
|
};
|
|
|
|
|
2023-09-03 07:14:57 +02:00
|
|
|
{
|
|
|
|
const buildOptions = Reflect<BuildOptions>();
|
|
|
|
|
|
|
|
assert<typeof 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";
|
|
|
|
|
|
|
|
/** Files for being able to run a hot reload keycloak container */
|
2022-08-16 14:41:06 +07:00
|
|
|
export function generateStartKeycloakTestingContainer(params: {
|
|
|
|
keycloakVersion: string;
|
|
|
|
keycloakThemeBuildingDirPath: string;
|
|
|
|
buildOptions: BuildOptionsLike;
|
|
|
|
}) {
|
|
|
|
const {
|
|
|
|
keycloakThemeBuildingDirPath,
|
|
|
|
keycloakVersion,
|
2023-06-08 23:09:14 +02:00
|
|
|
buildOptions: { themeName, extraThemeNames }
|
2022-08-16 14:41:06 +07:00
|
|
|
} = params;
|
2022-04-09 20:17:20 +02:00
|
|
|
|
|
|
|
fs.writeFileSync(
|
|
|
|
pathJoin(keycloakThemeBuildingDirPath, generateStartKeycloakTestingContainer.basename),
|
|
|
|
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-03-15 10:07:01 +01:00
|
|
|
`cd "${keycloakThemeBuildingDirPath.replace(/\\/g, "/")}"`,
|
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-06-08 23:09:14 +02:00
|
|
|
...[themeName, ...extraThemeNames].map(
|
|
|
|
themeName =>
|
|
|
|
` -v "${pathJoin(keycloakThemeBuildingDirPath, "src", "main", "resources", "theme", themeName).replace(
|
|
|
|
/\\/g,
|
|
|
|
"/"
|
|
|
|
)}":"/opt/keycloak/themes/${themeName}":rw \\`
|
|
|
|
),
|
2022-04-09 20:17:20 +02:00
|
|
|
` -it quay.io/keycloak/keycloak:${keycloakVersion} \\`,
|
2023-08-02 08:56:47 +02:00
|
|
|
` start-dev --features=declarative-user-profile`,
|
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
|
|
|
);
|
|
|
|
}
|