115 lines
4.3 KiB
Plaintext
115 lines
4.3 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-scipy-notebook": {"image": "cr.smcm.xyz/coder-images/jupyter-scipy-notebook:latest"},
|
|
},
|
|
}
|
|
|
|
def get_build_step(ctx, dockerfile, coder_template, path):
|
|
# {
|
|
# "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,
|
|
# },
|
|
|
|
build_step =
|
|
|
|
for command in BUILD_COMMANDS:
|
|
build_step["commands"].append(command.format(
|
|
image = image,
|
|
DRONE_COMMIT_SHA = ctx.build.commit,
|
|
dockerfile = dockerfile,
|
|
path = path,
|
|
registry_base = registry_base,
|
|
))
|
|
|
|
return build_step
|
|
|
|
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 = []
|
|
# 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],
|
|
))
|
|
|
|
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),
|
|
" || ".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,
|
|
}) |