multi piston in progress
This commit is contained in:
parent
2934f8939b
commit
08d8329d3d
27
api/main.go
27
api/main.go
|
@ -6,8 +6,10 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -27,10 +29,24 @@ type outbound struct {
|
||||||
Output string `json:"output"`
|
Output string `json:"output"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
var instance int
|
||||||
http.HandleFunc("/execute", Execute)
|
|
||||||
|
|
||||||
http.ListenAndServe("0.0.0.0:1337", nil)
|
func main() {
|
||||||
|
port := 2000
|
||||||
|
|
||||||
|
if len(os.Args) > 1 {
|
||||||
|
if i, err := strconv.Atoi(os.Args[1]); err == nil {
|
||||||
|
instance = i
|
||||||
|
port += i
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
instance = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("starting api on port", port)
|
||||||
|
|
||||||
|
http.HandleFunc("/execute", Execute)
|
||||||
|
http.ListenAndServe(fmt.Sprintf("0.0.0.0:%d", port), nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Execute(res http.ResponseWriter, req *http.Request) {
|
func Execute(res http.ResponseWriter, req *http.Request) {
|
||||||
|
@ -93,6 +109,11 @@ func launch(request inbound, res http.ResponseWriter) {
|
||||||
|
|
||||||
// set up the execution
|
// set up the execution
|
||||||
cmd := exec.Command("../docker/execute", args...)
|
cmd := exec.Command("../docker/execute", args...)
|
||||||
|
cmd.Env = os.Environ()
|
||||||
|
|
||||||
|
if instance > 0 {
|
||||||
|
cmd.Env = append(cmd.Env, fmt.Sprintf("SOCKET=unix:///var/run/docker-%d.sock", instance))
|
||||||
|
}
|
||||||
|
|
||||||
// capture out/err
|
// capture out/err
|
||||||
var stdout, stderr bytes.Buffer
|
var stdout, stderr bytes.Buffer
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
go run main.go
|
go run main.go $*
|
||||||
|
|
|
@ -16,6 +16,7 @@ filepath=$(realpath $2)
|
||||||
file=$(basename $2)
|
file=$(basename $2)
|
||||||
argpath="/tmp/$(date +%s%N).args"
|
argpath="/tmp/$(date +%s%N).args"
|
||||||
arg=$(basename $argpath)
|
arg=$(basename $argpath)
|
||||||
|
socket=${SOCKET:-unix:///var/run/docker.sock}
|
||||||
|
|
||||||
# write arg file
|
# write arg file
|
||||||
echo "${@:3}" > $argpath
|
echo "${@:3}" > $argpath
|
||||||
|
@ -63,7 +64,9 @@ case "$lang" in
|
||||||
exit
|
exit
|
||||||
esac
|
esac
|
||||||
|
|
||||||
docker run \
|
docker \
|
||||||
|
-H $socket \
|
||||||
|
run \
|
||||||
-m 64m \
|
-m 64m \
|
||||||
--network none \
|
--network none \
|
||||||
--rm \
|
--rm \
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
console.log('hi')
|
|
@ -0,0 +1,45 @@
|
||||||
|
[Unit]
|
||||||
|
Description=Docker Application Container Engine
|
||||||
|
Documentation=http://docs.docker.com
|
||||||
|
After=network.target
|
||||||
|
Wants=docker-storage-setup.service
|
||||||
|
Requires=docker-cleanup.timer
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=notify
|
||||||
|
NotifyAccess=main
|
||||||
|
EnvironmentFile=-/run/containers/registries.conf
|
||||||
|
EnvironmentFile=-/etc/sysconfig/docker
|
||||||
|
EnvironmentFile=-/etc/sysconfig/docker-storage
|
||||||
|
EnvironmentFile=-/etc/sysconfig/docker-network
|
||||||
|
Environment=GOTRACEBACK=crash
|
||||||
|
Environment=DOCKER_HTTP_HOST_COMPAT=1
|
||||||
|
Environment=PATH=/usr/libexec/docker:/usr/bin:/usr/sbin
|
||||||
|
ExecStart=/usr/bin/dockerd-current \
|
||||||
|
--add-runtime docker-runc=/usr/libexec/docker/docker-runc-current \
|
||||||
|
--default-runtime=docker-runc \
|
||||||
|
--exec-opt native.cgroupdriver=systemd \
|
||||||
|
--userland-proxy-path=/usr/libexec/docker/docker-proxy-current \
|
||||||
|
--init-path=/usr/libexec/docker/docker-init-current \
|
||||||
|
--seccomp-profile=/etc/docker/seccomp.json \
|
||||||
|
--exec-root=/var/run/docker-%i \
|
||||||
|
--graph=/var/lib/docker-%i \
|
||||||
|
--host unix:///var/run/docker-%i.sock \
|
||||||
|
--pidfile /var/run/docker-%i.pid \
|
||||||
|
$OPTIONS \
|
||||||
|
$DOCKER_STORAGE_OPTIONS \
|
||||||
|
$DOCKER_NETWORK_OPTIONS \
|
||||||
|
$ADD_REGISTRY \
|
||||||
|
$BLOCK_REGISTRY \
|
||||||
|
$INSECURE_REGISTRY \
|
||||||
|
$REGISTRIES
|
||||||
|
ExecReload=/bin/kill -s HUP $MAINPID
|
||||||
|
LimitNOFILE=1048576
|
||||||
|
LimitNPROC=1048576
|
||||||
|
LimitCORE=infinity
|
||||||
|
TimeoutStartSec=0
|
||||||
|
Restart=on-abnormal
|
||||||
|
KillMode=process
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
|
@ -0,0 +1,3 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
docker -H unix:///var/run/docker-$1.sock ${@:2}
|
|
@ -1,12 +1,12 @@
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=Piston
|
Description=Piston API
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=simple
|
Type=simple
|
||||||
User=root
|
User=root
|
||||||
Environment=PATH=/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
|
Environment=PATH=/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
|
||||||
WorkingDirectory=/root/piston/api
|
WorkingDirectory=/root/piston/api
|
||||||
ExecStart=/root/piston/api/start
|
ExecStart=/root/piston/api/start %i
|
||||||
Restart=on-failure
|
Restart=on-failure
|
||||||
|
|
||||||
[Install]
|
[Install]
|
Loading…
Reference in New Issue