Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 877b0cf

Browse files
authored
Merge pull request #1 from coder/how-to-manage-coder-templates
How to organize Coder templates
2 parents a576717 + 98d03ab commit 877b0cf

File tree

7 files changed

+294
-0
lines changed

7 files changed

+294
-0
lines changed
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
# Managing Coder templates
2+
3+
Coder templates are the DNA used to create workspaces. They are typically managed by a platform/infrastructure group and allow developers to focus on their projects instead of the underlying infrastructure for their workspaces.
4+
5+
[![Coder templates](./static/templates.png)](./static/templates.png)
6+
7+
## Organizing your templates
8+
9+
There are many ways to organize your templates:
10+
11+
- **Team based templates**: A template for each of your teams (e.g. a template for your _frontend_ team and a template for your _backend_ team.)
12+
13+
- **Project based templates**: A template for each of your projects (e.g. a template for your _cool-project_ and a template for your _awesome-project_.)
14+
15+
- **Image based templates**: A single template that is used for all your projects but with a different image for each project.
16+
17+
![Coder templates](./static/templates-cases.svg)
18+
19+
## What is the difference between a template and an image?
20+
21+
A template is a collection of infrastructure as code (Terraform) used to create workspaces. An image is a collection of software (e.g. Docker) that is used to create a workspace. A template can use one or more images. For example, you can have a template that uses the _golang_ image and the _node_ image, and the user will have the choice of which image to use when creating a workspace. Choices are managed by a terraform variable:
22+
23+
```hcl
24+
variable "image" {
25+
type = string
26+
description = "The image to use for the workspace"
27+
default = "node"
28+
validation {
29+
condition = contains(["node", "java"], var.image)
30+
error_message = "The image must be either ubuntu or node"
31+
}
32+
}
33+
```
34+
35+
## Creating your first template
36+
37+
1. Create a new repository in your GitHub account. This will be the repository that contains your Coder templates.
38+
39+
2. Create a new directory in your repository called `deeplearning`.
40+
41+
3. Create a new file in the `deeplearning` directory called `main.tf`. This is the terraform file that will be used to create your template.
42+
43+
```hcl
44+
terraform {
45+
required_providers {
46+
coder = {
47+
source = "coder/coder"
48+
version = "0.6.14"
49+
}
50+
docker = {
51+
source = "kreuzwerker/docker"
52+
version = "3.0.1"
53+
}
54+
}
55+
}
56+
...
57+
```
58+
59+
![Workspace creation](./static/workspace-creation-1.png)
60+
61+
![Workspace creation](./static/workspace-creation-2.png)
62+
63+
4. Create a rich-parameter variable of the form `data coder_parameter <name>`. This will be used to create a rich parameter in the template. For example:
64+
65+
> See full list of available parameters [here](https://registry.terraform.io/providers/coder/coder/latest/docs/data-sources/parameter)
66+
67+
```hcl
68+
data "coder_parameter" "framework" {
69+
name = "Framework"
70+
icon = "https://raw.githubusercontent.com/matifali/logos/main/memory.svg"
71+
description = "Choose your preffered framework"
72+
type = "string"
73+
mutable = false
74+
default = "no-conda"
75+
option {
76+
name = "PyTorch"
77+
description = "PyTorch"
78+
value = "pytorch"
79+
icon = "https://raw.githubusercontent.com/matifali/logos/main/pytorch.svg"
80+
}
81+
option {
82+
name = "PyTorch Nightly"
83+
description = "PyTorch Nightly"
84+
value = "pytorch-nightly"
85+
icon = "https://raw.githubusercontent.com/matifali/logos/main/pytorch.svg"
86+
}
87+
option {
88+
name = "Tensorflow"
89+
description = "Tensorflow"
90+
value = "tensorflow"
91+
icon = "https://raw.githubusercontent.com/matifali/logos/main/tensorflow.svg"
92+
}
93+
option {
94+
name = "Tensorflow + PyTorch"
95+
description = "Tensorflow + PyTorch"
96+
value = "no-conda"
97+
icon = "https://raw.githubusercontent.com/matifali/logos/main/tf-torch.svg"
98+
}
99+
option {
100+
name = "Tensorflow + PyTorch + conda"
101+
description = "Tensorflow + PyTorch + conda"
102+
value = "conda"
103+
icon = "https://raw.githubusercontent.com/matifali/logos/main/tf-torch-conda.svg"
104+
}
105+
option {
106+
name = "Conda"
107+
description = "Only conda (install whatever you need)"
108+
value = "conda-base"
109+
icon = "https://raw.githubusercontent.com/matifali/logos/main/conda.svg"
110+
}
111+
}
112+
```
113+
114+
5. For this example, we will use the pre-built [DockerDL](https://github.com/matifali/dockerdl) images.
115+
116+
> **Note**: You can use any image you want. You can use a pre-built image or coder can build an image for you from the Dockerfile in _images_ directory. See
117+
118+
```hcl
119+
data "docker_registry_image" "dockerdl" {
120+
name = "matifali/dockerdl:${data.coder_parameter.framework.value}"
121+
}
122+
123+
resource "docker_image" "dockerdl" {
124+
name = data.docker_registry_image.dockerdl.name
125+
pull_triggers = [data.docker_registry_image.dockerdl.sha256_digest]
126+
# Keep alive for other workspaces to use upon deletion
127+
keep_locally = true
128+
}
129+
130+
```
131+
132+
> Full example is available [here](https://github.com/matifali/coder-templates/blob/main/deeplearning/main.tf)
133+
134+
## Next steps
135+
136+
[How to keep your templates up to date](../keep-up-to-date): A guide on how to keep your templates up to date with the latest changes in the upstream repository using GitHub Actions. This will allow you to keep your templates up to date without having to manually update them. [Read more](../keep-up-to-date)
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
style: {
2+
opacity: 1.0
3+
}
4+
5+
team: Team Based Template {
6+
img1: "Frontend" {
7+
style: {
8+
stroke-dash: 10
9+
stroke-width: 1
10+
}
11+
frontend: "" {
12+
shape: image
13+
icon: https://raw.githubusercontent.com/matifali/logos/main/frontend-2.svg
14+
}
15+
}
16+
img2: "Backend" {
17+
style: {
18+
stroke-dash: 10
19+
stroke-width: 1
20+
}
21+
backend: "" {
22+
shape: image
23+
icon: https://raw.githubusercontent.com/matifali/logos/main/backend-2.svg
24+
}
25+
}
26+
}
27+
28+
project: Project Based Template {
29+
img1: "Ticketing App" {
30+
style: {
31+
stroke-dash: 10
32+
stroke-width: 1
33+
}
34+
Java: {
35+
shape: image
36+
icon: https://raw.githubusercontent.com/matifali/logos/main/java.svg
37+
}
38+
Bazel: {
39+
shape: image
40+
icon: https://raw.githubusercontent.com/matifali/logos/main/bazel.svg
41+
}
42+
Spring Boot: {
43+
shape: image
44+
icon: https://raw.githubusercontent.com/matifali/logos/main/springboot-1.svg
45+
}
46+
}
47+
img2: "Billing Dashboard" {
48+
style: {
49+
stroke-dash: 10
50+
stroke-width: 1
51+
}
52+
React: {
53+
shape: image
54+
icon: https://raw.githubusercontent.com/matifali/logos/main/react.svg
55+
}
56+
TypeScript: {
57+
shape: image
58+
icon: https://raw.githubusercontent.com/matifali/logos/main/typescript.svg
59+
}
60+
MongoDB: {
61+
shape: image
62+
icon: https://raw.githubusercontent.com/matifali/logos/main/mongodb-green.svg
63+
}
64+
}
65+
}
66+
67+
framework: Image Based Template {
68+
img1: PyTorch {
69+
style: {
70+
stroke-dash: 10
71+
stroke-width: 1
72+
}
73+
torch: "" {
74+
shape: image
75+
icon: https://raw.githubusercontent.com/matifali/logos/main/pytorch.svg
76+
}
77+
}
78+
img2: PyTorch Nightly {
79+
style: {
80+
stroke-dash: 10
81+
stroke-width: 1
82+
}
83+
torch-n: "" {
84+
shape: image
85+
icon: https://raw.githubusercontent.com/matifali/logos/main/pytorch-black.svg
86+
}
87+
}
88+
img3: TensorFlow {
89+
style: {
90+
stroke-dash: 10
91+
stroke-width: 1
92+
}
93+
tf: "" {
94+
shape: image
95+
icon: https://raw.githubusercontent.com/matifali/logos/main/tensorflow.svg
96+
}
97+
}
98+
img4: PyTorch + TensorFlow {
99+
style: {
100+
stroke-dash: 10
101+
stroke-width: 1
102+
}
103+
torch-tf: "" {
104+
shape: image
105+
icon: https://raw.githubusercontent.com/matifali/logos/main/tf-torch.svg
106+
}
107+
}
108+
img5: Conda {
109+
style: {
110+
stroke-dash: 10
111+
stroke-width: 1
112+
}
113+
conda: "" {
114+
shape: image
115+
icon: https://raw.githubusercontent.com/matifali/logos/main/conda.svg
116+
}
117+
}
118+
img6: Conda + PyTorch +\nTensorFlow {
119+
style: {
120+
stroke-dash: 10
121+
stroke-width: 1
122+
}
123+
torch-tf-conda: "" {
124+
shape: image
125+
icon: https://raw.githubusercontent.com/matifali/logos/main/tf-torch-conda.svg
126+
}
127+
}
128+
}

posts/how-to-manage-coder-templates/static/templates-cases.svg

Lines changed: 30 additions & 0 deletions
Loading
Loading

0 commit comments

Comments
 (0)