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

Skip to content

Commit 0b6efce

Browse files
johnstcnmafredri
andauthored
add lima template for coder (#2452)
This commit adds a lima example for Coder. You can now run limactl start --name=coder ./examples/lima/coder.yaml and have a "prod-like" Coder instance up and running within a minute or so. Co-authored-by: Mathias Fredriksson <[email protected]>
1 parent a9d62cc commit 0b6efce

File tree

2 files changed

+171
-0
lines changed

2 files changed

+171
-0
lines changed

examples/lima/README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
name: Run Coder in Lima
3+
description: Quickly stand up Coder using Lima
4+
tags: [local, docker, vm, lima]
5+
---
6+
7+
# Run Coder in Lima
8+
9+
This provides a sample [Lima](https://github.com/lima-vm/lima) configuration for Coder.
10+
This lets you quickly test out Coder in a self-contained environment.
11+
12+
> Prerequisite: You must have `lima` installed and available to use this.
13+
14+
## Getting Started
15+
16+
- Run `limactl start --name=coder https://raw.githubusercontent.com/coder/coder/main/examples/lima/coder.yaml`
17+
- You can use the configuration as-is, or edit it to your liking.
18+
19+
This will:
20+
- Start an Ubuntu 22.04 VM
21+
- Install Docker and Terraform from the official repos
22+
- Install Coder using the [installation script](https://coder.com/docs/coder-oss/latest/install#installsh)
23+
- Generates an initial user account `[email protected]` with a randomly generated password (stored in the VM under `/home/${USER}.linux/.config/coderv2/password`)
24+
- Initializes a [sample Docker template](https://github.com/coder/coder/tree/main/examples/templates/docker-code-server) for creating workspaces
25+
26+
Once this completes, you can visit `http://localhost:3000` and start creating workspaces!
27+
28+
Alternatively, enter the VM with `limactl shell coder` and run `coder template init` to start creating your own templates!
29+
30+
## Further Information
31+
32+
- To learn more about Lima, [visit the the project's GitHub page](https://github.com/lima-vm/lima/).

examples/lima/coder.yaml

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
# Deploy Coder in Lima via the install script
2+
# See: https://coder.com/docs/coder-oss/latest/install
3+
# $ limactl start ./coder.yaml
4+
# $ limactl shell coder
5+
# The web UI is accessible on http://localhost:3000 -- ports are forwarded automatically by lima:
6+
# $ coder login http://localhost:3000
7+
8+
# This example requires Lima v0.8.3 or later.
9+
images:
10+
# Try to use release-yyyyMMdd image if available. Note that release-yyyyMMdd will be removed after several months.
11+
- location: "https://cloud-images.ubuntu.com/releases/22.04/release-20220420/ubuntu-22.04-server-cloudimg-amd64.img"
12+
arch: "x86_64"
13+
digest: "sha256:de5e632e17b8965f2baf4ea6d2b824788e154d9a65df4fd419ec4019898e15cd"
14+
- location: "https://cloud-images.ubuntu.com/releases/22.04/release-20220420/ubuntu-22.04-server-cloudimg-arm64.img"
15+
arch: "aarch64"
16+
digest: "sha256:66224c7fed99ff5a5539eda406c87bbfefe8af6ff6b47d92df3187832b5b5d4f"
17+
# Fallback to the latest release image.
18+
# Hint: run `limactl prune` to invalidate the cache
19+
- location: "https://cloud-images.ubuntu.com/releases/22.04/release/ubuntu-22.04-server-cloudimg-amd64.img"
20+
arch: "x86_64"
21+
- location: "https://cloud-images.ubuntu.com/releases/22.04/release/ubuntu-22.04-server-cloudimg-arm64.img"
22+
arch: "aarch64"
23+
24+
# Your home directory is mounted read-only
25+
mounts:
26+
- location: "~"
27+
containerd:
28+
system: false
29+
user: false
30+
hostResolver:
31+
# hostResolver.hosts requires lima 0.8.3 or later. Names defined here will also
32+
# resolve inside containers, and not just inside the VM itself.
33+
hosts:
34+
host.docker.internal: host.lima.internal
35+
provision:
36+
- mode: system
37+
# This script defines the host.docker.internal hostname when hostResolver is disabled.
38+
# It is also needed for lima 0.8.2 and earlier, which does not support hostResolver.hosts.
39+
# Names defined in /etc/hosts inside the VM are not resolved inside containers when
40+
# using the hostResolver; use hostResolver.hosts instead (requires lima 0.8.3 or later).
41+
script: |
42+
#!/bin/sh
43+
set -eux -o pipefail
44+
sed -i 's/host.lima.internal.*/host.lima.internal host.docker.internal/' /etc/hosts
45+
- mode: system
46+
script: |
47+
#!/bin/bash
48+
set -eux -o pipefail
49+
command -v docker >/dev/null 2>&1 && exit 0
50+
export DEBIAN_FRONTEND=noninteractive
51+
curl -fsSL https://get.docker.com | sh
52+
# Ensure we have a decent logging driver set up for Docker, for debugging.
53+
cat > /etc/docker/daemon.json << EOF
54+
{
55+
"log-driver": "journald"
56+
}
57+
EOF
58+
systemctl restart docker
59+
# In case a user forgets to set the arch correctly, just install binfmt
60+
docker run --privileged --rm tonistiigi/binfmt --install all
61+
- mode: system
62+
script: |
63+
#!/bin/bash
64+
set -eux -o pipefail
65+
command -v terraform >/dev/null 2>&1 && exit 0
66+
wget -qO - terraform.gpg https://apt.releases.hashicorp.com/gpg | gpg --dearmor -o /usr/share/keyrings/terraform-archive-keyring.gpg
67+
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/terraform-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" > /etc/apt/sources.list.d/terraform.list
68+
export DEBIAN_FRONTEND=noninteractive
69+
apt-get update -y
70+
apt-get install terraform=1.1.9
71+
apt-mark hold terraform
72+
- mode: system
73+
script: |
74+
#!/bin/bash
75+
set -eux -o pipefail
76+
command -v coder >/dev/null 2>&1 && exit 0
77+
export DEBIAN_FRONTEND=noninteractive
78+
export HOME=/root
79+
curl -fsSL https://coder.com/install.sh | sh
80+
# Ensure Coder has permissions on /var/run/docker.socket
81+
usermod -aG docker coder
82+
# Ensure coder listens on all interfaces
83+
sed -i 's/CODER_ADDRESS=.*/CODER_ADDRESS=0.0.0.0:3000/' /etc/coder.d/coder.env
84+
# Ensure coder starts on boot
85+
systemctl enable coder
86+
systemctl start coder
87+
# Wait for Coder to have downloaded Terraform
88+
timeout 60s bash -c 'until /var/cache/coder/terraform version >/dev/null 2>&1; do sleep 1; done'
89+
# Coder restarts after downloading Terraform, wait for it to become available
90+
timeout 60s bash -c 'until nc -z localhost 3000 > /dev/null 2>&1; do sleep 1; done'
91+
- mode: user
92+
script: |
93+
#!/bin/bash
94+
set -eux -o pipefail
95+
# If we are already logged in, nothing to do
96+
coder templates list >/dev/null 2>&1 && exit 0
97+
# Set up initial user
98+
[ ! -e ~/.config/coderv2/session ] && coder login http://localhost:3000 --username admin --email [email protected] --password $(< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c8 | tee ${HOME}/.config/coderv2/password)
99+
# Create an initial template
100+
cd ${HOME}
101+
echo code-server | coder templates init
102+
cd ./docker-code-server
103+
if [ $(arch) = "aarch64" ]; then
104+
sed -i 's/arch.*=.*"amd64"/arch = "arm64"/' ./main.tf
105+
fi
106+
coder templates create docker-code-server -y -d .
107+
probes:
108+
- description: "docker to be installed"
109+
script: |
110+
#!/bin/bash
111+
set -eux -o pipefail
112+
if ! timeout 30s bash -c "until command -v docker >/dev/null 2>&1; do sleep 3; done"; then
113+
echo >&2 "docker is not installed yet"
114+
exit 1
115+
fi
116+
hint: |
117+
See "/var/log/cloud-init-output.log" in the guest.
118+
- description: "coder to be installed"
119+
script: |
120+
#!/bin/bash
121+
set -eux -o pipefail
122+
if ! timeout 30s bash -c "until command -v coder >/dev/null 2>&1; do sleep 3; done"; then
123+
echo >&2 "coder is not installed yet"
124+
exit 1
125+
fi
126+
hint: |
127+
See "/var/log/cloud-init-output.log" in the guest.
128+
message: |
129+
All Done! Your Coder instance is accessible at http://localhost:3000
130+
131+
Username: "[email protected]"
132+
Password: Run `LIMA_INSTANCE=coder lima cat /home/${USER}.linux/.config/coderv2/password` 🤫
133+
134+
Get started creating your own template now:
135+
------
136+
limactl shell coder
137+
cd && coder templates init
138+
------
139+

0 commit comments

Comments
 (0)