Skip to content

Commit

Permalink
Merge branch 'improvement/use-solutions-navbar-in-metalk8s-ui' into q…
Browse files Browse the repository at this point in the history
…/2.9
  • Loading branch information
bert-e committed Mar 10, 2021
2 parents 8e6fdd3 + 73e4a52 commit 7da43ba
Show file tree
Hide file tree
Showing 66 changed files with 2,142 additions and 1,156 deletions.
13 changes: 13 additions & 0 deletions buildchain/buildchain/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,25 @@ def _builder_image(name: str, dockerfile: Path, **kwargs: Any) -> LocalImage:
],
)

SHELL_UI_BUILDER: LocalImage = _builder_image(
name="shell-ui",
dockerfile=constants.ROOT / "ui" / "Dockerfile",
build_context=constants.ROOT / "shell-ui",
build_args={"NODE_IMAGE_VERSION": versions.NODEJS_IMAGE_VERSION},
file_dep=[
constants.ROOT / "shell-ui" / "package.json",
constants.ROOT / "shell-ui" / "package-lock.json",
constants.ROOT / "ui" / "entrypoint.sh",
],
)


_BUILDERS: Tuple[LocalImage, ...] = (
(
DOC_BUILDER,
GO_BUILDER,
UI_BUILDER,
SHELL_UI_BUILDER,
)
+ tuple(RPM_BUILDER.values())
+ tuple(DEB_BUILDER.values())
Expand Down
2 changes: 2 additions & 0 deletions buildchain/buildchain/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
STORAGE_OPERATOR_ROOT: Path = ROOT / "storage-operator"
# Path to the UI build root directory.
UI_BUILD_ROOT: Path = config.BUILD_ROOT / "ui"
# Path to the shell-ui build root directory.
SHELL_UI_BUILD_ROOT: Path = config.BUILD_ROOT / "shell-ui"
# Root for the source Debian package
SRC_DEB_ROOT: Path = ROOT / "packages" / "debian"

Expand Down
3 changes: 2 additions & 1 deletion buildchain/buildchain/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,10 @@ def _operator_image(name: str, **kwargs: Any) -> targets.OperatorImage:
file_dep=(
list(coreutils.ls_files_rec(constants.UI_BUILD_ROOT))
+ list(coreutils.ls_files_rec(constants.DOCS_BUILD_ROOT))
+ list(coreutils.ls_files_rec(constants.SHELL_UI_BUILD_ROOT))
+ [config.BUILD_ROOT / "metalk8s-ui-nginx.conf"]
),
task_dep=["ui", "doc"],
task_dep=["ui", "shell_ui", "doc"],
),
_local_image(
name="metalk8s-utils",
Expand Down
3 changes: 2 additions & 1 deletion buildchain/buildchain/salt_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def _get_parts(self) -> Iterator[str]:
SCALITY_LOGO: Path = constants.UI_ASSETS / "login/logo.png"
SCALITY_FAVICON: Path = constants.UI_ASSETS / "login/favicon.png"
LOGIN_STYLE: Path = constants.UI_ASSETS / "login/styles.css"
UI_THEME_OPTIONS: Path = constants.UI_BRANDING / "theme.json"
UI_THEME_OPTIONS: Path = constants.ROOT / "shell-ui" / "theme.json"

# List of salt files to install.
SALT_FILES: Tuple[Union[Path, targets.AtomicTarget], ...] = (
Expand Down Expand Up @@ -377,6 +377,7 @@ def _get_parts(self) -> Iterator[str]:
"ThemeConfig": textwrap.indent(
UI_THEME_OPTIONS.read_text(encoding="utf-8"), 12 * " "
),
"ShellUIVersion": versions.SHELL_UI_VERSION,
},
file_dep=[UI_THEME_OPTIONS],
),
Expand Down
95 changes: 95 additions & 0 deletions buildchain/buildchain/shell_ui.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# coding: utf-8

"""Tasks to build the Shell UI.
Overview:
┌──────────┐ ┌───────┐ ┌───────┐
│ shell-UI │───>│ mkdir │───>│ build │
└──────────┘ └───────┘ └───────┘
"""


from pathlib import Path

from buildchain import builder
from buildchain import config
from buildchain import constants
from buildchain import coreutils
from buildchain import docker_command
from buildchain import targets
from buildchain import types
from buildchain import utils


