Commit 1af30363 authored by Ozoux's avatar Ozoux
Browse files

Merge branch 'compile' into 'package'

Compile ressources hashes

See merge request !5
parents f48bc98d c830b9a7
Pipeline #687 passed with stages
in 35 seconds
.DS_Store
.db
liiibre.jar
\ No newline at end of file
liiibre.jar
build
\ No newline at end of file
stages:
- build
- package
build:
stage: build
image:
name: python:3-alpine
script: python compile.py
artifacts:
paths:
- build
package:
stage: package
image:
name: openjdk:15
script: jar -cf liiibre.jar theme META-INF
script: jar -cf liiibre.jar -C build/ .
artifacts:
paths:
- liiibre.jar
{
"themes": [
{
"name": "liiibre",
"types": [
"account",
"admin",
"email",
"login",
"welcome"
]
},
{
"name": "cfamederic",
"types": [
"email",
"login"
]
},
{
"name": "liiibrelite",
"types": [
"email",
"login"
]
},
{
"name": "smart",
"types": [
"email",
"login"
]
},
{
"name": "zwo",
"types": [
"email",
"login"
]
}
]
}
\ No newline at end of file
import os
import json
import shutil
import hashlib
import pathlib
import re
srcDir = "src"
buildDir = "build"
baseTheme = "liiibre"
def geThemes():
themes = []
for name in os.listdir(srcDir):
types = os.listdir(os.path.join(srcDir, name))
themes.append({"name": name, "types": types})
return themes
def clearBuildDir():
if os.path.exists(buildDir):
shutil.rmtree(buildDir)
os.mkdir(buildDir)
def generateManifest(themes):
manifestDir = os.path.join(buildDir, "META-INF")
os.mkdir(manifestDir)
with open(os.path.join(manifestDir, "keycloak-themes.json"), "w+") as manifest:
manifest.write(json.dumps({"themes": themes}))
def copyTheme(theme):
src = os.path.join(srcDir, theme["name"])
dest = os.path.join(buildDir, "theme", theme["name"])
shutil.copytree(src, dest)
def hashResources(theme):
hashedRessources = {}
for themeType in theme["types"]:
hashedRessources[themeType] = []
currentDir = os.path.join(buildDir, "theme", theme["name"], themeType)
for dirpath, _, files in os.walk(currentDir):
for file in files:
path = pathlib.Path(os.path.join(dirpath, file))
if re.search(".*\.(js|css)", path.as_posix()):
fileHash = getFileHash(path)
hashedPath = suffixFile(path, fileHash)
convertedPaths = convertPaths(
currentDir, path.as_posix(), hashedPath.as_posix())
hashedRessources[themeType].append(convertedPaths)
return hashedRessources
def getFileHash(path):
with open(path, "rb") as f:
file_hash = hashlib.md5()
while chunk := f.read(8192):
file_hash.update(chunk)
return file_hash.hexdigest()
def suffixFile(path, suffix):
suffixedPath = path.with_stem(
path.stem + "." + suffix)
os.rename(path, suffixedPath)
return suffixedPath
def convertPaths(dir, *paths):
return [path.replace(os.path.join(dir, "resources/"), "") for path in paths]
def updateProperties(theme, hashDic):
for themeType in theme["types"]:
if theme["name"] == baseTheme:
toReplace = [*hashDic[baseTheme][themeType]]
else:
toReplace = [*hashDic[baseTheme][themeType],
*hashDic[theme["name"]][themeType]]
with open(os.path.join(buildDir, "theme", theme["name"], themeType, "theme.properties"), 'r+') as f:
content = f.read()
for replaceArgs in toReplace:
content = content.replace(*replaceArgs)
f.seek(0)
f.write(content)
if __name__ == "__main__":
clearBuildDir()
themes = geThemes()
generateManifest(themes)
hashDic = {}
for theme in themes:
copyTheme(theme)
hashDic[theme["name"]] = hashResources(theme)
for theme in themes:
updateProperties(theme, hashDic)
......@@ -12,11 +12,11 @@ services:
keycloak:
image: quay.io/keycloak/keycloak
volumes:
- ./theme/cfamederic:/opt/jboss/keycloak/themes/cfamederic
- ./theme/liiibre:/opt/jboss/keycloak/themes/liiibre
- ./theme/liiibrelite:/opt/jboss/keycloak/themes/liiibrelite
- ./theme/smart:/opt/jboss/keycloak/themes/smart
- ./theme/zwo:/opt/jboss/keycloak/themes/zwo
- ./src/cfamederic:/opt/jboss/keycloak/themes/cfamederic
- ./src/liiibre:/opt/jboss/keycloak/themes/liiibre
- ./src/liiibrelite:/opt/jboss/keycloak/themes/liiibrelite
- ./src/smart:/opt/jboss/keycloak/themes/smart
- ./src/zwo:/opt/jboss/keycloak/themes/zwo
- ./disable-theme-cache.cli:/opt/jboss/startup-scripts/disable-theme-cache.cli
environment:
DB_VENDOR: POSTGRES
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment