-
Notifications
You must be signed in to change notification settings - Fork 891
add lima template for coder #2452
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5944d4d
add lima template for coder
johnstcn 4eb46b1
add README, auto-init template
johnstcn 0690ba7
Merge remote-tracking branch 'origin/main' into cj/lima-template
johnstcn 5782c86
Apply suggestions from code review
johnstcn 4094b02
fix initialization order
johnstcn 71a54e5
Merge remote-tracking branch 'origin/main' into cj/lima-template
johnstcn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--- | ||
name: Run Coder in Lima | ||
description: Quickly stand up Coder using Lima | ||
tags: [local, docker, vm, lima] | ||
--- | ||
|
||
# Run Coder in Lima | ||
|
||
This provides a sample [Lima](https://github.com/lima-vm/lima) configuration for Coder. | ||
This lets you quickly test out Coder in a self-contained environment. | ||
|
||
> Prerequisite: You must have `lima` installed and available to use this. | ||
|
||
## Getting Started | ||
|
||
- Run `limactl start --name=coder https://raw.githubusercontent.com/coder/coder/main/examples/lima/coder.yaml` | ||
- You can use the configuration as-is, or edit it to your liking. | ||
|
||
This will: | ||
- Start an Ubuntu 22.04 VM | ||
- Install Docker and Terraform from the official repos | ||
- Install Coder using the [installation script](https://coder.com/docs/coder-oss/latest/install#installsh) | ||
- Generates an initial user account `[email protected]` with a randomly generated password (stored in the VM under `/home/${USER}.linux/.config/coderv2/password`) | ||
- Initializes a [sample Docker template](https://github.com/coder/coder/tree/main/examples/templates/docker-code-server) for creating workspaces | ||
|
||
Once this completes, you can visit `http://localhost:3000` and start creating workspaces! | ||
|
||
Alternatively, enter the VM with `limactl shell coder` and run `coder template init` to start creating your own templates! | ||
|
||
## Further Information | ||
|
||
- To learn more about Lima, [visit the the project's GitHub page](https://github.com/lima-vm/lima/). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
# Deploy Coder in Lima via the install script | ||
# See: https://coder.com/docs/coder-oss/latest/install | ||
# $ limactl start ./coder.yaml | ||
# $ limactl shell coder | ||
# The web UI is accessible on http://localhost:3000 -- ports are forwarded automatically by lima: | ||
# $ coder login http://localhost:3000 | ||
|
||
# This example requires Lima v0.8.3 or later. | ||
images: | ||
# Try to use release-yyyyMMdd image if available. Note that release-yyyyMMdd will be removed after several months. | ||
- location: "https://cloud-images.ubuntu.com/releases/22.04/release-20220420/ubuntu-22.04-server-cloudimg-amd64.img" | ||
arch: "x86_64" | ||
digest: "sha256:de5e632e17b8965f2baf4ea6d2b824788e154d9a65df4fd419ec4019898e15cd" | ||
- location: "https://cloud-images.ubuntu.com/releases/22.04/release-20220420/ubuntu-22.04-server-cloudimg-arm64.img" | ||
arch: "aarch64" | ||
digest: "sha256:66224c7fed99ff5a5539eda406c87bbfefe8af6ff6b47d92df3187832b5b5d4f" | ||
# Fallback to the latest release image. | ||
# Hint: run `limactl prune` to invalidate the cache | ||
- location: "https://cloud-images.ubuntu.com/releases/22.04/release/ubuntu-22.04-server-cloudimg-amd64.img" | ||
arch: "x86_64" | ||
- location: "https://cloud-images.ubuntu.com/releases/22.04/release/ubuntu-22.04-server-cloudimg-arm64.img" | ||
arch: "aarch64" | ||
|
||
# Your home directory is mounted read-only | ||
mounts: | ||
- location: "~" | ||
containerd: | ||
system: false | ||
user: false | ||
hostResolver: | ||
# hostResolver.hosts requires lima 0.8.3 or later. Names defined here will also | ||
# resolve inside containers, and not just inside the VM itself. | ||
hosts: | ||
host.docker.internal: host.lima.internal | ||
provision: | ||
- mode: system | ||
# This script defines the host.docker.internal hostname when hostResolver is disabled. | ||
# It is also needed for lima 0.8.2 and earlier, which does not support hostResolver.hosts. | ||
# Names defined in /etc/hosts inside the VM are not resolved inside containers when | ||
# using the hostResolver; use hostResolver.hosts instead (requires lima 0.8.3 or later). | ||
script: | | ||
#!/bin/sh | ||
set -eux -o pipefail | ||
sed -i 's/host.lima.internal.*/host.lima.internal host.docker.internal/' /etc/hosts | ||
- mode: system | ||
script: | | ||
#!/bin/bash | ||
set -eux -o pipefail | ||
command -v docker >/dev/null 2>&1 && exit 0 | ||
export DEBIAN_FRONTEND=noninteractive | ||
curl -fsSL https://get.docker.com | sh | ||
# Ensure we have a decent logging driver set up for Docker, for debugging. | ||
cat > /etc/docker/daemon.json << EOF | ||
{ | ||
"log-driver": "journald" | ||
} | ||
EOF | ||
systemctl restart docker | ||
# In case a user forgets to set the arch correctly, just install binfmt | ||
docker run --privileged --rm tonistiigi/binfmt --install all | ||
- mode: system | ||
script: | | ||
#!/bin/bash | ||
set -eux -o pipefail | ||
command -v terraform >/dev/null 2>&1 && exit 0 | ||
wget -qO - terraform.gpg https://apt.releases.hashicorp.com/gpg | gpg --dearmor -o /usr/share/keyrings/terraform-archive-keyring.gpg | ||
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 | ||
export DEBIAN_FRONTEND=noninteractive | ||
apt-get update -y | ||
apt-get install terraform=1.1.9 | ||
apt-mark hold terraform | ||
- mode: system | ||
script: | | ||
#!/bin/bash | ||
set -eux -o pipefail | ||
command -v coder >/dev/null 2>&1 && exit 0 | ||
export DEBIAN_FRONTEND=noninteractive | ||
export HOME=/root | ||
curl -fsSL https://coder.com/install.sh | sh | ||
# Ensure Coder has permissions on /var/run/docker.socket | ||
usermod -aG docker coder | ||
# Ensure coder listens on all interfaces | ||
sed -i 's/CODER_ADDRESS=.*/CODER_ADDRESS=0.0.0.0:3000/' /etc/coder.d/coder.env | ||
# Ensure coder starts on boot | ||
systemctl enable coder | ||
systemctl start coder | ||
# Wait for Coder to have downloaded Terraform | ||
timeout 60s bash -c 'until /var/cache/coder/terraform version >/dev/null 2>&1; do sleep 1; done' | ||
# Coder restarts after downloading Terraform, wait for it to become available | ||
timeout 60s bash -c 'until nc -z localhost 3000 > /dev/null 2>&1; do sleep 1; done' | ||
- mode: user | ||
script: | | ||
#!/bin/bash | ||
set -eux -o pipefail | ||
# If we are already logged in, nothing to do | ||
coder templates list >/dev/null 2>&1 && exit 0 | ||
# Set up initial user | ||
[ ! -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) | ||
# Create an initial template | ||
cd ${HOME} | ||
echo code-server | coder templates init | ||
cd ./docker-code-server | ||
if [ $(arch) = "aarch64" ]; then | ||
sed -i 's/arch.*=.*"amd64"/arch = "arm64"/' ./main.tf | ||
fi | ||
coder templates create docker-code-server -y -d . | ||
probes: | ||
- description: "docker to be installed" | ||
script: | | ||
#!/bin/bash | ||
set -eux -o pipefail | ||
if ! timeout 30s bash -c "until command -v docker >/dev/null 2>&1; do sleep 3; done"; then | ||
echo >&2 "docker is not installed yet" | ||
exit 1 | ||
fi | ||
hint: | | ||
See "/var/log/cloud-init-output.log" in the guest. | ||
- description: "coder to be installed" | ||
script: | | ||
#!/bin/bash | ||
set -eux -o pipefail | ||
if ! timeout 30s bash -c "until command -v coder >/dev/null 2>&1; do sleep 3; done"; then | ||
echo >&2 "coder is not installed yet" | ||
exit 1 | ||
fi | ||
hint: | | ||
See "/var/log/cloud-init-output.log" in the guest. | ||
message: | | ||
All Done! Your Coder instance is accessible at http://localhost:3000 | ||
|
||
Username: "[email protected]" | ||
Password: Run `LIMA_INSTANCE=coder lima cat /home/${USER}.linux/.config/coderv2/password` 🤫 | ||
|
||
Get started creating your own template now: | ||
------ | ||
limactl shell coder | ||
cd && coder templates init | ||
------ | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.