|
| 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__) |
0 commit comments