diff --git a/README.md b/README.md index 36208a15..021bca3d 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,8 @@

+> New with v4.7.4: **M1 Mac** support (for testing locally with a dockerized Keycloak). +

Ultimately this build tool generates a Keycloak theme @@ -474,6 +476,10 @@ and `kcRegisterContext["authorizedMailDomains"]` to validate on. # Changelog highlights +# v4.7.4 + +**M1 Mac** support (for testing locally with a dockerized Keycloak). + # v4.7.2 > WARNING: This is broken. diff --git a/src/bin/KeycloakVersion.ts b/src/bin/KeycloakVersion.ts deleted file mode 100644 index 84494684..00000000 --- a/src/bin/KeycloakVersion.ts +++ /dev/null @@ -1,3 +0,0 @@ -export const keycloakVersions = ["11.0.3", "15.0.2", "16.1.0"] as const; - -export type KeycloakVersion = typeof keycloakVersions[number]; diff --git a/src/bin/build-keycloak-theme/build-keycloak-theme.ts b/src/bin/build-keycloak-theme/build-keycloak-theme.ts index 5bcf6583..8400a594 100644 --- a/src/bin/build-keycloak-theme/build-keycloak-theme.ts +++ b/src/bin/build-keycloak-theme/build-keycloak-theme.ts @@ -2,10 +2,9 @@ import { generateKeycloakThemeResources } from "./generateKeycloakThemeResources import { generateJavaStackFiles } from "./generateJavaStackFiles"; import { join as pathJoin, relative as pathRelative, basename as pathBasename } from "path"; import * as child_process from "child_process"; -import { generateDebugFiles, containerLaunchScriptBasename } from "./generateDebugFiles"; +import { generateStartKeycloakTestingContainer } from "./generateStartKeycloakTestingContainer"; import { URL } from "url"; import * as fs from "fs"; -import { getIsM1 } from "../tools/isM1"; type ParsedPackageJson = { name: string; @@ -89,13 +88,11 @@ export function main() { "cwd": keycloakThemeBuildingDirPath, }); - generateDebugFiles({ + generateStartKeycloakTestingContainer({ keycloakThemeBuildingDirPath, themeName, //We want, however to test in a container running the latest Keycloak version - //Except on M1 where we can't use the default image and we only have - //https://github.com/InseeFrLab/keycloakify/issues/43#issuecomment-975699658 - "keycloakVersion": getIsM1() ? "15.0.2" : "16.1.0", + "keycloakVersion": "17.0.1", }); console.log( @@ -134,10 +131,10 @@ export function main() { "", "To test your theme locally, with hot reloading, you can spin up a Keycloak container image with the theme loaded by running:", "", - `👉 $ ./${pathRelative(reactProjectDirPath, pathJoin(keycloakThemeBuildingDirPath, containerLaunchScriptBasename))} 👈`, + `👉 $ ./${pathRelative(reactProjectDirPath, pathJoin(keycloakThemeBuildingDirPath, generateStartKeycloakTestingContainer.basename))} 👈`, "", "Once your container is up and running: ", - "- Log into the admin console 👉 http://localhost:8080 username: admin, password: admin 👈", + "- Log into the admin console 👉 http://localhost:8080/admin username: admin, password: admin 👈", '- Create a realm named "myrealm"', '- Create a client with id "myclient" and root url: "https://www.keycloak.org/app/"', `- Select Login Theme: ${themeName} (don't forget to save at the bottom of the page)`, diff --git a/src/bin/build-keycloak-theme/generateDebugFiles/generateDebugFiles.ts b/src/bin/build-keycloak-theme/generateDebugFiles/generateDebugFiles.ts deleted file mode 100644 index d31ff5bb..00000000 --- a/src/bin/build-keycloak-theme/generateDebugFiles/generateDebugFiles.ts +++ /dev/null @@ -1,90 +0,0 @@ -import * as fs from "fs"; -import { join as pathJoin, dirname as pathDirname } from "path"; -import type { KeycloakVersion } from "../../KeycloakVersion"; -import { getIsM1 } from "../../tools/isM1"; - -export const containerLaunchScriptBasename = "start_keycloak_testing_container.sh"; - -/** Files for being able to run a hot reload keycloak container */ -export function generateDebugFiles(params: { keycloakVersion: KeycloakVersion; themeName: string; keycloakThemeBuildingDirPath: string }) { - const { themeName, keycloakThemeBuildingDirPath, keycloakVersion } = params; - - fs.writeFileSync( - pathJoin(keycloakThemeBuildingDirPath, "Dockerfile"), - Buffer.from( - [ - `FROM ${ - getIsM1() - ? "eduardosanzb/keycloak@sha256:b1f5bc674eaff6f4e7b37808b9863440310ff93c282fc9bff812377be48bf519" - : `jboss/keycloak:${keycloakVersion}` - }`, - "", - "USER root", - "", - "WORKDIR /", - "", - "ADD configuration /opt/jboss/keycloak/standalone/configuration/", - "", - 'ENTRYPOINT [ "/opt/jboss/tools/docker-entrypoint.sh" ]', - ].join("\n"), - "utf8", - ), - ); - - const dockerImage = `${themeName}/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 \\", - " -e JAVA_OPTS=-Dkeycloak.profile=preview \\", - ` -v ${pathJoin( - keycloakThemeBuildingDirPath, - "src", - "main", - "resources", - "theme", - themeName, - )}:/opt/jboss/keycloak/themes/${themeName}: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, `standalone-ha_${keycloakVersion}.xml`)) - .toString("utf8") - .replace( - new RegExp( - ["2592000", "true", "true"].join("\\s*"), - "g", - ), - ["-1", "false", "false"].join("\n"), - ), - ); -} diff --git a/src/bin/build-keycloak-theme/generateDebugFiles/index.ts b/src/bin/build-keycloak-theme/generateDebugFiles/index.ts deleted file mode 100644 index acfa69a9..00000000 --- a/src/bin/build-keycloak-theme/generateDebugFiles/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "./generateDebugFiles"; diff --git a/src/bin/build-keycloak-theme/generateDebugFiles/standalone-ha_11.0.3.xml b/src/bin/build-keycloak-theme/generateDebugFiles/standalone-ha_11.0.3.xml deleted file mode 100644 index 14d54ade..00000000 --- a/src/bin/build-keycloak-theme/generateDebugFiles/standalone-ha_11.0.3.xml +++ /dev/null @@ -1,666 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE - h2 - - sa - sa - - - - jdbc:h2:${jboss.server.data.dir}/keycloak;AUTO_SERVER=TRUE - h2 - - 100 - - - sa - sa - - - - - org.h2.jdbcx.JdbcDataSource - - - - - - - - - false - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - auth - - - classpath:${jboss.home.dir}/providers/* - - - master - 900 - - 2592000 - true - true - ${env.KEYCLOAK_WELCOME_THEME:keycloak} - ${env.KEYCLOAK_DEFAULT_THEME:keycloak} -

