76 lines
2.7 KiB
Plaintext
76 lines
2.7 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.jinja > {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:
|
|
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],
|
|
))
|
|
|
|
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,
|
|
},
|
|
],
|
|
}
|