Skip to content

Commit 0512430

Browse files
authored
feat: add templates and update icon paths (#144)
This PR copies the templates in coder/coder/examples/templates over to the registry, so that template contribution can be done through the registry. For now, the starter templates in the coder/coder binary and the templates available in coder/registry will simply be different constructs, until we find a solution we like around a single source of truth for templates that doesn't raise hairy semver concerns for coder/coder: https://codercom.slack.com/archives/C05T7165ET1/p1749493368773469
1 parent 6d1e99d commit 0512430

File tree

55 files changed

+6341
-4
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+6341
-4
lines changed

.github/typos.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
[default.extend-words]
22
muc = "muc" # For Munich location code
33
Hashi = "Hashi"
4-
HashiCorp = "HashiCorp"
4+
HashiCorp = "HashiCorp"
5+
6+
[files]
7+
extend-exclude = ["registry/coder/templates/aws-devcontainer/architecture.svg"] #False positive

.icons/1f4e6.png

5.5 KB
Loading

.icons/do.png

1.96 KB
Loading

.icons/docker.png

5.73 KB
Loading

.icons/k8s.png

5.15 KB
Loading

.icons/lxc.svg

Lines changed: 21 additions & 0 deletions
Loading

.icons/nomad.svg

Lines changed: 2 additions & 0 deletions
Loading
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
---
2+
display_name: AWS EC2 (Devcontainer)
3+
description: Provision AWS EC2 VMs with a devcontainer as Coder workspaces
4+
icon: ../../../../.icons/aws.svg
5+
maintainer_github: coder
6+
verified: true
7+
tags: [vm, linux, aws, persistent, devcontainer]
8+
---
9+
10+
# Remote Development on AWS EC2 VMs using a Devcontainer
11+
12+
Provision AWS EC2 VMs as [Coder workspaces](https://coder.com/docs) with this example template.
13+
![Architecture Diagram](./architecture.svg)
14+
15+
<!-- TODO: Add screenshot -->
16+
17+
## Prerequisites
18+
19+
### Authentication
20+
21+
By default, this template authenticates to AWS using the provider's default [authentication methods](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#authentication-and-configuration).
22+
23+
The simplest way (without making changes to the template) is via environment variables (e.g. `AWS_ACCESS_KEY_ID`) or a [credentials file](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html#cli-configure-files-format). If you are running Coder on a VM, this file must be in `/home/coder/aws/credentials`.
24+
25+
To use another [authentication method](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#authentication), edit the template.
26+
27+
## Required permissions / policy
28+
29+
The following sample policy allows Coder to create EC2 instances and modify
30+
instances provisioned by Coder:
31+
32+
```json
33+
{
34+
"Version": "2012-10-17",
35+
"Statement": [
36+
{
37+
"Sid": "VisualEditor0",
38+
"Effect": "Allow",
39+
"Action": [
40+
"ec2:GetDefaultCreditSpecification",
41+
"ec2:DescribeIamInstanceProfileAssociations",
42+
"ec2:DescribeTags",
43+
"ec2:DescribeInstances",
44+
"ec2:DescribeInstanceTypes",
45+
"ec2:DescribeInstanceStatus",
46+
"ec2:CreateTags",
47+
"ec2:RunInstances",
48+
"ec2:DescribeInstanceCreditSpecifications",
49+
"ec2:DescribeImages",
50+
"ec2:ModifyDefaultCreditSpecification",
51+
"ec2:DescribeVolumes"
52+
],
53+
"Resource": "*"
54+
},
55+
{
56+
"Sid": "CoderResources",
57+
"Effect": "Allow",
58+
"Action": [
59+
"ec2:DescribeInstanceAttribute",
60+
"ec2:UnmonitorInstances",
61+
"ec2:TerminateInstances",
62+
"ec2:StartInstances",
63+
"ec2:StopInstances",
64+
"ec2:DeleteTags",
65+
"ec2:MonitorInstances",
66+
"ec2:CreateTags",
67+
"ec2:RunInstances",
68+
"ec2:ModifyInstanceAttribute",
69+
"ec2:ModifyInstanceCreditSpecification"
70+
],
71+
"Resource": "arn:aws:ec2:*:*:instance/*",
72+
"Condition": {
73+
"StringEquals": {
74+
"aws:ResourceTag/Coder_Provisioned": "true"
75+
}
76+
}
77+
}
78+
]
79+
}
80+
```
81+
82+
## Architecture
83+
84+
This template provisions the following resources:
85+
86+
- AWS Instance
87+
88+
Coder uses `aws_ec2_instance_state` to start and stop the VM. This example template is fully persistent, meaning the full filesystem is preserved when the workspace restarts. See this [community example](https://github.com/bpmct/coder-templates/tree/main/aws-linux-ephemeral) of an ephemeral AWS instance.
89+
90+
> **Note**
91+
> This template is designed to be a starting point! Edit the Terraform to extend the template to support your use case.
92+
93+
## Caching
94+
95+
To speed up your builds, you can use a container registry as a cache.
96+
When creating the template, set the parameter `cache_repo` to a valid Docker repository in the form `host.tld/path/to/repo`.
97+
98+
See the [Envbuilder Terraform Provider Examples](https://github.com/coder/terraform-provider-envbuilder/blob/main/examples/resources/envbuilder_cached_image/envbuilder_cached_image_resource.tf/) for a more complete example of how the provider works.
99+
100+
> [!NOTE]
101+
> We recommend using a registry cache with authentication enabled.
102+
> To allow Envbuilder to authenticate with a registry cache hosted on ECR, specify an IAM instance
103+
> profile that has read and write access to the given registry. For more information, see the
104+
> [AWS documentation](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use_switch-role-ec2_instance-profiles.html).
105+
>
106+
> Alternatively, you can specify the variable `cache_repo_docker_config_path`
107+
> with the path to a Docker config `.json` on disk containing valid credentials for the registry.
108+
109+
## code-server
110+
111+
`code-server` is installed via the [`code-server`](https://registry.coder.com/modules/code-server) registry module. For a list of all modules and templates pplease check [Coder Registry](https://registry.coder.com).

registry/coder/templates/aws-devcontainer/architecture.svg

Lines changed: 8 additions & 0 deletions
Loading
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#cloud-config
2+
cloud_final_modules:
3+
- [scripts-user, always]
4+
hostname: ${hostname}
5+
users:
6+
- name: ${linux_user}
7+
sudo: ALL=(ALL) NOPASSWD:ALL
8+
shell: /bin/bash
9+
ssh_authorized_keys:
10+
- "${ssh_pubkey}"
11+
# Automatically grow the partition
12+
growpart:
13+
mode: auto
14+
devices: ['/']
15+
ignore_growroot_disabled: false
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash
2+
# Install Docker
3+
if ! command -v docker &> /dev/null
4+
then
5+
echo "Docker not found, installing..."
6+
curl -fsSL https://get.docker.com -o get-docker.sh && sh get-docker.sh 2>&1 >/dev/null
7+
usermod -aG docker ${linux_user}
8+
newgrp docker
9+
else
10+
echo "Docker is already installed."
11+
fi
12+
13+
# Set up Docker credentials
14+
mkdir -p "/home/${linux_user}/.docker"
15+
16+
if [ -n "${docker_config_json_base64}" ]; then
17+
# Write the Docker config JSON to disk if it is provided.
18+
printf "%s" "${docker_config_json_base64}" | base64 -d | tee "/home/${linux_user}/.docker/config.json"
19+
else
20+
# Assume that we're going to use the instance IAM role to pull from the cache repo if we need to.
21+
# Set up the ecr credential helper.
22+
apt-get update -y && apt-get install -y amazon-ecr-credential-helper
23+
mkdir -p .docker
24+
printf '{"credsStore": "ecr-login"}' | tee "/home/${linux_user}/.docker/config.json"
25+
fi
26+
chown -R ${linux_user}:${linux_user} "/home/${linux_user}/.docker"
27+
28+
# Start envbuilder
29+
sudo -u coder docker run \
30+
--rm \
31+
--net=host \
32+
-h ${hostname} \
33+
-v /home/${linux_user}/envbuilder:/workspaces \
34+
%{ for key, value in environment ~}
35+
-e ${key}="${value}" \
36+
%{ endfor ~}
37+
${builder_image}

0 commit comments

Comments
 (0)