-
Notifications
You must be signed in to change notification settings - Fork 9
Deployment
Deployment insertion is the step of create()
that renders the top-level configuration template, and then sends the configuration and other templates to the deployment manager.
The deployment is described in the top-level configuration YAML file, which should be called [level-name].yaml
. For more information on how to create deployment configurations, refer to the Google documentation. The Thunder CTF framework also has the added functionality of rendering the top-level configuration as a Jinja template when given a dictionary of arguments to pass to the template.
from core.framework import levels
from core.framework.cloudhelpers import deployments
LEVEL_PATH = 'thunder/a1openbucket'
RESOURCE_PREFIX = 'a1'
def create():
...
# ---------Deployment Insertion---------
# Insert deployment
config_template_args = {'nonce': nonce}
template_files = ['core/framework/templates/bucket_acl.jinja']
deployments.insert(LEVEL_PATH,
template_files=template_files,
config_template_args=config_template_args)
# --------------------------------------
...
imports:
- path: bucket_acl.jinja
resources:
- name: a1-bucket
type: bucket_acl.jinja
properties:
predefined_acl: publicRead
nonce: {{ nonce }}
Most of the details of creating a deployment are abstracted away by the Thunder CTF framework, so all the level creator has to do is to run deployments.insert()
, which takes 4 arguments:
Relative path of the level from the levels/
directory, as described in the Level Overview page of this guide.
Dictionary of arguments that will be used when rendering the top-level configuration as a Jinja template. If not supplied, the top-level configuration will not be rendered and instead will be used directly.
In thunder/a1openbucket
, the config_template_args dictionary includes the randomized nonce, meaning it will the variable nonce
be accessible in the jinja template:
# ---------Deployment Insertion---------
# Insert deployment
config_template_args = {'nonce': nonce}
resources:
- name: a1-bucket
type: bucket_acl.jinja
properties:
predefined_acl: publicRead
nonce: {{ nonce }}
If the level needs to store information for the destroy()
function to work, the create()
function can pass a dictionary argument with the keyword labels
to deployments.insert()
. The label 'level'
is reserved for use by the Thunder CTF framework.
When you wish to retrieve the labels in the destroy()
function, run deployments.get_labels()
.
template_files is a list of paths of the Deployment Manager templates that the top-level deployment uses. The template paths should start with core/
and should either be in the provided framework templates in core/framework/templates
directory or in the level's directory.
For more information on using Deployment Manager templates, refer to the Google documentation.
When importing templates, the full relative path should be given when calling deployments.insert()
, but only the filename should be given in the top-level configuration:
template_files = ['core/framework/templates/bucket_acl.jinja']
deployments.insert(LEVEL_PATH,
template_files=template_files,
config_template_args=config_template_args)
imports:
- path: bucket_acl.jinja
Schema files validate the usage of templates, and can also be helpful to users of the template by describing the properties the template requires. Schema files will automatically be used with templates if they are provided in a sibling directory to the templates called schema
, and the schema files must also be titled [template-name].schema
.