This commit is contained in:
parent
52075482cf
commit
39ece19997
55
.drone.star
55
.drone.star
@ -46,36 +46,45 @@ TEMPLATES = {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
def get_jinja_command(template, output, context):
|
|
||||||
jinja2args = " ".join(["-D '{key}={value}'".format(key = key, value = value) for (key, value) in context.items()])
|
|
||||||
|
|
||||||
return "/usr/local/bin/jinja2 {jinja2args} {template}.tf.jinja > {output}".format(
|
|
||||||
jinja2args = jinja2args,
|
|
||||||
template = template,
|
|
||||||
output = output,
|
|
||||||
)
|
|
||||||
|
|
||||||
def main(ctx):
|
def main(ctx):
|
||||||
pipeline = {
|
pipeline = {
|
||||||
"kind": "pipeline",
|
"kind": "pipeline",
|
||||||
"name": "default",
|
"name": "default",
|
||||||
"type": "docker",
|
"type": "docker",
|
||||||
"steps": [],
|
"environment": {},
|
||||||
|
"steps": [
|
||||||
|
{
|
||||||
|
"name": "generate Dockerfiles",
|
||||||
|
"image": "alpine:edge",
|
||||||
|
"commands": [
|
||||||
|
"echo http://dl-cdn.alpinelinux.org/alpine/edge/testing >> /etc/apk/repositories",
|
||||||
|
"apk add jinja2-cli",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"trigger": {
|
||||||
|
"branch": ["main"],
|
||||||
|
"event": ["push", "custom", "cron"],
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
jinja_commands = []
|
|
||||||
|
|
||||||
for jinja_template in TEMPLATES:
|
for jinja_template in TEMPLATES:
|
||||||
for coder_template in TEMPLATES[jinja_template]:
|
for (coder_template, context) in TEMPLATES[jinja_template].items():
|
||||||
jinja_commands.append("mkdir {name}".format(name = coder_template))
|
pipeline["steps"][0]["commands"].append("mkdir {name}".format(name = coder_template))
|
||||||
jinja_commands.append(get_jinja_command(
|
|
||||||
jinja_template,
|
jinja2args = " ".join([
|
||||||
"{name}/main.tf".format(name = coder_template),
|
"-D '{key}={value}'".format(key = key, value = value) for (key, value) in context.items()
|
||||||
TEMPLATES[jinja_template][coder_template],
|
])
|
||||||
))
|
pipeline["steps"][0]["commands"].append(
|
||||||
|
"/usr/bin/jinja2 {jinja2args} {jinja_template}.tf.jinja < /dev/null > {output}".format(
|
||||||
|
jinja2args = jinja2args,
|
||||||
|
jinja_template = jinja_template,
|
||||||
|
output = "{coder_template}/main.tf".format(coder_template = coder_template),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
pipeline["steps"].append({
|
pipeline["steps"].append({
|
||||||
"name": "push {name}".format(name = coder_template),
|
"name": "push {coder_template}".format(coder_template = coder_template),
|
||||||
"image": "alpine:latest",
|
"image": "alpine:latest",
|
||||||
"environment": {
|
"environment": {
|
||||||
"CODER_URL": "http://coder.coder.svc.cluster.local",
|
"CODER_URL": "http://coder.coder.svc.cluster.local",
|
||||||
@ -98,10 +107,4 @@ def main(ctx):
|
|||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
|
||||||
pipeline["steps"].insert(0, {
|
|
||||||
"name": "generate templates",
|
|
||||||
"image": "roquie/docker-jinja2-cli",
|
|
||||||
"commands": jinja_commands,
|
|
||||||
})
|
|
||||||
|
|
||||||
return pipeline
|
return pipeline
|
||||||
Reference in New Issue
Block a user