-
Notifications
You must be signed in to change notification settings - Fork 0
[WIP] Core Sandbox Logic #1
base: master
Are you sure you want to change the base?
Changes from 3 commits
899aab0
216edf6
4f9a15e
f449fe8
0a02737
12abeac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| [[source]] | ||
| name = "pypi" | ||
| url = "https://pypi.org/simple" | ||
| verify_ssl = true | ||
|
|
||
| [dev-packages] | ||
| python-language-server = {extras = ["all"],version = "*"} | ||
|
|
||
| [packages] | ||
|
|
||
| [requires] | ||
| python_version = "3.8" | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| ARG PROJECT_ROOT | ||
|
|
||
| FROM golang:latest | ||
| ADD ${PROJECT_ROOT} . | ||
|
|
||
| RUN go build -o app | ||
| ENTRYPOINT app | ||
| # CMD ['go', 'run', '.'] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| FROM python:latest | ||
| COPY $PROJECT_ROOT . | ||
| RUN pip install . | ||
| CMD ["python", "-m", "unittest"] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure about why this is just running tests vs. running an app like above?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Dockerfiles aren't stable yet - that's why this is still WIP. They'll become much more fancy down the line once we get venue for testing. This will be resolved at merge-time. Edit: Leaving this unresolved so I remember. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package main | ||
|
|
||
|
|
||
| import "fmt" | ||
|
|
||
|
|
||
| func main() { | ||
| fmt.Println("Hello World!") | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import docker | ||
| import pytest | ||
|
|
||
| from os.path import abspath, dirname, join | ||
|
|
||
| from sandbox import Sandbox | ||
|
|
||
|
|
||
| class TestSandbox: | ||
| @pytest.fixture(scope="module") | ||
| def client(self) -> docker.APIClient: | ||
| return docker.DockerClient(base_url="unix:///var/run/docker.sock") | ||
|
|
||
| def test_go_sample(self, client): | ||
| d_name = dirname(__file__) | ||
| box = Sandbox(client=client, | ||
|
hariamoor-zz marked this conversation as resolved.
|
||
| language="golang", | ||
| project_root=abspath(join(d_name, "test_go_sample"))) | ||
|
|
||
| assert box.parse() == "Hello World!\n" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import docker | ||
| import rootpath | ||
|
|
||
| from os.path import abspath, join | ||
|
|
||
|
|
||
| class Sandbox: | ||
|
hariamoor-zz marked this conversation as resolved.
hariamoor-zz marked this conversation as resolved.
|
||
| SCHEMA = { | ||
| "python": "docker_files/Dockerfile.py", | ||
| "golang": "docker_files/Dockerfile.go", | ||
| } | ||
|
|
||
|
Sail338 marked this conversation as resolved.
Outdated
|
||
| def __init__(self, client: docker.APIClient, language: str, | ||
| project_root: str): | ||
| self.client = client | ||
| self.language = language | ||
| self.project_root = project_root | ||
|
hariamoor-zz marked this conversation as resolved.
Outdated
|
||
|
|
||
| def parse(self) -> str: | ||
| df_path = abspath( | ||
|
hariamoor-zz marked this conversation as resolved.
Outdated
|
||
| join(rootpath.detect(), Sandbox.SCHEMA[self.language])) | ||
|
|
||
| with open(df_path, "r") as df: | ||
| image = self.client.images.build( | ||
| fileobj=df, | ||
| custom_context=True, | ||
| buildargs={"PROJECT_ROOT": self.project_root}) | ||
|
|
||
| return self.client.containers.run(image).attach() | ||
|
hariamoor-zz marked this conversation as resolved.
Outdated
hariamoor-zz marked this conversation as resolved.
Outdated
|
||
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.