nalgeon / codapi

Interactive code examples for documentation, education and fun
https://codapi.org
Apache License 2.0
1.3k stars 61 forks source link

go can't create file, read-only file system #22

Closed 52funny closed 4 days ago

52funny commented 1 month ago

Thank you to the author for such a great work, during my use, I found that go would not run and I would get the following error.

2024/06/14 15:17:16 codapi 0.8.0, commit 4468c6193c552ad16de72e52fbce94fb1fecb9a8, built at 2024-03-10T19:05:55Z
2024/06/14 15:17:16 listening on port 1313...
2024/06/14 15:17:16 workers: 8
2024/06/14 15:17:16 boxes: [alpine go]
2024/06/14 15:17:16 commands: [go sh]
2024/06/14 15:17:19 [run --rm --name go_run_5e695235 --runtime runc --cpus 1 --memory 64m --network none --pids-limit 64 --user sandbox --read-only --volume /tmp/572654041:/sandbox:rw --cap-drop all --ulimit nofile=96 codapi/go go run main.go]
2024/06/14 15:17:20 ✗ go_run_5e695235: go: creating work dir: mkdir /tmp/go-build2203374890: read-only file system (exi [truncated]
^C2024/06/14 15:17:35 stopping...

This is my go dockerfile

FROM golang:1.22

# user
RUN adduser --home /sandbox --disabled-password sandbox

USER sandbox

WORKDIR /sandbox

# proxy
RUN go env -w GO111MODULE=on && go env -w GOPROXY=https://goproxy.cn

# packages
RUN go mod init code \
    && go get -u github.com/cloudflare/circl \
    && go get -u github.com/tidwall/gjson

commands/go.json

{
    "run": {
        "engine": "docker",
        "entry": "main.go",
        "steps": [
            {
                "box": "go",
                "command": [
                    "go",
                    "run",
                    "main.go"
                ]
            }
        ]
    }
}

boxes.json

{
    "alpine": {
        "image": "codapi/alpine"
    },
    "go": {
        "image": "codapi/go"
    }
}
studygyaan1 commented 2 weeks ago

Yes getting same issue

curl -H "content-type: application/json" -d '{ "sandbox": "go", "command": "run", "files": {"": "package main\nimport \"fmt\"\nfunc main() { fmt.Println(\"Hello, Codapi!\") }" }}'  http://localhost:1313/v1/exec

{
  "id": "go_run_3834a973",
  "ok": false,
  "duration": 475,
  "stdout": "",
  "stderr": "go: creating work dir: mkdir /tmp/go-build71566867: read-only file system (exit status 1)"
}
yuetsh commented 2 weeks ago

@52funny @studygyaan1 add "volume": "%s:/sandbox" in boxes.json image

52funny commented 2 weeks ago

@yuetsh thanks! It's working now! I added a configuration field based on you. In the configs/boxes.json:

{
    "go": {
        "image": "codapi/go",
        "writable": true,
        "volume": "%s:/sandbox:rw"
    }
}