aboutsummaryrefslogtreecommitdiffstats
path: root/README.md
blob: e89d4411fc196349ceb84e3ab8f283d9f205258c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# snekbox
Python sandbox runners for executing code in isolation aka snekbox

The user sends a piece of python code to a snekbox, the snekbox executes the code and sends the result back to the users.

```
user ->
        website ->
        <-      websocket ->
                <-      webserver ->
                        <-      rabbitmq ->
                                <-      snekbox ->
                                        <-      <executes python code>

```


# Dependencies

| dep            | version (or greater) |
|----------------|:---------------------|
| python         | 3.6.5                |
| pip            | 10.0.1               |
| pipenv         | 2018.05.18           |
| docker         | 18.03.1-ce           |
| docker-compose | 1.21.2               |

## Setup local test

install python packages

```bash
pipenv sync --dev
```

Start a rabbitmq instance and get the container IP

```bash
docker run --name rmq -d rabbitmq:3.7.5-alpine
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' rmq
# expected output with default setting: 172.17.0.2
# If not, change the snekbox/config.py file to match
```

start the webserver

```bash
docker run --name snekboxweb --network=host -d pythondiscord/snekboxweb:latest
netstat -plnt
# tcp    0.0.0.0:5000    LISTEN
```

## Test the code

use two terminals!

```bash
#terminal 1
pipenv run python snekbox.py

#terminal 2
pipenv run python snekweb.py
```

`http://localhost:5000`

## Build and run the consumer in a container

```bash
docker build -t pythondiscord/snekbox:latest -f docker/Dockerfile .

#terminal 1
docker run --name snekbox -d pythondiscord/snekbox:latest
docker logs snekbox -f

#terminal 2
pipenv run python snekbox/publish.py
```

## Docker compose

Start all the containers with docker-compose

```bash
docker-compose up
```

this boots up rabbitmq, the snekbox and a webinterface on port 5000

`http://localhost:5000`