Skip to main content

Statefile Arguments

Statefile Arguments are a way to reuse your Statefile by taking advantage of Liquid templating.
Let considere this example, create a new file called my-deployment.yml and add the following content :

ApiVersion: v0.18

# Definition of your arguments
# The type of argument, can be:
# - String
# - Number
# - Boolean
Args:
- Name: name
Kind: String
- Name: domain
Kind: String
- Name: image
Kind: String
- Name: port
Kind: String

Namespace: global

Cargoes:
- Name: ${{ Args.name }}
Containers:
- Name: app
Image: ${{ Args.image }}

Resources:
- Name: ${{ Args.domain }}
Kind: ncproxy.io/rule/v0.15
Data:
Rules:
- Domain: ${{ Args.domain }}
Network: Public
Locations:
- Path: /
Target:
Key: global.${{ Args.name }}.c
Port: ${{ Args.port }}

Now if you apply it with:

nanocl state apply -s my-deployment.yml

You will notice the following error message:

error: the following required arguments were not provided:
--name <name>
--domain <domain>
--image <image>
--port <port>

Usage: nanocl state args -- --name <name> --domain <domain> --image <image> --port <port>

For more information, try '--help'.

The Statefile now require arguments that will be used for rendering

The correct command is now:

state apply -s my-deployment.yml -- --name deploy-example \
--domain deploy-example.com \
--image ghcr.io/next-hat/nanocl-get-started:latest \
--port 9000

That why you can quickly deploy any Http service really easily.
Now you have the basics to create a awsome Statefile !