Skip to content

Commit 24bd81e

Browse files
build: split build of metalk8s-ui app & image
Build NodeJS stuff before generating the metalk8s-ui image. It will allow to embed the documentation and the NodeJS code when generating the metalk8s-ui container image. Refs: scality#1595
1 parent b2446ff commit 24bd81e

File tree

7 files changed

+111
-17
lines changed

7 files changed

+111
-17
lines changed

.pylint-dict

+1
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,4 @@ GPG
6262
JsonReporter
6363
LZ77
6464
Mio
65+
UI

buildchain/buildchain/builder.py

+21-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from buildchain import config
1010
from buildchain import constants
11+
from buildchain import coreutils
1112
from buildchain import types
1213
from buildchain import utils
1314
from buildchain import versions
@@ -81,9 +82,28 @@ def _builder_image(
8182
]
8283
)
8384

85+
UI_BUILDER : LocalImage = _builder_image(
86+
name='ui',
87+
dockerfile=constants.ROOT/'ui'/'Dockerfile',
88+
build_args={'NODE_IMAGE_VERSION': versions.NODEJS_IMAGE_VERSION},
89+
file_dep=(
90+
list(coreutils.ls_files_rec(constants.ROOT/'ui'/'public')) +
91+
list(coreutils.ls_files_rec(constants.ROOT/'ui'/'src')) +
92+
[
93+
constants.ROOT/'ui'/'package.json',
94+
constants.ROOT/'ui'/'package-lock.json',
95+
constants.ROOT/'ui'/'entrypoint.sh',
96+
]
97+
)
98+
)
99+
84100

85101
_BUILDERS : Tuple[LocalImage, ...] = (
86-
RPM_BUILDER, DEB_BUILDER, DOC_BUILDER, GO_BUILDER
102+
RPM_BUILDER,
103+
DEB_BUILDER,
104+
DOC_BUILDER,
105+
GO_BUILDER,
106+
UI_BUILDER,
87107
)
88108

89109

buildchain/buildchain/constants.py

+2
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@
5757
)
5858
# Path to the storage-operator source directory.
5959
STORAGE_OPERATOR_ROOT : Path = ROOT/'storage-operator'
60+
# Path to the UI build root directory.
61+
UI_BUILD_ROOT : Path = config.BUILD_ROOT/'ui'
6062

6163
# Docker entrypoints.
6264
DEBIAN_ENTRYPOINT : Path = ROOT/'packages/debian/entrypoint.sh'

buildchain/buildchain/ui.py

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# coding: utf-8
2+
3+
"""Tasks to build the MetalK8s UI.
4+
5+
Overview:
6+
7+
┌───────┐ ┌──────────┐
8+
│ mkdir │───>│ build UI │
9+
└───────┘ └──────────┘
10+
"""
11+
12+
13+
from pathlib import Path
14+
15+
from buildchain import builder
16+
from buildchain import constants
17+
from buildchain import coreutils
18+
from buildchain import docker_command
19+
from buildchain import targets
20+
from buildchain import types
21+
from buildchain import utils
22+
23+
24+
def task_ui() -> types.TaskDict:
25+
"""Build the MetalK8s UI."""
26+
return {
27+
'actions': None,
28+
'task_dep': [
29+
'_ui_mkdir_build_root',
30+
'_ui_build',
31+
],
32+
}
33+
34+
35+
def task__ui_mkdir_build_root() -> types.TaskDict:
36+
"""Create the MetalK8s UI build root directory."""
37+
return targets.Mkdir(
38+
directory=constants.UI_BUILD_ROOT,
39+
user_mask=0o000, # node user needs to be able to write in this folder
40+
task_dep=['_build_root'],
41+
).task
42+
43+
44+
def task__ui_build() -> types.TaskDict:
45+
"""Build the MetalK8s UI NodeJS."""
46+
def clean() -> None:
47+
coreutils.rm_rf(constants.UI_BUILD_ROOT)
48+
49+
build_ui = docker_command.DockerRun(
50+
builder=builder.UI_BUILDER,
51+
command=['/entrypoint.sh'],
52+
run_config=docker_command.default_run_config(
53+
constants.ROOT/'ui'/'entrypoint.sh'
54+
),
55+
mounts=[
56+
utils.bind_mount(
57+
target=Path('/home/node/build'),
58+
source=constants.UI_BUILD_ROOT,
59+
),
60+
],
61+
)
62+
63+
return {
64+
'actions': [build_ui],
65+
'title': utils.title_with_target1('NPM BUILD'),
66+
'task_dep': [
67+
'_build_builder:{}'.format(builder.UI_BUILDER.name),
68+
],
69+
'file_dep': list(utils.git_ls('ui')),
70+
'targets': [constants.UI_BUILD_ROOT/'index.html'],
71+
'clean': [clean],
72+
}
73+
74+
75+
__all__ = utils.export_only_tasks(__name__)

buildchain/dodo.py

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from buildchain.lint import *
2323
from buildchain.packaging import *
2424
from buildchain.salt_tree import *
25+
from buildchain.ui import *
2526
from buildchain.vagrant import *
2627

2728

ui/Dockerfile

+4-16
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,15 @@
1-
ARG NGINX_IMAGE_VERSION=1.15.8
21
ARG NODE_IMAGE_VERSION=10.16.0
32

4-
FROM node:${NODE_IMAGE_VERSION} AS build-step
3+
FROM node:${NODE_IMAGE_VERSION}
54

65
USER node
76
WORKDIR /home/node
87

98
# These are ordered by 'likeliness of change'
109
COPY config-overrides.js .babelrc /home/node/
1110
COPY public /home/node/public
12-
13-
COPY package*.json /home/node/
14-
RUN npm ci
15-
11+
COPY package.json package-lock.json /home/node/
1612
COPY src /home/node/src
17-
RUN npm run build
18-
19-
FROM nginx:${NGINX_IMAGE_VERSION}
20-
21-
COPY conf/nginx.conf /etc/nginx/conf.d/default.conf
22-
23-
WORKDIR /usr/share/nginx/html/
24-
RUN rm -rf ./*
25-
COPY --from=build-step /home/node/build ./
13+
COPY entrypoint.sh /entrypoint.sh
2614

27-
CMD ["nginx", "-g", "daemon off;"]
15+
ENTRYPOINT ["/entrypoint.sh"]

ui/entrypoint.sh

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
set -eu
4+
5+
npm ci
6+
7+
npm run build

0 commit comments

Comments
 (0)