Skip to content

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 6 commits into from
Jun 17, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add README, auto-init template
  • Loading branch information
johnstcn committed Jun 17, 2022
commit 4eb46b1e0f40f1c32ab581312dab1351c91a8e30
32 changes: 32 additions & 0 deletions examples/lima/README.md
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]
---

# Lima VM Template

This provides a [Lima](https://github.com/lima-vm/lima) template for Coder.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: We might not want to call this "template" to avoid confusion with actual coder templates (and examples/templates directory). Maybe "sample" or just remove?

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 from the official repos
- Install Coder using the [installation script](https://coder.com/docs/coder-oss/latest/install#installsh)
- Generates an initial user account `admin@coder.com` 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/).
43 changes: 27 additions & 16 deletions examples/lima/coder.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ provision:
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jiffy

- mode: system
script: |
#!/bin/bash
Expand All @@ -79,8 +90,18 @@ provision:
set -eux -o pipefail
# If we are already logged in, nothing to do
coder templates list >/dev/null 2>&1 && exit 0
# Wait for Coder to become available
timeout 30s bash -c 'until nc -z localhost 3000; do sleep 1; done'
# Set up initial user
[ ! -e ~/.config/coderv2/session ] && coder login http://localhost:3000 --username admin --email admin@coder.com --password password
[ ! -e ~/.config/coderv2/session ] && coder login http://localhost:3000 --username admin --email admin@coder.com --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: |
Expand All @@ -102,25 +123,15 @@ probes:
fi
hint: |
See "/var/log/cloud-init-output.log". in the guest
- description: "terraform to be fully downloaded"
script: |
#!/bin/bash
set -eux -o pipefail
if ! timeout 30s bash -c "until [ $(du /var/cache/coder/terraform | awk '{print $1}') -ge 62784 ] >/dev/null 2>&1; do sleep 3; done"; then
echo >&2 "terraform is not fully downloaded yet"
exit 1
fi
hint: |
Check "/var/cache/coder/terraform" in the guest
message: |
All Done! Your Coder instance is accessible at http://localhost:3000

Username: "admin@coder.com"
Password: "password" 🤫
Start a workspace now by running the following commands:
Password: `LIMA_INSTANCE=coder lima cat /home/${USER}.linux/.config/coderv2/password` 🤫
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Password: `LIMA_INSTANCE=coder lima cat /home/${USER}.linux/.config/coderv2/password` 🤫
Password: $(LIMA_INSTANCE=coder lima cat /home/${USER}.linux/.config/coderv2/password) 🤫

Minor suggestion, $() is the preferred form, but I didn't test if it works in this scenario 😅.

Copy link
Member Author

@johnstcn johnstcn Jun 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, it doesn't execute in the output, it's more of an indication for the user to run it 😅
I'll change that wording a bit so it's clearer!


Get started creating your own template now:
------
limactl shell coder
cd && echo code-server | coder templates init
cd ./docker-code-server && coder templates create -y
coder create -t docker-code-server my-workspace -y
cd && coder templates init
------