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 = {
|
2023-09-04 00:25:36 +02:00
|
|
|
keycloakifyBuildDirPath: 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 */
|
2023-09-04 00:25:36 +02:00
|
|
|
export function generateStartKeycloakTestingContainer(params: { keycloakVersion: string; buildOptions: BuildOptionsLike }) {
|
|
|
|
const { keycloakVersion, buildOptions } = params;
|
|
|
|
|
|
|
|
const themeRelativeDirPath = pathJoin("src", "main", "resources", "theme");
|
|
|
|
const themeDirPath = pathJoin(buildOptions.keycloakifyBuildDirPath, themeRelativeDirPath);
|
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-09-04 00:25:36 +02:00
|
|
|
...fs
|
|
|
|
.readdirSync(themeDirPath)
|
|
|
|
.filter(name => fs.lstatSync(pathJoin(themeDirPath, name)).isDirectory())
|
|
|
|
.map(
|
|
|
|
themeName =>
|
|
|
|
` -v "${pathJoin(".", themeRelativeDirPath, 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
|
|
|
);
|
|
|
|
}
|