This repository has been archived on 2026-01-10. You can view files and clone it, but cannot push or open issues or pull requests.
coder-templates/.drone.star
Steve McMaster 0294e0fb39
Some checks failed
continuous-integration/drone/push Build is passing
continuous-integration/drone Build is failing
update
2022-12-11 14:08:08 -05:00

78 lines
2.8 KiB
Plaintext

CODER_URL = "https://github.com/coder/coder/releases/download/v0.11.0/coder_0.11.0_linux_amd64.tar.gz"
TEMPLATES = {
"base": {
"android": {"image": "codercom/enterprise-android:ubuntu"},
"kubernetes": {"image": "codercom/enterprise-base:ubuntu"},
"python38": {"image": "cr.smcm.xyz/coder-images/python-38:latest"},
"python311": {"image": "cr.smcm.xyz/coder-images/python-311:latest"},
},
"alpine": {
"alpine": {"image": "cr.smcm.xyz/coder-images/alpine:latest"},
"alpine-3.17": {"image": "cr.smcm.xyz/coder-images/alpine-3.17:latest"},
"alpine-edge": {"image": "cr.smcm.xyz/coder-images/alpine-edge:latest"},
},
"splunk": {
"appinspect": {"image": "cr.smcm.xyz/coder-images/python-38:latest"},
},
}
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.ninja > {output}".format(
jinja2args = jinja2args,
template = template,
output = output,
)
def main(ctx):
jinja_commands = []
coder_commands = [
"apk add git",
"wget -q -O- {url} | tar -xzf - -C /usr/local/bin ./coder".format(url = CODER_URL),
]
for jinja_template in TEMPLATES:
jinja_template_file = "{name}.tf.jinja".format(name = jinja_template)
for coder_template in TEMPLATES[jinja_template]:
jinja_commands.append("mkdir {name}".format(name = coder_template))
jinja_commands.append(get_jinja_command(
jinja_template_file,
"{name}/main.tf".format(name = coder_template),
TEMPLATES[jinja_template][coder_template],
))
coder_commands.append(
" || ".join([
"coder templates push -d {name} --yes {name}".format(name = coder_template),
"coder templates create -d {name} --yes {name}".format(name = coder_template),
]),
)
return {
"kind": "pipeline",
"name": "default",
"type": "docker",
"steps": [
{
"name": "generate templates",
"image": "roquie/docker-jinja2-cli",
"commands": jinja_commands,
},
{
"name": "push templates",
"image": "alpine:latest",
"environment": {
"CODER_URL": "http://coder.coder.svc.cluster.local",
"CODER_SESSION_TOKEN": {
"from_secret": "CODER_SESSION_TOKEN",
},
"CODER_TEMPLATE_VERSION": ctx.build.commit,
},
"commands": coder_commands,
},
],
}