Skip to content

Commit b07d403

Browse files
committed
updated with suggestions
1 parent a61c3d0 commit b07d403

File tree

4 files changed

+239
-79
lines changed

4 files changed

+239
-79
lines changed

posts/how-to-manage-coder-templates/index.md

Lines changed: 81 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ There are many ways to organize your templates:
1414

1515
- **Image based templates**: A single template that is used for all your projects but with a different image for each project.
1616

17-
![Coder templates](./static/templates-cases.png)
17+
![Coder templates](./static/templates-cases.svg)
1818

1919
## What is the difference between a template and an image?
2020

@@ -24,111 +24,113 @@ A template is a collection of infrastructure as code (Terraform) used to create
2424
variable "image" {
2525
type = string
2626
description = "The image to use for the workspace"
27-
default = "ubuntu"
27+
default = "node"
2828
validation {
29-
condition = contains(["ubuntu", "node"], var.image)
29+
condition = contains(["node", "java"], var.image)
3030
error_message = "The image must be either ubuntu or node"
3131
}
3232
}
33+
```
3334

3435
## Creating your first template
3536

36-
![Workspace creation](./static/workspace-creation-1.png)
37-
![Workspace creation](./static/workspace-creation-2.png)
38-
3937
1. Create a new repository in your GitHub account. This will be the repository that contains your Coder templates.
4038

4139
2. Create a new directory in your repository called `deeplearning`.
4240

4341
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.
4442

45-
```hcl
46-
terraform {
47-
required_providers {
48-
coder = {
49-
source = "coder/coder"
50-
version = "0.6.14"
51-
}
52-
docker = {
53-
source = "kreuzwerker/docker"
54-
version = "3.0.1"
55-
}
56-
}
57-
}
58-
...
59-
```
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)
6062

6163
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:
6264

6365
> See full list of available parameters [here](https://registry.terraform.io/providers/coder/coder/latest/docs/data-sources/parameter)
6466
65-
```hcl
66-
data "coder_parameter" "framework" {
67-
name = "Framework"
68-
icon = "https://raw.githubusercontent.com/matifali/logos/main/memory.svg"
69-
description = "Choose your preffered framework"
70-
type = "string"
71-
mutable = false
72-
default = "no-conda"
73-
option {
74-
name = "PyTorch"
75-
description = "PyTorch"
76-
value = "pytorch"
77-
icon = "https://raw.githubusercontent.com/matifali/logos/main/pytorch.svg"
78-
}
79-
option {
80-
name = "PyTorch Nightly"
81-
description = "PyTorch Nightly"
82-
value = "pytorch-nightly"
83-
icon = "https://raw.githubusercontent.com/matifali/logos/main/pytorch.svg"
84-
}
85-
option {
86-
name = "Tensorflow"
87-
description = "Tensorflow"
88-
value = "tensorflow"
89-
icon = "https://raw.githubusercontent.com/matifali/logos/main/tensorflow.svg"
90-
}
91-
option {
92-
name = "Tensorflow + PyTorch"
93-
description = "Tensorflow + PyTorch"
94-
value = "no-conda"
95-
icon = "https://raw.githubusercontent.com/matifali/logos/main/tf-torch.svg"
96-
}
97-
option {
98-
name = "Tensorflow + PyTorch + conda"
99-
description = "Tensorflow + PyTorch + conda"
100-
value = "conda"
101-
icon = "https://raw.githubusercontent.com/matifali/logos/main/tf-torch-conda.svg"
102-
}
103-
option {
104-
name = "Conda"
105-
description = "Only conda (install whatever you need)"
106-
value = "conda-base"
107-
icon = "https://raw.githubusercontent.com/matifali/logos/main/conda.svg"
108-
}
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"
109104
}
110-
```
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+
```
111113

112114
5. For this example, we will use the pre-built [DockerDL](https://github.com/matifali/dockerdl) images.
113115

114-
> **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
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
115117
116-
```hcl
117-
data "docker_registry_image" "dockerdl" {
118-
name = "matifali/dockerdl:${data.coder_parameter.framework.value}"
119-
}
118+
```hcl
119+
data "docker_registry_image" "dockerdl" {
120+
name = "matifali/dockerdl:${data.coder_parameter.framework.value}"
121+
}
120122
121-
resource "docker_image" "dockerdl" {
122-
name = data.docker_registry_image.dockerdl.name
123-
pull_triggers = [data.docker_registry_image.dockerdl.sha256_digest]
124-
# Keep alive for other workspaces to use upon deletion
125-
keep_locally = true
126-
}
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+
}
127129
128-
```
130+
```
129131

130132
> Full example is available [here](https://github.com/matifali/coder-templates/blob/main/deeplearning/main.tf)
131133
132134
## Next steps
133135

134-
- [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)
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

0 commit comments

Comments
 (0)