-
Notifications
You must be signed in to change notification settings - Fork 53
Creator: The `config` section
If you are here it's assumed that you've at least read HOWTO Create a Generator. If not it's best you do so first otherwise what we have to tell you won't make a lot of sense.
When reading through the HOWTos we can see it seems pretty easy to make things work. You create a directory, some files
that get copied and an info.yaml
file that might look like this:
type: generator
config:
base: runtime-vertx
While others might have more or different properties. So, what's that about? What can a Generator actually do?
Well, that's a good question, so let's start what Generators can do by default:
Any non-custom Generator performs, or tries to perform, the following list of actions (in order):
⚠️ Any properties mentioned from now on are assumed to be children of theconfig
section. Also if the property mentioned does not exist the action does not take place unless stated otherwise.
- First applies the Generator mentioned in the
base
property - Checks if this Generator was already applied before, if so it skips to item 20
- Adds the Resources for the application image mentioned in the
image
property - Applies the
runtime-base-support
Generator if this is a Runtime Generator - Copies the entire contents of the
files
folder to the target project - Copies the entire contents of the
files-VERSION
folder to the target project, where VERSION would be the same as theruntime.version
value passed to the Generator in the properties - Applies the
maven-setup
Generator if apom.xml
file was found in the root offiles
folder - Merges the file
merge/pom.xml
with thepom.xml
file in the root of the target project - Merges any
merge-VERSION/pom.xml
files with thepom.xml
file in the root of the target project, where VERSION would be the same as theruntime.version
value passed to the Generator in the properties - Merges the file
merge/package.json
with thepackage.json
file in the root of the target project - Merges the file
merge-VERSION/package.json
with thepackage.json
file in the root of the target project, where VERSION would be the same as theruntime.version
value passed to the Generator in the properties - Sets the default Readiness Probe for the K8s/OpenShift service (by default a GET
/health
). This can be overridden by using thereadinessProbe
property. This can either be a string containing a different URL to check, or an object containing the Resource Definitions to insert directly. See Define Readiness Probes. - The same as the previous point, but for the Liveness Probe. See Define Liveness Probes.
- Sets the service's CPU limit using the value from
cpuLimit
- Sets the service's memory limit using the value from
memoryLimit
- Reads any Yaml files from the
resources
folder and adds their contents to the project resources (it actually first runs acases
transformation on their contents) - Reads any Yaml files from the
resources-VERSION
folder, where VERSION would be the same as theruntime.version
value passed to the Generator in the properties, and adds their contents to the project resources (it actually first runs acases
transformation on their contents) - Takes any actions defined in the
moreActions
section and executes them - Checks the property
transformFiles
for a list of file patterns. Any files in the target project that match any of those patterns will be transformed using thecases
transformer. - Adds the values defined in
props.env
to the service's build and runtime environments (resp. in the BuildConfig and DeploymentConfig) - Takes any actions defined in the
actionsAlways
section and executes them - Adds the values defined in
extra
to the properties returned by the Generator to its caller
As you can see Generators can do a whole bunch of things by default!
It might seem somewhat overwhelming but those actions really just boil down to three things:
- Copy and change files
- Add resources (as in K8s Resource Definitions)
- Delegate some of the first two points to another Generator
Not so complicated now, right?
Well not so fast. We're not done yet. There's still one other property to mention.
If the property actions
exists none of the default actions will be executed and the above list will become much shorter:
- Takes any actions defined in the
actions
section and executes them - Takes any actions defined in the
actionsAlways
section and executes them - Adds the values defined in
extra
to the properties returned by the Generator to its caller
All the actions mentioned above can also be executed independently and can often be configured in several way to behave differently.
An action in its simplest form looks like this:
actions:
- action: "NAME"
Any other properties that are found in the same object will be passed on the the action while it executes.
actions:
- action: "NAME"
any: dummy
other: dummy
props: dummy
So what actions are available?
Name | Function | Arguments |
---|---|---|
apply | Apply another Generator | generator - The name of the Generator to apply |
copy | Copy files |
from - Source directory (in Generator, default files )to - Target directory (in project) |
move | Move a file |
from - Source file (in project) to - Target file (in project) |
transform | Transforms files |
files - File pattern (in project) ... - See The transform Action for more information |
mergePoms | Merges two Maven POM files |
from - Source POM (in Generator, default merge/pom.xml )to - Target POM (in project, default pom.xml ) |
mergePackageJson | Merges two Nodejs Package files |
from - Source JSON (in Generator, default merge/package.json )to - Target JSON (in project, default package.xml ) |
route | Creates a Route for the Service |
name - The name for the Route (default routeName from the properties) |
- Create a Custom Generator - What if all these predefined actions aren't enough for you? What if what you need is a totally custom Generator?
-
The transform Action - To learn all there is to know about the
transform
action