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
2023-02-25 01:13:52 -05:00

89 lines
3.6 KiB
Plaintext

CODER_URL = "https://github.com/coder/coder/releases/download/v0.17.4/coder_0.17.4_linux_amd64.tar.gz"
TEMPLATES = {
"base": {
"android": {"image": "codercom/enterprise-android:ubuntu"},
"kubernetes": {"image": "codercom/enterprise-base:ubuntu"},
"python-38": {"image": "cr.smcm.xyz/coder-images/python-38:latest"},
"python-311": {"image": "cr.smcm.xyz/coder-images/python-311:latest"},
},
"alpine": {
"alpine": {"image": "cr.smcm.xyz/coder-images/alpine:latest"},
"alpine-315": {"image": "cr.smcm.xyz/coder-images/alpine-3.15:latest"},
"alpine-317": {"image": "cr.smcm.xyz/coder-images/alpine-3.17:latest"},
"alpine-edge": {"image": "cr.smcm.xyz/coder-images/alpine-edge:latest"},
},
"splunk": {
"splunk": {"image": "cr.smcm.xyz/coder-images/splunk:latest"},
"splunk-82": {"image": "cr.smcm.xyz/coder-images/splunk-8.2:latest"},
"splunk-90": {"image": "cr.smcm.xyz/coder-images/splunk-9.0:latest"},
},
# "proxychains": {
# "splunk-python": {"image": "cr.smcm.xyz/coder-images/python-38:latest"},
# },
"jupyter": {
"jupyter-base-notebook": {"image": "cr.smcm.xyz/coder-images/jupyter-base-notebook:latest"},
"jupyter-minimal-notebook": {"image": "cr.smcm.xyz/coder-images/jupyter-minimal-notebook:latest"},
"jupyter-scipy-notebook": {"image": "cr.smcm.xyz/coder-images/jupyter-scipy-notebook: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.jinja > {output}".format(
jinja2args = jinja2args,
template = template,
output = output,
)
def main(ctx):
pipeline = {
"kind": "pipeline",
"name": "default",
"type": "docker",
"steps": [],
}
jinja_commands = []
for jinja_template in TEMPLATES:
for coder_template in TEMPLATES[jinja_template]:
jinja_commands.append("mkdir {name}".format(name = coder_template))
jinja_commands.append(get_jinja_command(
jinja_template,
"{name}/main.tf".format(name = coder_template),
TEMPLATES[jinja_template][coder_template],
))
pipeline["steps"].append({
"name": "push {name}".format(name = coder_template),
"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": [
"apk add git",
"wget -q -O- {url} | tar -xzf - -C /usr/local/bin ./coder".format(url = CODER_URL),
"sleep $(( $RANDOM % 15 ))",
" || ".join([
"coder templates push -d {name} --yes {name}".format(name = coder_template),
"coder templates create -d {name} --yes {name}".format(name = coder_template),
]),
],
"depends_on": [
"generate templates",
],
})
pipeline["steps"].insert(0, {
"name": "generate templates",
"image": "roquie/docker-jinja2-cli",
"commands": jinja_commands,
})
return pipeline