Applying Manifests
Anemos can apply the generated manifests to a Kubernetes cluster. There are two ways to do this:
using the anemos apply <package>
command to apply a package directly, or using the anemos build --apply <js-file>
command to build and apply all manifests.
Using the anemos apply <package>
command
anemos apply <package>
command takes a package argument and applies the manifests defined in that package.
The package can be in a few different formats, such as:
- A local file path to a JavaScript file such as
package.js
or.path/to/package.js
- A Remote URL to a JavaScript file such as
https://anemos.sh/examples/hello-world.js
- A package name from the NPM registry
- A local file path to an NPM package
- A Remote URL to an NPM package
When you run the anemos apply <package>
command, Anemos will call the add
function of the package,
compute the diff between the current state of the cluster and the manifests generated by the package,
print the changes, and apply them if you confirm.
You can pass -y
flag to skip the confirmation step and apply the changes directly. It is also possible
to pass options to the package with -f
flag. Value of this flag is a path to a JSON or YAML file.
The contents of this file will be parsed and passed to the package as an options
object.
If the value of the -f
flag is -
, Anemos will read the options from the standard input.
Here is an example of how to apply a package:
anemos apply --yes https://anemos.sh/examples/hello-world.js -f - <<EOF
replicaCount: 3
EOF
[09:44:11.880] INFO: Starting to build documents
[09:44:11.881] INFO: Applying actions for step: '2' - Sanitize
[09:44:11.881] INFO: Applying actions for step: '5' - Generate resources
[09:44:11.883] INFO: Applying actions for step: '100' - Apply
Summary of changes:
OP NAMESPACE RESOURCE
A default deployments/anemos-hello-world
A default services/anemos-hello-world
[09:44:11.948] INFO: Successfully applied Kubernetes manifests
Using the anemos build --apply <js-file>
command
The anemos build --apply <js-file>
command builds the given JavaScript file and applies the
generated manifests to the cluster. Each document group will be applied separately,
and the command will wait for the user to confirm before applying each group.
This command is useful when you want to build a complex script that uses multiple packages to generate manifests for many applications, and you want to apply them all at once.
You can pass -y
flag to skip the confirmation step and apply the changes directly.
Let's import two packages and apply them using the anemos build --apply <js-file>
command:
const anemos = require('@ohayocorp/anemos');
const helloWorld = require("https://anemos.sh/examples/hello-world.js");
const simplePackage = require("https://anemos.sh/examples/simple-package.js");
const builder = new anemos.Builder("1.31", anemos.KubernetesDistribution.Minikube, anemos.EnvironmentType.Development);
helloWorld.add(builder);
simplePackage.add(builder);
builder.build();
Run the following command to apply the manifests:
anemos build --apply index.js
Output will be similar to the one below:
[11:38:20.582] INFO: Starting to build documents
[11:38:20.582] INFO: Applying actions for step: '2' - Sanitize
[11:38:20.583] INFO: Applying actions for step: '5' - Generate resources
[11:38:20.583] INFO: Applying actions for step: '99,-1' - Delete outputs
[11:38:20.584] INFO: Applying actions for step: '99' - Output
[11:38:20.584] INFO: Writing documents to /home/ohayocorp/anemos-project/output/manifests
[11:38:20.587] INFO: Applying actions for step: '100' - Apply
[11:38:20.588] INFO: Applying document group: anemos-hello-world
Summary of changes:
OP NAMESPACE RESOURCE
A default deployments/anemos-hello-world
A default services/anemos-hello-world
Apply these changes? [y/N]: y
[11:38:23.053] INFO: Applying document group: simple-package
Summary of changes:
OP NAMESPACE RESOURCE
A default pods/simple-package
A default services/simple-package
Apply these changes? [y/N]: y
[11:38:24.249] INFO: Successfully applied Kubernetes manifests