CODER_URL = "https://github.com/coder/coder/releases/download/v2.0.0/coder_2.0.0_linux_amd64.tar.gz" TEMPLATES = { "base": {}, "alpine": { "alpine": { "image": "cr.smcm.xyz/coder-images/alpine", "alpine_releases": "3.17,3.18,edge" }, }, "android": { "android-2023-06": { "image": "cr.smcm.xyz/coder-images/android-2023.06", "coder_user_uid": "1001", "coder_user_gid": "1002", } }, "python": { "python": { "image": "cr.smcm.xyz/coder-images/python", "python_versions": "3.8,3.11" } }, "rust": { "rust": { "image": "cr.smcm.xyz/coder-images/rust", "rust_versions": "1.71" } }, "splunk": { "splunk": { "image": "cr.smcm.xyz/coder-images/splunk", "splunk_versions": "8.2,9.0,9.1" }, }, "jupyter": { "jupyter-scipy-notebook": {"image": "cr.smcm.xyz/coder-images/jupyter-scipy-notebook"}, }, } 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