Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3281d6a

Browse files
committed
quick copy edit
1 parent9b40e7f commit3281d6a

File tree

1 file changed

+28
-55
lines changed

1 file changed

+28
-55
lines changed

‎docs/tutorials/template-from-scratch.md

Lines changed: 28 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,12 @@
1-
#A guided tour ofa template
1+
#Writea template from scratch
22

3-
This guided tour introduces you to the different parts of a Coder template by
4-
showing you how to create a template from scratch.
3+
A template is a common configuration that you use to deploy workspaces.
54

6-
You'll write a simple template that provisions a workspace as a Docker container
7-
with Ubuntu.
5+
This tutorial teaches you how to create a template that provisions a workspace as a Docker container with Ubuntu.
86

97
##Before you start
108

11-
To follow this guide, you'll need:
12-
13-
- A computer or cloud computing instance with both
14-
[Docker](https://docs.docker.com/get-docker/) and[Coder](../install/index.md)
15-
installed on it.
16-
17-
- When setting up your computer or computing instance, make sure to install
18-
Docker first, then Coder. Otherwise, you'll need to add the`coder` user to
19-
the`docker` group.
20-
21-
- The URL for your Coder instance. If you're running Coder locally, the default
22-
URL is[http://127.0.0.1:3000](http://127.0.0.1:3000).
23-
24-
- A text editor. For this tour, we use[GNU nano](https://nano-editor.org/).
9+
You'll need a computer or cloud computing instance with both[Docker](https://docs.docker.com/get-docker/) and[Coder](../install/index.md) installed on it.
2510

2611
##What's in a template
2712

@@ -37,22 +22,21 @@ started, or stopped.
3722
>[Getting Started Guides](https://developer.hashicorp.com/terraform/tutorials).
3823
3924
Here's a simplified diagram that shows the main parts of the template we'll
40-
create.
25+
create:
4126

4227
![Template architecture](../images/templates/template-architecture.png)
4328

4429
##1. Create template files
4530

4631
On your local computer, create a directory for your template and create the
47-
`Dockerfile`.
32+
`Dockerfile`. You will upload the files to your Coder instance later.
4833

4934
```sh
5035
mkdir -p template-tour/build&&cd$_
51-
nano Dockerfile
5236
```
5337

54-
You'll enter a simple`Dockerfile` that starts with the
55-
[official Ubuntu image](https://hub.docker.com/_/ubuntu/). Inthe editor, enter
38+
Enter content into a`Dockerfile` that starts with the
39+
[official Ubuntu image](https://hub.docker.com/_/ubuntu/). Inyour editor, enter
5640
and save the following text in`Dockerfile` then exit the editor:
5741

5842
```dockerfile
@@ -72,21 +56,17 @@ USER ${USER}
7256
WORKDIR /home/${USER}
7357
```
7458

75-
Notice how`Dockerfile` adds a few things to the parent`ubuntu` image, which
59+
`Dockerfile` adds a few things to the parent`ubuntu` image, which
7660
your template needs later:
7761

7862
- It installs the`sudo` and`curl` packages.
7963
- It adds a`coder` user, including a home directory.
8064

8165
##2. Set up template providers
8266

83-
Edit the Terraform file to provision the workspace's resources:
84-
85-
```shell
86-
nano main.tf
87-
```
67+
Edit the Terraform`main.tf` file to provision the workspace's resources.
8868

89-
We'll startby setting upour providers. At a minimum, we need the`coder`
69+
Startby setting upthe providers. At a minimum, we need the`coder`
9070
provider. For this template, we also need the`docker` provider:
9171

9272
```tf
@@ -126,7 +106,7 @@ The
126106
[`coder_workspace`](https://registry.terraform.io/providers/coder/coder/latest/docs/data-sources/workspace)
127107
data source provides details about the state of a workspace, such as its name,
128108
owner, and so on. The data source also lets us know when a workspace is being
129-
started or stopped. We'lltake advantage of this information in later steps to:
109+
started or stopped. We'lluse this information in later steps to:
130110

131111
- Set some environment variables based on the workspace owner.
132112
- Manage ephemeral and persistent storage.
@@ -140,10 +120,9 @@ runs inside the compute aspect of your workspace, typically a VM or container.
140120
In our case, it will run in Docker.
141121

142122
You do not need to have any open ports on the compute aspect, but the agent
143-
needs`curl` access to the Coder server. Remember that we installed`curl` in
144-
`Dockerfile`, earlier.
123+
needs`curl` access to the Coder server.
145124

146-
Add this snippetbelow the last closing`}` in`main.tf` to create the agent:
125+
Add this snippetafter the last closing`}` in`main.tf` to create the agent:
147126

148127
```tf
149128
resource "coder_agent" "main" {
@@ -184,29 +163,26 @@ resource "coder_agent" "main" {
184163

185164
Because Docker is running locally in the Coder server, there is no need to
186165
authenticate`coder_agent`. But if your`coder_agent` is running on a remote
187-
host, your templatewould need
166+
host, your templatewill need
188167
[authentication credentials](../admin/external-auth.md).
189168

190169
This template's agent also runs a startup script, sets environment variables,
191170
and provides metadata.
192171

193-
The
194-
[`startup script`](https://registry.terraform.io/providers/coder/coder/latest/docs/resources/agent#startup_script)
195-
installs[code-server](https://coder.com/docs/code-server), a browser-based
196-
[VS Code](https://code.visualstudio.com/) app that runs in the workspace. We'll
197-
give users access to code-server through`coder_app`, later.
172+
-[`startup script`](https://registry.terraform.io/providers/coder/coder/latest/docs/resources/agent#startup_script)
173+
- Installs[code-server](https://coder.com/docs/code-server), a browser-based[VS Code](https://code.visualstudio.com/) app that runs in the workspace.
198174

199-
The
200-
[`env`](https://registry.terraform.io/providers/coder/coder/latest/docs/resources/agent#env)
201-
block sets environments variables for the workspace. We use the data source from
202-
`coder_workspace` to set the environment variables based on the workspace's
203-
owner. This way, the owner can make git commits immediately without any manual
204-
configuration.
175+
We'll give users access to code-server through`coder_app`, later.
176+
177+
-[`env` block](https://registry.terraform.io/providers/coder/coder/latest/docs/resources/agent#env)
178+
- Sets environments variables for the workspace.
179+
180+
We use the data source from`coder_workspace` to set the environment variables based on the workspace's owner. This way, the owner can make git commits immediately without any manual configuration.
181+
182+
-[`metadata`](../admin/templates/extending-templates/agent-metadata.md) blocks
183+
- Your template can use metadata to show information to the workspace owner Coder displays this metadata in the Coder dashboard.
205184

206-
Your template can use metadata to show information to the workspace owner. Coder
207-
displays this metadata in the Coder dashboard. Our template has
208-
[`metadata`](../admin/templates/extending-templates/agent-metadata.md) blocks
209-
for CPU and RAM usage.
185+
Our template has`metadata` blocks for CPU and RAM usage.
210186

211187
##4. coder_app
212188

@@ -220,10 +196,7 @@ This is commonly used for
220196
[web IDEs](../user-guides/workspace-access/web-ides.md) such as
221197
[code-server](https://coder.com/docs/code-server), RStudio, and JupyterLab.
222198

223-
To install code-server in the workspace, remember that we installed it in the
224-
`startup_script` argument in`coder_agent`. We make it available from a
225-
workspace with a`coder_app` resource. See
226-
[web IDEs](../user-guides/workspace-access/web-ides.md) for more examples.
199+
We installed code-server in the`startup_script` argument. To add code-server to the workspace, make it available from a workspace with a`coder_app` resource. See[web IDEs](../user-guides/workspace-access/web-ides.md) for more examples.
227200

228201
```tf
229202
resource "coder_app" "code-server" {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp