-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(docker-admin-ui): add support for plugins installation (#319)
- Loading branch information
Showing
6 changed files
with
106 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
ignored: | ||
- DL3018 # Pin versions in apk add | ||
- DL3013 # Pin versions in pip | ||
- DL3003 # Use WORKDIR to switch to a directory | ||
- DL3016 # Pin versions in npm | ||
- SC2086 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,18 @@ | ||
GLUU_VERSION=1.0.0 | ||
GLUU_VERSION?=1.0.0 | ||
IMAGE_NAME=gluufederation/admin-ui | ||
UNSTABLE_VERSION=dev | ||
UNSTABLE_VERSION?=dev | ||
|
||
build-ui: | ||
.PHONY: test clean all build-dev trivy-scan grype-scan | ||
.DEFAULT_GOAL := build-dev | ||
|
||
build-dev: | ||
@echo "[I] Building Docker image ${IMAGE_NAME}:${GLUU_VERSION}_${UNSTABLE_VERSION}" | ||
@docker build --rm --force-rm -t ${IMAGE_NAME}:${GLUU_VERSION}_${UNSTABLE_VERSION} . | ||
|
||
trivy-scan: | ||
@echo "[I] Scanning Docker image ${IMAGE_NAME}:${GLUU_VERSION}_${UNSTABLE_VERSION} using trivy" | ||
@trivy -d image ${IMAGE_NAME}:${GLUU_VERSION}_${UNSTABLE_VERSION} | ||
|
||
grype-scan: | ||
@echo "[I] Scanning Docker image ${IMAGE_NAME}:${GLUU_VERSION}_${UNSTABLE_VERSION} using grype" | ||
@grype -v ${IMAGE_NAME}:${GLUU_VERSION}_${UNSTABLE_VERSION} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import logging.config | ||
import json | ||
import os | ||
import shutil | ||
import sys | ||
|
||
from jans.pycloudlib.utils import exec_cmd | ||
|
||
from settings import LOGGING_CONFIG | ||
|
||
logging.config.dictConfig(LOGGING_CONFIG) | ||
logger = logging.getLogger("entrypoint") | ||
|
||
ADMIN_UI_DIR = "/opt/flex/admin-ui" | ||
|
||
|
||
def _discover_plugins(): | ||
os.chdir(ADMIN_UI_DIR) | ||
|
||
user_plugins = [ | ||
plugin.strip() | ||
for plugin in os.environ.get("GLUU_ADMIN_UI_PLUGINS", "").strip().split(",") | ||
if plugin.strip() | ||
] | ||
|
||
for plugin in set(user_plugins): | ||
src = f"/app/plugins/{plugin}.zip" | ||
|
||
if not os.path.isfile(src): | ||
continue | ||
|
||
logger.info(f"Adding plugin {plugin} from {src}") | ||
cmd = f"npm run plugin:add {src}" | ||
out, err, code = exec_cmd(cmd) | ||
|
||
if code != 0: | ||
sys.exit(err.decode()) | ||
logger.info(out.decode()) | ||
|
||
with open(os.path.join(ADMIN_UI_DIR, "plugins.config.json")) as f: | ||
loaded_plugins = [plug["key"] for plug in json.loads(f.read())] | ||
return loaded_plugins | ||
|
||
|
||
def _build_src() -> None: | ||
logger.info("Building admin-ui app ...") | ||
public_dir = "/var/lib/nginx/html" | ||
|
||
os.chdir(ADMIN_UI_DIR) | ||
|
||
cmd = "npm run build:prod" | ||
out, err, code = exec_cmd(cmd) | ||
|
||
if code != 0: | ||
sys.exit(err.decode()) | ||
|
||
logger.info(out.decode()) | ||
shutil.copytree( | ||
os.path.join(ADMIN_UI_DIR, "dist"), | ||
public_dir, | ||
dirs_exist_ok=True, | ||
) | ||
logger.info("Finished building admin-ui app") | ||
|
||
|
||
def main() -> None: | ||
loaded_plugins = _discover_plugins() | ||
_build_src() | ||
logger.info(f"Loaded plugins: {', '.join(loaded_plugins)}") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters