Skip to content

Commit

Permalink
wrote memorycell Dockerfile, memorycell server, create container
Browse files Browse the repository at this point in the history
Git issue references:

Gamelan music currently playing: Gendhing Prabu Mataram

Co-authored-by: c <[email protected]>
Co-authored-by: Mouse Reeve <[email protected]>
  • Loading branch information
3 people committed Mar 22, 2018
1 parent 6c23c8b commit 4a81098
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 3 deletions.
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM golang:1.9-alpine as memorycell

WORKDIR /go/src/github.com/connorwalsh/dockerlang
COPY . .
# no need to go get since we are vendoring all our deps
RUN cd ./memorycell && ls && go build

FROM alpine

WORKDIR /usr/bin
COPY --from=memorycell /go/src/github.com/connorwalsh/dockerlang/memorycell/memorycell .

CMD ["/usr/bin/memorycell"]
38 changes: 37 additions & 1 deletion execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,20 @@ import (
"os"

"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/network"
"github.com/docker/docker/client"
"github.com/docker/go-connections/nat"
uuid "github.com/satori/go.uuid"
)

const (
MEMORY_PORT = "6666"

COMPUTATION_TYPE_ENV_VAR = "COMPUTATION_TYPE_ENV_VAR"
COMPUTATION_VALUE_ENV_VAR = "COMPUTATION_VALUE_ENV_VAR"
)

var (
executer *ExecutionEngine
)
Expand All @@ -21,7 +31,9 @@ type ExecutionEngine struct {
}

type ExecutionData struct {
Operands []DLCI
ComputationType string
Value string
Operands []DLCI
}

// constructs an ExecutionEngine and binds to the globally scoped executer.
Expand Down Expand Up @@ -80,5 +92,29 @@ func (e *ExecutionEngine) Run(d *ExecutionData) (DLCI, error) {

// pass data structure needed to compute

// create a DLCI (finally)
dlci := "cool"

e.Docker.ContainerCreate(
context.TODO(),
&container.Config{
ExposedPorts: nat.PortSet{MEMORY_PORT: struct{}{}},
Image: "dockerlang",
Env: []string{
fmt.Sprintf("%s=%s", COMPUTATION_TYPE_ENV_VAR, d.ComputationType),
fmt.Sprintf("%s=%s", COMPUTATION_VALUE_ENV_VAR, d.Value),
},
},
nil,
&network.NetworkingConfig{
EndpointsConfig: map[string]*network.EndpointSettings{
e.Network: &network.EndpointSettings{
NetworkID: e.Network,
},
},
},
dlci,
)

return "", nil
}
4 changes: 2 additions & 2 deletions forest.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ func (b *BaseAST) Eval() (DLCI, error) {
}

// we've computed all dependencies, now lets eval this thang
literal, err := b.Execute()
dlci, err := b.Execute()
if err != nil {
return "", err
}

return literal, nil
return dlci, nil
}

type Expr struct {
Expand Down
43 changes: 43 additions & 0 deletions memorycell/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package main

import (
"fmt"
"log"
"net/http"
"os"

"github.com/connorwalsh/dockerlang"
)

var (
COMPUTATION_TYPE string
COMPUTATION_VALUE string
)

func main() {

// get the computation type and value
COMPUTATION_TYPE = os.Getenv(dockerlang.COMPUTATION_TYPE_ENV_VAR)
COMPUTATION_VALUE = os.Getenv(dockerlang.COMPUTATION_VALUE_ENV_VAR)

http.HandleFunc("/", ExecHandler)
http.HandleFunc("/kill", KillHandler)

fmt.Printf(
"Dockerlang Memory Ready for Use (%s %s)...\n",
COMPUTATION_TYPE,
COMPUTATION_VALUE,
)
log.Fatal(http.ListenAndServe(
fmt.Sprintf(":%s", dockerlang.MEMORY_PORT),
nil,
))
}

func ExecHandler(w http.ResponseWriter, r *http.Request) {
fmt.Println("EXEC SOMETHING")
}

func KillHandler(w http.ResponseWriter, r *http.Request) {
fmt.Println("KILL ME")
}
Binary file added memorycell/memorycell
Binary file not shown.

0 comments on commit 4a81098

Please sign in to comment.