Create Stackfiles
What are Stackfiles?**
Stackfiles are bundles, a set of predefined Templates and Plugins from a Stack, and you can use them in the stk-legacy create app
) command.
When you use a Stackfile, you can apply a set of Plugins with a single STK CLI
command when creating an app
.
When to use Stackfiles?**
- In scenarios where a Template/Plugin bundle is often used in a Stack.
- Stackfiles are useful to avoid using multiple commands to create a project. You can create a bundle of predefined Templates and Plugins and place them within the context of a project.
How to create Stackfiles?
Follow the steps below:
Step 1. Create a folder named 'stackfiles' in your Stack repository
Step 2. Execute the command
Inside the Stackfiles folder, run the command below and choose a name for your Stackfile:
stk-legacy create stackfile <stackfile-name>
Step 3. Edit and define the <name-stackfile>.yaml
file
The yaml
file name is the one you defined in the previous step.
Browse for the folder and open the file. You will see something like the structure below:
type: app
description: Just an example
template: <stack-name>/<template-name>
inputs:
some_input: value
plugins:
- plugin: <stack-name>/<plugin-name>
inputs:
some_input: value
some_list:
- item1
- item2
You need to edit and define the items below:
- The Template you want to use.
- The Plugins you want to apply.
The sequence of applying Plugins is defined in the file.
Mandatory attributes:
Attribute | Description |
---|---|
type | Indicates that the Stackfile will be used in a stk-legacy create app . |
Optional attributes:
Attribute | Description |
---|---|
description | Stackfile description will be on the stk-legacy list stackfile command. |
template | Template to be used to create the app in the format name-stack/name-template . |
inputs | Objects with the input values that will be passed to the Template. It is not mandatory and if some input value defined in the Template is not informed, the question is asked to the user. |
plugins | List of objects that indicate the Plugins that will be applied. The Plugin must be informed in the format stack-name/plugin-name . |
See an example of a Stackfile structure already filled out:
type: app
description: Python Rest API using flask
template: stack-python/python-app-template
inputs:
source_folder: src
plugins:
- plugin: stack-python/flask-api-plugin
inputs:
enable_cors: true
- plugin: stack-python/zappa-deploy-plugin
If you update the Template and/or Plugin used in the Stackfile, it is not necessary to delete and create the Stackfile again. The updates are loaded automatically, as long as you keep the Template/Plugins'name the same name as before.
Step 4. Add the file in Git
Follow the steps below:
Add the
yaml
file from the Stackfile into Git and push the Stack;After this, your Stackfile will be published.
See an example below of a repository's layout with Stackfiles:
/stack-python
stack.yaml
/python-app-template/
template.yaml
/templates/
...
/flask-api-plugin/
plugin.yaml
/templates/
...
/zappa-deploy-plugin/
plugin.yaml
/templates/
...
/stackfiles/
default.yaml
flask-serverless-api.yaml
How to use Stackfiles?
You can use Stackfiles with the command:
For Stackfiles included in the Stack itself use the syntax:
stk-legacy create app name-app --stackfile <name-stack>/<name-stackfile>
- When you use the Stackfile, Template, and Plugin already defined, the app will be applied with the same settings.
The Stackfile name is optional and can be omitted. In this case, the default Stackfile is used, represented by the default.yaml
file.
Examples
Apply a default Stackfile example:
stk-legacy create app name-app --stackfile <name-stack>
You can use a customized Stackfile, that is, one that is not in the Stackfiles folder of a Stack. Enter the path to the yaml
file from the specification.
Apply a customized Stackfile example:
stk-legacy create app name-app --stackfile /home/user/custom-stackfile.yaml
Was this page helpful?