Skip to content

Commit 811872f

Browse files
committed
Add scratch as starter template
1 parent e659957 commit 811872f

File tree

5 files changed

+89
-3
lines changed

5 files changed

+89
-3
lines changed

docs/cli/templates_init.md

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/examples.gen.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,5 +156,14 @@
156156
"container"
157157
],
158158
"markdown": "\n# Remote Development on Nomad\n\nProvision Nomad Jobs as [Coder workspaces](https://coder.com/docs/v2/latest/workspaces) with this example template. This example shows how to use Nomad service tasks to be used as a development environment using docker and host csi volumes.\n\n\u003c!-- TODO: Add screenshot --\u003e\n\n\u003e **Note**\n\u003e This template is designed to be a starting point! Edit the Terraform to extend the template to support your use case.\n\n## Prerequisites\n\n- [Nomad](https://www.nomadproject.io/downloads)\n- [Docker](https://docs.docker.com/get-docker/)\n\n## Setup\n\n### 1. Start the CSI Host Volume Plugin\n\nThe CSI Host Volume plugin is used to mount host volumes into Nomad tasks. This is useful for development environments where you want to mount persistent volumes into your container workspace.\n\n1. Login to the Nomad server using SSH.\n\n2. Append the following stanza to your Nomad server configuration file and restart the nomad service.\n\n ```hcl\n plugin \"docker\" {\n config {\n allow_privileged = true\n }\n }\n ```\n\n ```shell\n sudo systemctl restart nomad\n ```\n\n3. Create a file `hostpath.nomad` with following content:\n\n ```hcl\n job \"hostpath-csi-plugin\" {\n datacenters = [\"dc1\"]\n type = \"system\"\n\n group \"csi\" {\n task \"plugin\" {\n driver = \"docker\"\n\n config {\n image = \"registry.k8s.io/sig-storage/hostpathplugin:v1.10.0\"\n\n args = [\n \"--drivername=csi-hostpath\",\n \"--v=5\",\n \"--endpoint=${CSI_ENDPOINT}\",\n \"--nodeid=node-${NOMAD_ALLOC_INDEX}\",\n ]\n\n privileged = true\n }\n\n csi_plugin {\n id = \"hostpath\"\n type = \"monolith\"\n mount_dir = \"/csi\"\n }\n\n resources {\n cpu = 256\n memory = 128\n }\n }\n }\n }\n ```\n\n4. Run the job:\n\n ```shell\n nomad job run hostpath.nomad\n ```\n\n### 2. Setup the Nomad Template\n\n1. Create the template by running the following command:\n\n ```shell\n coder template init nomad-docker\n cd nomad-docker\n coder template push\n ```\n\n2. Set up Nomad server address and optional authentication:\n\n3. Create a new workspace and start developing.\n"
159+
},
160+
{
161+
"id": "scratch",
162+
"url": "",
163+
"name": "Scratch",
164+
"description": "A minimal Scaffolding for a Coder Template",
165+
"icon": "/emojis/1f4e6.png",
166+
"tags": [],
167+
"markdown": "\n# A minimal Scaffolding for a Coder Template\n\nUse this starter template as a basis to create your own unique template from scratch.\n"
159168
}
160169
]

examples/examples.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ var (
3535
//go:embed templates/gcp-windows
3636
//go:embed templates/kubernetes
3737
//go:embed templates/nomad-docker
38+
//go:embed templates/scratch
3839
files embed.FS
3940

4041
exampleBasePath = "https://github.com/coder/coder/tree/main/examples/templates/"

examples/templates/scratch/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
display_name: Scratch
3+
description: A minimal Scaffolding for a Coder Template
4+
icon: ../../../site/static/emojis/1f4e6.png
5+
maintainer_github: coder
6+
verified: true
7+
tags: []
8+
---
9+
10+
# A minimal Scaffolding for a Coder Template
11+
12+
Use this starter template as a basis to create your own unique template from scratch.

examples/templates/scratch/main.tf

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
terraform {
2+
required_providers {
3+
coder = {
4+
source = "coder/coder"
5+
}
6+
}
7+
}
8+
9+
data "coder_provisioner" "me" {}
10+
11+
data "coder_workspace" "me" {}
12+
13+
resource "coder_agent" "main" {
14+
arch = data.coder_provisioner.me.arch
15+
os = data.coder_provisioner.me.os
16+
startup_script_timeout = 180
17+
startup_script = <<-EOT
18+
set -e
19+
# Run programs at workspace startup
20+
EOT
21+
22+
metadata {
23+
display_name = "CPU Usage"
24+
key = "0_cpu_usage"
25+
script = "coder stat cpu"
26+
interval = 10
27+
timeout = 1
28+
}
29+
30+
metadata {
31+
display_name = "RAM Usage"
32+
key = "1_ram_usage"
33+
script = "coder stat mem"
34+
interval = 10
35+
timeout = 1
36+
}
37+
}
38+
39+
# Use this to set environment variables in your workspace
40+
# details: https://registry.terraform.io/providers/coder/coder/latest/docs/resources/env
41+
resource "coder_env" "my_env" {
42+
agent_id = coder_agent.main.id
43+
name = "FOO"
44+
value = "bar"
45+
}
46+
47+
# Adds code-server
48+
# See all available modules at https://regsitry.coder.com
49+
module "code-server" {
50+
source = "registry.coder.com/modules/code-server/coder"
51+
version = "1.0.2"
52+
agent_id = coder_agent.main.id
53+
}
54+
55+
# Runs a script at workspace start/stop or on a cron schedule
56+
# details: https://registry.terraform.io/providers/coder/coder/latest/docs/resources/script
57+
resource "coder_script" "my_script" {
58+
agent_id = coder_agent.main.id
59+
display_name = "My Script"
60+
run_on_start = true
61+
script = <<-EOF
62+
echo "Hello ${data.coder_workspace.me.owner}!"
63+
EOF
64+
}

0 commit comments

Comments
 (0)