Skip to content
This repository was archived by the owner on Aug 11, 2021. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[[source]]
Comment thread
hariamoor-zz marked this conversation as resolved.
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]
python-language-server = {extras = ["all"],version = "*"}

[packages]

[requires]
python_version = "3.8"
195 changes: 195 additions & 0 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file added __init__.py
Empty file.
28 changes: 0 additions & 28 deletions sandbox.py

This file was deleted.

Empty file added sandboxes/__init__.py
Empty file.
8 changes: 8 additions & 0 deletions sandboxes/docker_files/Dockerfile.go
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', '.']
4 changes: 4 additions & 0 deletions sandboxes/docker_files/Dockerfile.py
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"]
Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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?

Copy link
Copy Markdown
Collaborator Author

@hariamoor-zz hariamoor-zz May 30, 2020

Choose a reason for hiding this comment

The 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.

Empty file.
Empty file.
9 changes: 9 additions & 0 deletions sandboxes/docker_files/tests/test_go/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package main


import "fmt"


func main() {
fmt.Println("Hello World!")
}
20 changes: 20 additions & 0 deletions sandboxes/docker_files/tests/test_sandbox.py
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,
Comment thread
hariamoor-zz marked this conversation as resolved.
language="golang",
project_root=abspath(join(d_name, "test_go_sample")))

assert box.parse() == "Hello World!\n"
29 changes: 29 additions & 0 deletions sandboxes/sandbox.py
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:
Comment thread
hariamoor-zz marked this conversation as resolved.
Comment thread
hariamoor-zz marked this conversation as resolved.
SCHEMA = {
"python": "docker_files/Dockerfile.py",
"golang": "docker_files/Dockerfile.go",
}

Comment thread
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
Comment thread
hariamoor-zz marked this conversation as resolved.
Outdated

def parse(self) -> str:
df_path = abspath(
Comment thread
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()
Comment thread
hariamoor-zz marked this conversation as resolved.
Outdated
Comment thread
hariamoor-zz marked this conversation as resolved.
Outdated
4 changes: 0 additions & 4 deletions tests/test_sandbox.py

This file was deleted.