def task_shell_ui() -> types.TaskDict:
"""Build the Shell UI."""
return {
"actions": None,
"task_dep": [
"_shell_ui_mkdir_build_root",
"_shell_ui_build",
],
}


def task__shell_ui_mkdir_build_root() -> types.TaskDict:
"""Create the Shell UI build root directory."""
task = targets.Mkdir(
directory=constants.SHELL_UI_BUILD_ROOT,
task_dep=["_build_root"],
).task
# `node` user in the container needs to be able to write in this folder.
task["actions"].append(lambda: constants.SHELL_UI_BUILD_ROOT.chmod(0o777))
return task


def task__shell_ui_build() -> types.TaskDict:
"""Build the Shell UI code."""

def clean() -> None:
run_shell_ui_builder("clean")()

return {
"actions": [run_shell_ui_builder("build")],
"title": utils.title_with_target1("NPM BUILD"),
"task_dep": [
"_build_builder:{}".format(builder.SHELL_UI_BUILDER.name),
"_shell_ui_mkdir_build_root",
],
"file_dep": list(utils.git_ls("shell-ui")),
"targets": [constants.SHELL_UI_BUILD_ROOT / "index.html"],
"clean": [clean],
}


def run_shell_ui_builder(cmd: str) -> docker_command.DockerRun:
"""Return a DockerRun instance of the UI builder for the given command."""
return docker_command.DockerRun(
builder=builder.SHELL_UI_BUILDER,
command=["/entrypoint.sh", cmd],
run_config=docker_command.default_run_config(
constants.ROOT / "ui" / "entrypoint.sh"
),
mounts=[
utils.bind_mount(
target=Path("/home/node/build"),
source=constants.SHELL_UI_BUILD_ROOT,
),
]
+ [
utils.bind_ro_mount(
target=Path("/home/node") / path,
source=constants.ROOT / "shell-ui" / path,
)
for path in [
"src",
"webpack.config.prd.js",
"babel.config.js",
".flowconfig",
]
],
)


