Servers infra generation #
One of the go-asyncapi core features is generating the
infrastructure-as-code (IaC) definitions from an AsyncAPI document.
In other words, infra command generates server setup files from a given AsyncAPI document.
The generated files are useful for setting up the development environment quickly or as the starting point for the deployment configurations. They contain the AsyncAPI entities, that are relevant to the infrastructure setup: servers, channels, etc.
Right now, only docker-compose technology is supported,
The result of generation can also be customized in templates. See templating guide for more details.
Usage #
All command options are duplicated in configuration file. So, you can set them there as well.
To generate the servers definitions from an AsyncAPI document, run the following command:
go-asyncapi infra <asyncapi-document> [options...]
The result will be put in the docker-compose.yaml file in the current working directory.
Server variables #
Server may have the Server Variables defined in AsyncAPI. In this case, the definition for this server won’t be generated
unless you specify the variable values in the go-asyncapi configuration file, because go-asyncapi can’t guess the variable values.
Server with missing Server Variables value
# This file is generated by go-asyncapi tool
# NOTE: Server production is not rendered due to missing server variables in the go-asyncapi configuration
# NOTE: Server production is not rendered due to missing server variables in the go-asyncapi configuration
# NOTE: Server production is not rendered due to missing server variables in the go-asyncapi configuration
# NOTE: Server production is not rendered due to missing server variables in the go-asyncapi configuration
# NOTE: Server production is not rendered due to missing server variables in the go-asyncapi configuration
To make it work, set values of Server Variables in go-asyncapi configuration file and run the infra command again.
For example, here we set a single variable variableName of the production server to 1883:
infra:
serverOpts:
- serverName: production
variables:
variableName: 1883