|
| 1 | +# apphub-configurator |
| 2 | + |
| 3 | +[](https://pypi.org/project/apphub-configurator) |
| 4 | +[](https://pypi.org/project/apphub-configurator) |
| 5 | + |
| 6 | +----- |
| 7 | + |
| 8 | +## Table of Contents |
| 9 | + |
| 10 | +- [Installation](#installation) |
| 11 | +- [Overview](#overview) |
| 12 | +- [Examples](#Examples) |
| 13 | +- [License](#license) |
| 14 | + |
| 15 | +## Installation |
| 16 | + |
| 17 | +```console |
| 18 | +pip install apphub-configurator |
| 19 | +``` |
| 20 | +## Overview |
| 21 | +This package contains a notebook and the python modules to support the generation of ApplicationHub configurations for a minikube cluster. For more information about ApplicationHub please check this [link](https://github.com/EOEPCA/application-hub-context) |
| 22 | + |
| 23 | +## Examples: |
| 24 | + |
| 25 | +Find more examples if you need from this [link](https://github.com/EOEPCA/application-hub-context/tree/ESAEOEPCA-236/config-generator/apphub-configurator/examples) |
| 26 | + |
| 27 | +### Step 1: Setup the environment |
| 28 | + |
| 29 | +To begin using the `apphub-configurator` package, import the required functions from the package: |
| 30 | + |
| 31 | +```python |
| 32 | +from apphub_configurator.helpers import load_config_map, load_manifests, create_init_container, load_init_script |
| 33 | +``` |
| 34 | + |
| 35 | +### Step 2: Example of configuration generation |
| 36 | + |
| 37 | +Here is an overview of the functions and how to use them to generate configurations: |
| 38 | + |
| 39 | +1. **Loading Kubernetes Manifests:** |
| 40 | + Use `load_manifests()` to load the required Kubernetes manifests. This function takes the following parameters: |
| 41 | + - `name`: The name of the manifest. |
| 42 | + - `key`: The key used to reference the manifest. |
| 43 | + - `file_path`: The file path to the manifest YAML file. |
| 44 | + |
| 45 | + Example usage: |
| 46 | + ```python |
| 47 | + load_manifests(name="example-name", key="example-key", file_path="path/to/manifest.yaml") |
| 48 | + ``` |
| 49 | + |
| 50 | +2. **Creating Volumes:** |
| 51 | + You can create a Kubernetes `Volume` by specifying the following: |
| 52 | + - `name`: The name of the volume. |
| 53 | + - `size`: The size of the volume (e.g., `"50Gi"`). |
| 54 | + - `claim_name`: The claim name for the volume. |
| 55 | + - `mount_path`: The path where the volume should be mounted. |
| 56 | + |
| 57 | + Example usage: |
| 58 | + ```python |
| 59 | + Volume( |
| 60 | + name="workspace-volume", |
| 61 | + size="50Gi", |
| 62 | + claim_name="workspace-claim", |
| 63 | + mount_path="/workspace" |
| 64 | + ) |
| 65 | + ``` |
| 66 | + |
| 67 | +3. **Loading ConfigMaps:** |
| 68 | + Use `load_config_map()` to load configuration maps. It requires the following parameters: |
| 69 | + - `name`: The name of the config map. |
| 70 | + - `key`: The key for the configuration map. |
| 71 | + - `file_name`: The file path to the configuration file. |
| 72 | + - `mount_path`: The path where the config map should be mounted. |
| 73 | + |
| 74 | + Example usage: |
| 75 | + ```python |
| 76 | + load_config_map(name="bash-login", key="bash-login", file_name="path/to/bash-login", mount_path="/etc/profile.d/bash-login.sh") |
| 77 | + ``` |
| 78 | + |
| 79 | +4. **Creating Init Containers:** |
| 80 | + The `create_init_container()` function allows you to define init containers with the following parameters: |
| 81 | + - `image`: The container image to use. |
| 82 | + - `volume`: The volume associated with the container. |
| 83 | + - `mount_path`: The path where the volume will be mounted inside the container. |
| 84 | + |
| 85 | + Example usage: |
| 86 | + ```python |
| 87 | + create_init_container(image="example-image", volume=your_volume, mount_path="/calrissian") |
| 88 | + ``` |
| 89 | + |
| 90 | +5. **Creating Profiles:** |
| 91 | + You can create a `Profile` by defining its parameters such as `id`, `groups`, `definition`, and others. The profile can include volumes, config maps, init containers, and manifests. |
| 92 | + |
| 93 | + Example usage: |
| 94 | + ```python |
| 95 | + Profile( |
| 96 | + id="profile_1", |
| 97 | + definition=ProfileDefinition( |
| 98 | + display_name="Example Profile", |
| 99 | + description="This profile configures an example service", |
| 100 | + default=True |
| 101 | + ), |
| 102 | + volumes=[your_volume], |
| 103 | + config_maps=[your_config_map], |
| 104 | + init_containers=[your_init_container], |
| 105 | + manifests=[your_manifest] |
| 106 | + ) |
| 107 | + ``` |
| 108 | + |
| 109 | +6. **Generating the Configuration:** |
| 110 | + After defining your profiles and configurations, you can use the `Config` class to generate the final configuration. This configuration can be saved to a YAML file. |
| 111 | + |
| 112 | + Example usage: |
| 113 | + ```python |
| 114 | + config = Config(profiles=[your_profile]) |
| 115 | + with open("generated_config.yml", "w") as file: |
| 116 | + yaml.dump(config.dict(), file) |
| 117 | + ``` |
| 118 | + |
| 119 | + |
| 120 | +## License |
| 121 | + |
| 122 | +`apphub-configurator` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license. |
0 commit comments