CODER_URL = "https://github.com/coder/coder/releases/download/v2.0.0/coder_2.0.0_linux_amd64.tar.gz" TEMPLATES = { "base": {}, "_lang": { "golang": { "lang": "golang", "versions": "1.21" }, "python": { "lang": "python", "versions": "3.8,3.11" }, "rust": { "lang": "rust", "versions": "1.71" } }, "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", } }, "jupyter": { "jupyter-scipy-notebook": {"image": "cr.smcm.xyz/coder-images/jupyter-scipy-notebook"}, }, "splunk": { "splunk": { "image": "cr.smcm.xyz/coder-images/splunk", "splunk_versions": "8.2,9.0,9.1" }, }, "ubuntu": { "ubuntu": { "image": "cr.smcm.xyz/coder-images/ubuntu", "alpine_releases": "20.04,22.04,23.04,23.10" }, }, } def main(ctx): pipeline = { "kind": "pipeline", "name": "default", "type": "docker", "environment": {}, "steps": [ { "name": "generate templates", "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"], }, } for jinja_template in TEMPLATES: for (coder_template, context) in TEMPLATES[jinja_template].items(): pipeline["steps"][0]["commands"].append("mkdir {name}".format(name = coder_template)) jinja2args = " ".join([ "-D '{key}={value}'".format(key = key, value = value) for (key, value) in context.items() ]) 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({ "name": "push {coder_template}".format(coder_template = 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", ], }) return pipeline