__all__ = utils.export_only_tasks(__name__)
14 changes: 13 additions & 1 deletion buildchain/buildchain/versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
for use in tests and documentation as well.
"""
import operator
import json

from collections import namedtuple
from pathlib import Path
Expand Down Expand Up @@ -39,7 +40,8 @@ def load_version_information() -> None:
globals()[var] = value.strip()


VERSION_FILE = (Path(__file__) / "../../../VERSION").resolve()
REPO_ROOT = (Path(__file__) / "../../../").resolve()
VERSION_FILE = REPO_ROOT / "VERSION"

# Metalk8s version.
# (Those declarations are not mandatory, but they help pylint and mypy).
Expand All @@ -53,6 +55,11 @@ def load_version_information() -> None:
SHORT_VERSION: str = "{}.{}".format(VERSION_MAJOR, VERSION_MINOR)
VERSION: str = "{}.{}{}".format(SHORT_VERSION, VERSION_PATCH, VERSION_SUFFIX)

# Get shell ui version from package.json
shell_ui_package_contents = (REPO_ROOT / "shell-ui/package.json").read_text(
encoding="utf-8"
)
SHELL_UI_VERSION: str = json.loads(shell_ui_package_contents)["version"]

# }}}
# Container images {{{
Expand Down Expand Up @@ -203,6 +210,11 @@ def _version_prefix(version: str, prefix: str = "v") -> str:
version=VERSION,
digest=None,
),
Image(
name="shell-ui",
version=VERSION,
digest=None,
),
Image(
name="metalk8s-utils",
version=VERSION,
Expand Down
1 change: 1 addition & 0 deletions buildchain/dodo.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from buildchain.packaging import *
from buildchain.salt_tree import *
from buildchain.ui import *
from buildchain.shell_ui import *
from buildchain.vagrant import *


Expand Down
49 changes: 48 additions & 1 deletion eve/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1176,6 +1176,9 @@ stages:
application:
context: 'ui'
dockerfile: eve/workers/pod-integration-tests/ui/app.Dockerfile
shell-ui:
context: 'shell-ui'
dockerfile: eve/workers/pod-integration-tests/ui/shell-ui.Dockerfile
steps:
- Git: *git_pull
- ShellCommand:
Expand All @@ -1189,7 +1192,7 @@ stages:
name: Install Cypress and its dependencies
workdir: build/ui
command: |
PKGS="cypress cypress-cucumber-preprocessor cypress-wait-until"
PKGS="cypress cypress-cucumber-preprocessor cypress-wait-until @testing-library/cypress"
for pkg in $PKGS; do
npm install --no-save --no-package-lock $pkg@$(node -p \
-e "require('./package-lock.json').dependencies['$pkg'].version" \
Expand Down Expand Up @@ -1251,6 +1254,7 @@ stages:
name: Trigger all unit tests simultaneously
stage_names:
- unit_tests_ui
- unit_tests_shell_ui
- unit_tests_crd_client_generator
- unit_tests_storage_operator
- unit_tests_salt
Expand Down Expand Up @@ -1311,6 +1315,49 @@ stages:
STEP_NAME: unit_tests_ui
- Upload: *upload_final_status_artifact

unit_tests_shell_ui:
_metalk8s_internal_info:
junit_info: &_unit-test_shell_ui_junit_info
TEST_SUITE: unit test
TEST_NAME: shell-ui
worker:
type: kube_pod
path: eve/workers/pod-unit-tests/pod.yaml
images:
docker-unit-tests:
context: 'shell-ui'
dockerfile: eve/workers/pod-unit-tests/ui/Dockerfile
vars:
name: "metalk8s-unit-tests-shell-ui-worker"
steps:
- Git: *git_pull
- ShellCommand:
<<: *add_final_status_artifact_failed
env:
<<: *_env_final_status_artifact_failed
<<: *_unit-test_shell_ui_junit_info
STEP_NAME: unit_tests_shell_ui
- ShellCommand: *yum_clean_all
- ShellCommand:
name: Install UI dependencies
workdir: build/shell-ui
command: >
npm ci --prefer-offline --no-audit
haltOnFailure: true
- ShellCommand:
name: Run all Shell UI unit tests
workdir: build/shell-ui
command: >
npm run test --no-update-notifier
haltOnFailure: true
- ShellCommand:
<<: *add_final_status_artifact_success
env:
<<: *_env_final_status_artifact_success
<<: *_unit-test_shell_ui_junit_info
STEP_NAME: unit_tests_sehll_ui
- Upload: *upload_final_status_artifact

unit_tests_crd_client_generator:
_metalk8s_internal_info:
junit_info: &_unit-test_crd_client_generator_junit_info
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ NODE_PACKAGES=(
cypress@5.6.0
cypress-cucumber-preprocessor@4.0.0
cypress-wait-until@1.7.1
@testing-library/cypress@7.0.3
)

curl -sL https://rpm.nodesource.com/setup_10.x | sudo bash -
Expand Down
44 changes: 42 additions & 2 deletions eve/workers/pod-integration-tests/ui/pod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,36 @@ kind: Pod
metadata:
name: "metalk8s-integration-tests-ui"
spec:
initContainers:
- name: shell-ui
image: {{ images['shell-ui'] }}
resources:
requests:
cpu: 250m
memory: 200Mi
limits:
cpu: 350m
memory: 300Mi
command: ["/bin/sh"]
args:
- -c
- |
cat > /usr/share/nginx/html/shell/config.json <<EOF
{
"docUrl": "/docs",
"oidc": {
"providerUrl": "/oidc",
"redirectUrl": "/",
"clientId": "metalk8s-ui",
"responseType": "id_token",
"scopes": "openid profile email groups offline_access audience:server:client_id:oidc-auth-client"
}
}
EOF
cp -r /usr/share/nginx/html/ /tmp/shell-ui-files
volumeMounts:
- name: shell-ui-files
mountPath: /tmp/shell-ui-files
containers:
- name: worker
image: {{ images['worker'] }}
Expand All @@ -18,6 +48,7 @@ spec:
volumeMounts:
- name: worker-workspace
mountPath: /home/eve/workspace

- name: application
image: {{ images['application'] }}
resources:
Expand All @@ -27,12 +58,21 @@ spec:
limits:
cpu: 350m
memory: 300Mi
command: ["nginx"]
args: ["-g", "daemon off;"]
command: ["/bin/sh"]
args:
- -c
- |
cp -r /tmp/shell-ui-files/html/shell/ /usr/share/nginx/html/
nginx -g 'daemon off;' 2>&1
ports:
- containerPort: 80
name: http
protocol: TCP
volumeMounts:
- name: shell-ui-files
mountPath: /tmp/shell-ui-files
volumes:
- name: worker-workspace
emptyDir: {}
- name: shell-ui-files
emptyDir: {}

0 comments on commit 7da43ba

Please sign in to comment.