feat: initial public version

This commit is contained in:
Anton
2023-11-25 04:02:45 +05:00
parent ebd1d47fc6
commit 8447197d0f
64 changed files with 3880 additions and 4 deletions

70
docs/docker-xfs.md Normal file
View File

@@ -0,0 +1,70 @@
# XFS filesystem for Docker
1. Install the necessary packages:
```bash
sudo apt-get update
sudo apt-get install xfsprogs
```
2. Identify the disk or partition you want to use for the new filesystem. You can use the `lsblk` or `fdisk -l` command to list the available disks and partitions. Make sure you select the correct one as this process will erase all data on it.
3. If the partition you want to use is not formatted, format it with an XFS filesystem. Replace `/dev/sdX` with the appropriate device identifier:
```bash
sudo mkfs.xfs /dev/sdX
```
4. Once the partition is formatted, create a mount point. This will be the directory where the new filesystem will be mounted:
```bash
sudo mkdir /mnt/docker
```
5. Update the `/etc/fstab` file to automatically mount the new filesystem at boot:
```
/dev/sdX /mnt/docker xfs defaults,nofail,discard,noatime,quota,prjquota,pquota,gquota 0 2
```
6. Mount the new filesystem and verify that it is working:
```bash
sudo mount -a
df -h
```
The output of `df -h` should show the new filesystem mounted at `/mnt/docker`.
7. Stop the docker daemon:
```bash
systemctl stop docker
```
8. Update the `/etc/docker/daemon.json` file to point docker to the new mount point:
```json
{
"data-root": "/mnt/docker"
}
```
9. Start the docker daemon:
```bash
systemctl start docker
```
10. Build the images:
```bash
su - codapi
make images
```
11. Verify that docker can now limit the storage size:
```bash
docker run -it --storage-opt size=16m codapi/alpine /bin/df -h | grep overlay
```

101
docs/install.md Normal file
View File

@@ -0,0 +1,101 @@
# Installing Codapi
Steps for Debian (11/12) or Ubuntu (20.04/22.04).
1. Install necessary packages (as root):
```sh
apt update && apt install -y ca-certificates curl docker.io make unzip
systemctl enable docker.service
systemctl restart docker.service
```
2. Create Codapi user (as root):
```sh
useradd --groups docker --shell /usr/bin/bash --create-home --home /opt/codapi codapi
```
3. Verify that Docker is working (as codapi):
```sh
docker run hello-world
```
4. Install Codapi (as codapi):
```sh
cd /opt/codapi
curl -L -o codapi.zip "https://api.github.com/repos/nalgeon/codapi/actions/artifacts/926428361/zip"
unzip -u codapi.zip
chmod +x build/codapi
rm -f codapi.zip
```
6. Build Docker images (as codapi):
```sh
cd /opt/codapi
make images
```
7. Verify that Codapi starts without errors (as codapi):
```sh
cd /opt/codapi
./build/codapi
```
Should print the `alpine` box and the `sh` command:
```
2023/09/16 15:18:05 codapi 20230915:691d224
2023/09/16 15:18:05 listening on port 1313...
2023/09/16 15:18:05 workers: 8
2023/09/16 15:18:05 boxes: [alpine]
2023/09/16 15:18:05 commands: [sh]
```
Stop it with Ctrl+C.
8. Configure Codapi as systemd service (as root):
```sh
mv /opt/codapi/codapi.service /etc/systemd/system/
chown root:root /etc/systemd/system/codapi.service
systemctl enable codapi.service
systemctl start codapi.service
```
Verify that the Codapi service is running:
```sh
systemctl status codapi.service
```
Should print `active (running)`:
```
codapi.service - Code playgrounds
Loaded: loaded (/etc/systemd/system/codapi.service; enabled; preset: enabled)
Active: active (running)
...
```
9. Verify that Codapi is working:
```sh
curl -H "content-type: application/json" -d '{ "sandbox": "sh", "command": "run", "files": {"": "echo hello" }}' http://localhost:1313/v1/exec
```
Should print `ok` = `true`:
```json
{
"id": "sh_run_dd27ed27",
"ok": true,
"duration": 650,
"stdout": "hello\n",
"stderr": ""
}
```