${jboss.home.dir}/themes - - - - - - - - - - - - - jpa - - - basic - - - - - - - - - - - - - - - - - - - default - - - - - - - - ${keycloak.jta.lookup.provider:jboss} - - - - - - - - - - - ${keycloak.x509cert.lookup.provider:default} - - - - ${keycloak.hostname.provider:default} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/bin/build-keycloak-theme/generateDebugFiles/standalone-ha_15.0.2.xml b/src/bin/build-keycloak-theme/generateDebugFiles/standalone-ha_15.0.2.xml deleted file mode 100644 index deb3d5de..00000000 --- a/src/bin/build-keycloak-theme/generateDebugFiles/standalone-ha_15.0.2.xml +++ /dev/null @@ -1,693 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE - h2 - - sa - sa - - - - jdbc:h2:${jboss.server.data.dir}/keycloak;AUTO_SERVER=TRUE - h2 - - sa - sa - - - - - org.h2.jdbcx.JdbcDataSource - - - - - - - - - false - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - auth - - - classpath:${jboss.home.dir}/providers/* - - - master - 900 - - 2592000 - true - true - ${env.KEYCLOAK_WELCOME_THEME:keycloak} - ${env.KEYCLOAK_DEFAULT_THEME:keycloak} - ${jboss.home.dir}/themes - - - - - - - - - - - - - jpa - - - basic - - - - - - - - - - - - - - - - - - - default - - - - - - - - ${keycloak.jta.lookup.provider:jboss} - - - - - - - - - - - ${keycloak.x509cert.lookup.provider:default} - - - - ${keycloak.hostname.provider:default} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/bin/build-keycloak-theme/generateDebugFiles/standalone-ha_16.1.0.xml b/src/bin/build-keycloak-theme/generateDebugFiles/standalone-ha_16.1.0.xml deleted file mode 100644 index 711d319d..00000000 --- a/src/bin/build-keycloak-theme/generateDebugFiles/standalone-ha_16.1.0.xml +++ /dev/null @@ -1,652 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE - h2 - - sa - sa - - - - jdbc:h2:${jboss.server.data.dir}/keycloak;AUTO_SERVER=TRUE - h2 - - sa - sa - - - - - org.h2.jdbcx.JdbcDataSource - - - - - - - - - false - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - auth - - - classpath:${jboss.home.dir}/providers/* - - - master - 900 - - 2592000 - true - true - ${env.KEYCLOAK_WELCOME_THEME:keycloak} - ${env.KEYCLOAK_DEFAULT_THEME:keycloak} - ${jboss.home.dir}/themes - - - - - - - - - - - - - jpa - - - basic - - - - - - - - - - - - - - - - - - - default - - - - - - - - ${keycloak.jta.lookup.provider:jboss} - - - - - - - - - - - ${keycloak.x509cert.lookup.provider:default} - - - - ${keycloak.hostname.provider:default} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/bin/build-keycloak-theme/generateKeycloakThemeResources.ts b/src/bin/build-keycloak-theme/generateKeycloakThemeResources.ts index eff20684..aff511a4 100644 --- a/src/bin/build-keycloak-theme/generateKeycloakThemeResources.ts +++ b/src/bin/build-keycloak-theme/generateKeycloakThemeResources.ts @@ -7,7 +7,6 @@ import { downloadBuiltinKeycloakTheme } from "../download-builtin-keycloak-theme import * as child_process from "child_process"; import { resourcesCommonPath, resourcesPath, subDirOfPublicDirBasename } from "../../lib/getKcContext/kcContextMocks/urlResourcesPath"; import { isInside } from "../tools/isInside"; -import type { KeycloakVersion } from "../KeycloakVersion"; export function generateKeycloakThemeResources(params: { themeName: string; @@ -18,7 +17,7 @@ export function generateKeycloakThemeResources(params: { urlOrigin: undefined | string; extraPagesId: string[]; extraThemeProperties: string[]; - keycloakVersion: KeycloakVersion; + keycloakVersion: string; }) { const { themeName, diff --git a/src/bin/build-keycloak-theme/generateStartKeycloakTestingContainer.ts b/src/bin/build-keycloak-theme/generateStartKeycloakTestingContainer.ts new file mode 100644 index 00000000..f30873e7 --- /dev/null +++ b/src/bin/build-keycloak-theme/generateStartKeycloakTestingContainer.ts @@ -0,0 +1,44 @@ +import * as fs from "fs"; +import { join as pathJoin } from "path"; + +generateStartKeycloakTestingContainer.basename = "start_keycloak_testing_container.sh"; + +const containerName = "keycloak-testing-container"; + +/** Files for being able to run a hot reload keycloak container */ +export function generateStartKeycloakTestingContainer(params: { keycloakVersion: string; themeName: string; keycloakThemeBuildingDirPath: string }) { + const { themeName, keycloakThemeBuildingDirPath, keycloakVersion } = params; + + fs.writeFileSync( + pathJoin(keycloakThemeBuildingDirPath, generateStartKeycloakTestingContainer.basename), + Buffer.from( + [ + "#!/bin/bash", + "", + `docker rm ${containerName} || true`, + "", + `cd ${keycloakThemeBuildingDirPath}`, + "", + "docker run \\", + " -p 8080:8080 \\", + ` --name ${containerName} \\`, + " -e KEYCLOAK_ADMIN=admin \\", + " -e KEYCLOAK_ADMIN_PASSWORD=admin \\", + " -e JAVA_OPTS=-Dkeycloak.profile=preview \\", + ` -v ${pathJoin( + keycloakThemeBuildingDirPath, + "src", + "main", + "resources", + "theme", + themeName, + )}:/opt/keycloak/themes/${themeName}:rw \\`, + ` -it quay.io/keycloak/keycloak:${keycloakVersion} \\`, + ` start-dev`, + "", + ].join("\n"), + "utf8", + ), + { "mode": 0o755 }, + ); +} diff --git a/src/bin/download-builtin-keycloak-theme.ts b/src/bin/download-builtin-keycloak-theme.ts index 58a6421f..a1721363 100644 --- a/src/bin/download-builtin-keycloak-theme.ts +++ b/src/bin/download-builtin-keycloak-theme.ts @@ -3,9 +3,8 @@ import { keycloakThemeBuildingDirPath } from "./build-keycloak-theme"; import { join as pathJoin } from "path"; import { downloadAndUnzip } from "./tools/downloadAndUnzip"; -import type { KeycloakVersion } from "./KeycloakVersion"; -export function downloadBuiltinKeycloakTheme(params: { keycloakVersion: KeycloakVersion; destDirPath: string }) { +export function downloadBuiltinKeycloakTheme(params: { keycloakVersion: string; destDirPath: string }) { const { keycloakVersion, destDirPath } = params; for (const ext of ["", "-community"]) { @@ -19,7 +18,7 @@ export function downloadBuiltinKeycloakTheme(params: { keycloakVersion: Keycloak if (require.main === module) { const keycloakVersion = (() => { - const keycloakVersion = process.argv[2] as KeycloakVersion | undefined; + const keycloakVersion = process.argv[2] as string | undefined; if (keycloakVersion === undefined) { return "11.0.3"; diff --git a/src/bin/generate-i18n-messages.ts b/src/bin/generate-i18n-messages.ts index 342471d7..fe4dcb25 100644 --- a/src/bin/generate-i18n-messages.ts +++ b/src/bin/generate-i18n-messages.ts @@ -5,12 +5,11 @@ import { crawl } from "./tools/crawl"; import { downloadBuiltinKeycloakTheme } from "./download-builtin-keycloak-theme"; import { getProjectRoot } from "./tools/getProjectRoot"; import { rm_rf, rm_r } from "./tools/rm"; -import { keycloakVersions } from "./KeycloakVersion"; //@ts-ignore const propertiesParser = require("properties-parser"); -for (const keycloakVersion of keycloakVersions) { +for (const keycloakVersion of ["11.0.3", "15.0.2", "16.1.0"]) { console.log({ keycloakVersion }); const tmpDirPath = pathJoin(getProjectRoot(), "tmp_xImOef9dOd44"); diff --git a/src/bin/tools/isM1.ts b/src/bin/tools/isM1.ts deleted file mode 100644 index 7233bb19..00000000 --- a/src/bin/tools/isM1.ts +++ /dev/null @@ -1,5 +0,0 @@ -import * as os from "os"; - -export function getIsM1() { - return os.cpus()[0].model.includes("Apple M1"); -}