Skip to content

Commit 4a27ed0

Browse files
committed
doc: add lima yaml file for codapi
1 parent 93571b9 commit 4a27ed0

2 files changed

Lines changed: 103 additions & 0 deletions

File tree

lima/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# codapi-lima
2+
3+
This is a mix of the Debian and Docker (rootful) templates,
4+
with the Codapi provisioning from install.md added on top.
5+
6+
It will run the codapi server in a virtual machine instance,
7+
and export codapi on port 1313 for usage on the host system.
8+
9+
To start a new instance:
10+
`limactl start codapi.yaml`
11+
12+
CNCF Lima - Linux Machines.
13+
See <https://lima-vm.io/>

lima/codapi.yaml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
minimumLimaVersion: 2.0.0
2+
3+
#base:
4+
#- template:_images/debian-13
5+
images:
6+
- location: https://cloud.debian.org/images/cloud/trixie/daily/latest/debian-13-genericcloud-amd64-daily.qcow2
7+
arch: x86_64
8+
- location: https://cloud.debian.org/images/cloud/trixie/daily/latest/debian-13-genericcloud-arm64-daily.qcow2
9+
arch: aarch64
10+
mountTypesUnsupported: [9p]
11+
# Mounts are disabled in this template, but can be enabled optionally.
12+
mounts: []
13+
# containerd is managed by Docker, not by Lima, so the values are set to false here.
14+
containerd:
15+
system: false
16+
user: false
17+
provision:
18+
- mode: system
19+
script: |
20+
#!/bin/sh
21+
command -v ca-certificates curl make unzip >/dev/null 2>&1 && exit 0
22+
sudo apt update && sudo apt install -y ca-certificates curl make unzip
23+
- mode: system
24+
script: |
25+
#!/bin/bash
26+
set -eux -o pipefail
27+
command -v docker >/dev/null 2>&1 && exit 0
28+
export DEBIAN_FRONTEND=noninteractive
29+
curl -fsSL https://get.docker.com | sh
30+
- mode: system
31+
script: |
32+
#!/bin/sh
33+
id codapi >/dev/null 2>&1 && exit 0
34+
sudo useradd --groups docker --shell /usr/bin/bash --create-home --home /opt/codapi codapi
35+
- mode: system
36+
script: |
37+
#!/bin/bash
38+
set -eux -o pipefail
39+
test -e /opt/codapi/bin/codapi && exit 0
40+
sudo su - codapi
41+
cd /opt/codapi
42+
command -v jq || apt install -y jq
43+
version=$(curl -fsSL https://api.github.com/repos/nalgeon/codapi/releases/latest | jq -r .tag_name | sed -e 's/v//')
44+
case $(uname -m) in
45+
x86_64) arch=amd64;;
46+
aarch64) arch=arm64;;
47+
esac
48+
curl -fL -o codapi.tar.gz "https://github.com/nalgeon/codapi/releases/download/v$version/codapi_${version}_linux_${arch}.tar.gz"
49+
tar xvzf codapi.tar.gz
50+
rm -f codapi.tar.gz
51+
- mode: system
52+
script: |
53+
#!/bin/bash
54+
set -eux -o pipefail
55+
sudo su - codapi
56+
cd /opt/codapi
57+
docker build --file sandboxes/ash/Dockerfile --tag codapi/ash:latest sandboxes/ash
58+
- mode: system
59+
script: |
60+
#!/bin/sh
61+
sudo mv /opt/codapi/codapi.service /etc/systemd/system/
62+
sudo chown root:root /etc/systemd/system/codapi.service
63+
sudo systemctl enable codapi.service
64+
sudo systemctl start codapi.service
65+
probes:
66+
- script: |
67+
#!/bin/bash
68+
set -eux -o pipefail
69+
if ! timeout 30s bash -c "until command -v docker >/dev/null 2>&1; do sleep 3; done"; then
70+
echo >&2 "docker is not installed yet"
71+
exit 1
72+
fi
73+
if ! timeout 30s bash -c "until pgrep dockerd; do sleep 3; done"; then
74+
echo >&2 "dockerd is not running"
75+
exit 1
76+
fi
77+
if ! timeout 30s bash -c "until test -e /opt/codapi/bin/codapi; do sleep 3; done"; then
78+
echo >&2 "codapi is not installed yet"
79+
exit 1
80+
fi
81+
if ! timeout 30s bash -c "until pgrep codapi; do sleep 3; done"; then
82+
echo >&2 "codapi is not running"
83+
exit 1
84+
fi
85+
hint: See "/var/log/cloud-init-output.log" in the guest
86+
message: |
87+
To verify that Codapi is working, run the following commands:
88+
------
89+
curl -H "content-type: application/json" -d '{ "sandbox": "ash", "command": "run", "files": {"": "echo hello" }}' http://localhost:1313/v1/exec
90+
------

0 commit comments

Comments
 (0)