7 Commits
0.8.0 ... main

Author SHA1 Message Date
Anton
4411aef6fc doc: api - fix broken link 2024-06-13 03:04:31 +05:00
Anton
2a95a86a2f doc: api 2024-06-13 03:03:31 +05:00
Anton
e0b733b18c doc: readme - funding 2024-06-13 03:01:09 +05:00
Anton Zhiyanov
d7e55541c3 doc: funding 2024-06-08 23:43:48 +05:00
Andreas Deininger
f250034cd4 infr: bump github action workflows (#11) 2024-03-28 09:12:01 +05:00
Andreas Deininger
38dfe1a380 fix: typos in comments (#10) 2024-03-28 09:10:03 +05:00
Anton
e6c7b053f9 doc: codapi 0.8.0 2024-03-11 00:12:07 +05:00
11 changed files with 64 additions and 61 deletions

1
.github/FUNDING.yml vendored Normal file
View File

@@ -0,0 +1 @@
github: [nalgeon]

View File

@@ -24,10 +24,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: "stable"
@@ -35,7 +35,7 @@ jobs:
run: make test build
- name: Upload artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: codapi
path: build/codapi

View File

@@ -14,15 +14,15 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: "stable"
- name: Release and publish
uses: goreleaser/goreleaser-action@v4
uses: goreleaser/goreleaser-action@v5
with:
args: release --clean
env:

View File

@@ -32,51 +32,11 @@ For an introduction to Codapi, see this post: [Interactive code examples for fun
See [Installing Codapi](docs/install.md) for details.
## Usage (API)
## Usage
Call `/v1/exec` to run the code in a sandbox:
See [API](docs/api.md) to run sandboxed code using the HTTP API.
```http
POST https://api.codapi.org/v1/exec
content-type: application/json
{
"sandbox": "python",
"command": "run",
"files": {
"": "print('hello world')"
}
}
```
`sandbox` is the name of the pre-configured sandbox, and `command` is the name of a command supported by that sandbox. See [Adding a sandbox](docs/add-sandbox.md) for details on how to add a new sandbox.
`files` is a map, where the key is a filename and the value is its contents. When executing a single file, it should either be named as the `command` expects, or be an empty string (as in the example above).
Response:
```http
HTTP/1.1 200 OK
Content-Type: application/json
```
- `id` is the unique execution identifier.
- `ok` is `true` if the code executed without errors, or `false` otherwise.
- `duration` is the execution time in milliseconds.
- `stdout` is what the code printed to the standard output.
- `stderr` is what the code printed to the standard error, or a compiler/os error (if any).
## Usage (JavaScript)
See [codapi-js](https://github.com/nalgeon/codapi-js) to embed the JavaScript widget into a web page. The widget uses exactly the same API as described above.
## Contributing
Contributions are welcome. For anything other than bugfixes, please first open an issue to discuss what you want to change.
Be sure to add or update tests as appropriate.
See [codapi-js](https://github.com/nalgeon/codapi-js) to embed the JavaScript widget into a web page.
## Contributing
@@ -84,12 +44,12 @@ Contributions are welcome. For anything other than bugfixes, please first open a
Be sure to add or update tests as appropriate.
## Funding
Copyright 2023 [Anton Zhiyanov](https://antonz.org/).
Codapi is mostly a [one-man](https://antonz.org/) project, not backed by a VC fund or anything.
The software is available under the Apache-2.0 license.
If you find Codapi useful, please consider sponsoring it on GitHub. It really helps to move the project forward.
## Stay tuned
♥ [Become a sponsor](https://github.com/sponsors/nalgeon) to support Codapi.
★ [Subscribe](https://antonz.org/subscribe/) to stay on top of new features.

42
docs/api.md Normal file
View File

@@ -0,0 +1,42 @@
# API
Call `/v1/exec` to run the code in a sandbox:
```http
POST https://api.codapi.org/v1/exec
content-type: application/json
{
"sandbox": "python",
"command": "run",
"files": {
"": "print('hello world')"
}
}
```
`sandbox` is the name of the pre-configured sandbox, and `command` is the name of a command supported by that sandbox. See [Adding a sandbox](add-sandbox.md) for details on how to add a new sandbox.
`files` is a map, where the key is a filename and the value is its contents. When executing a single file, it should either be named as the `command` expects, or be an empty string (as in the example above).
Response:
```http
HTTP/1.1 200 OK
Content-Type: application/json
```
- `id` is the unique execution identifier.
- `ok` is `true` if the code executed without errors, or `false` otherwise.
- `duration` is the execution time in milliseconds.
- `stdout` is what the code printed to the standard output.
- `stderr` is what the code printed to the standard error, or a compiler/os error (if any).
-
- `id` is the unique execution identifier.
- `ok` is `true` if the code executed without errors, or `false` otherwise.
- `duration` is the execution time in milliseconds.
- `stdout` is what the code printed to the standard output.
- `stderr` is what the code printed to the standard error, or a compiler/os error (if any).
-

View File

@@ -28,10 +28,10 @@ docker run hello-world
```sh
cd /opt/codapi
curl -L -O "https://github.com/nalgeon/codapi/releases/download/0.7.1/codapi_0.7.1_linux_amd64.tar.gz"
tar xvzf codapi_0.7.1_linux_amd64.tar.gz
curl -L -O "https://github.com/nalgeon/codapi/releases/download/0.8.0/codapi_0.8.0_linux_amd64.tar.gz"
tar xvzf codapi_0.8.0_linux_amd64.tar.gz
chmod +x codapi
rm -f codapi_0.7.1_linux_amd64.tar.gz
rm -f codapi_0.8.0_linux_amd64.tar.gz
```
5. Build Docker images (as codapi):

View File

@@ -6,7 +6,7 @@ import (
"sort"
)
// A Config describes application cofig.
// A Config describes application config.
type Config struct {
PoolSize int `json:"pool_size"`
Verbose bool `json:"verbose"`

View File

@@ -209,7 +209,7 @@ func (e *Docker) exec(box *config.Box, step *config.Step, req Request, dir strin
if err.Error() == "signal: killed" {
if step.Action == actionRun {
// we have to "docker kill" the container here, because the proccess
// we have to "docker kill" the container here, because the process
// inside the container is not related to the "docker run" process,
// and will hang forever after the "docker run" process is killed
go func() {

View File

@@ -63,7 +63,7 @@ func (err ExecutionError) Unwrap() error {
}
// An ArgumentError is returned if code execution failed
// due to the invalid value of the request agrument.
// due to the invalid value of the request argument.
type ArgumentError struct {
name string
reason error

View File

@@ -62,7 +62,7 @@ func (m *Memory) MustNotHave(t *testing.T, message ...string) {
}
}
// Clear cleares the memory.
// Clear clears the memory.
func (m *Memory) Clear() {
m.Lines = []string{}
}

View File

@@ -20,7 +20,7 @@ var engineConstr = map[string]func(*config.Config, string, string) engine.Engine
}
// engines is the registry of command executors.
// Each engine executes a specific command in a specifix sandbox.
// Each engine executes a specific command in a specific sandbox.
// sandbox : command : engine
// TODO: Maybe it's better to create a single instance of each engine
// and pass the sandbox and command as arguments to the Exec.