Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move to memory db #5

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
10 changes: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,12 @@

# Go
vendor
bin
bin

# Tars
*.tar

# A directory that I made to put tests in
test-projects/
.env

4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ proto: server-proto proxy-proto
server-proto:
protoc -I/usr/local/include -I. \
-I${GOPATH}/src \
-I${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
-I${GOPATH}/pkg/mod/github.com/grpc-ecosystem/grpc-gateway@v1.12.1/third_party/googleapis \
--go_out=plugins=grpc:. \
graderpb/grader.proto

.PHONY: proxy-proto
proxy-proto:
protoc -I/usr/local/include -I. \
-I${GOPATH}/src \
-I${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
-I${GOPATH}/pkg/mod/github.com/grpc-ecosystem/grpc-gateway@v1.12.1/third_party/googleapis \
--grpc-gateway_out=logtostderr=true:. \
graderpb/grader.proto

Expand Down
56 changes: 56 additions & 0 deletions cmd/grader-cli/container.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package main

import (
"context"
"fmt"
pb "github.com/Capstone-auto-grader/grader-api-v2/graderpb"
"github.com/urfave/cli"
"io/ioutil"
)

func MakeContainer() cli.Command {
command := cli.Command{
Name: "build_container",
Description: "Given a TAR file, builds a container",
Flags: []cli.Flag{
cli.StringFlag{
Name: "file_path, f",
Usage: "file path",
},
cli.StringFlag{
Name: "container_tag, t",
Usage: "container tag",
},
},
Action: MakeContainerAction(),
}
return command
}

func MakeContainerAction() cli.ActionFunc {
return func(c *cli.Context) error {
ctx := context.Background()
addr := c.GlobalString("addr")
cert := c.GlobalString("cert")

filepath := c.String("file_path")
tag := c.String("container_tag")
fmt.Println("TAG ", tag)
tar, err := ioutil.ReadFile(filepath)
if err != nil {
return fmt.Errorf("error reading file %s: %s", filepath, err)

}
req := &pb.CreateImageRequest{
ImageName:tag,
ImageTar: tar}

client := NewClient(cert, addr)
resp, err := client.CreateImage(ctx, req)
if err != nil {
return err
}
fmt.Println(resp.String())
return nil
}
}
1 change: 1 addition & 0 deletions cmd/grader-cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func main() {
}
app.Commands = cli.Commands{
Submit(),
MakeContainer(),
}

if err := app.Run(os.Args); err != nil {
Expand Down
31 changes: 18 additions & 13 deletions cmd/grader-cli/submit.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,25 @@ func Submit() cli.Command {
Description: "submit sends an assignment to be graded to the grader API",
Flags: []cli.Flag{
cli.StringFlag{
Name: "id, i",
Usage: "assignment id",
Name: "image_name, i",
Usage: "image name",
},
cli.StringFlag{
Name: "urn, u",
Usage: "assignment urn",
Name: "submission_uri, s",
Usage: "submission s3 uri",
},
cli.StringFlag{
Name: "zipkey, z",
Usage: "zip key (s3 key)",
Name: "test_uri, k",
Usage: "test bundle s3 uri",
},
cli.StringFlag{
Name: "name, n",
Usage: "student's name",
},
cli.IntFlag{Name:"timeout, t",
Usage:"timeout",
Value: 60},

},
Action: SubmitAction(),
}
Expand All @@ -44,18 +48,19 @@ func SubmitAction() cli.ActionFunc {
addr := c.GlobalString("addr")
cert := c.GlobalString("cert")

id := c.String("id")
urn := c.String("urn")
zipkey := c.String("zipkey")
id := c.String("image_name")
subm := c.String("submission_uri")
test := c.String("test_uri")
name := c.String("name")

timeout := c.Int("timeout")
req := &pb.SubmitForGradingRequest{
Tasks: []*pb.Task{
{
AssignmentId: id,
UrnKey: urn,
ZipKey: zipkey,
ImageName: id,
TestKey: test,
ZipKey: subm,
StudentName: name,
Timeout: int32(timeout),
},
},
}
Expand Down
10 changes: 6 additions & 4 deletions cmd/graderd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ package main
import (
"context"
"flag"
"github.com/Capstone-auto-grader/grader-api-v2/internal/docker-client"
"github.com/joho/godotenv"
"log"
"net/http"
"strings"
Expand All @@ -33,7 +35,7 @@ var (
// command-line flags
grpcAddr = flag.String("GRPC_ADDR", "localhost", "gRPC server endpoint")
grpcPort = flag.String("GRPC_PORT", ":9090", "gRPC server port")
dockerAddr = flag.String("DOCKER_ADDR", "http://localhost:2376", "docker host endpoint")
dockerAddr = flag.String("DOCKER_ADDR", "tcp://localhost:2375", "docker host endpoint")
dockerVersion = flag.String("DOCKER_VERSION", "1.40", "docker host version")
databaseAddr = flag.String("DATABASE_ADDR", "localhost:3306", "database endpoint")
webAddr = flag.String("WEB_ADDR", "localhost:8080", "web API server endpoint")
Expand All @@ -54,7 +56,7 @@ func serve() error {
log.Fatalln(errors.Wrap(err, failedCertCreation))
}
grpcServer := grpc.NewServer(grpc.Creds(serverCert))
graderService := graderd.NewGraderService(graderd.NewDockerClient(*dockerAddr, *dockerVersion), graderd.NewPGDatabase(*databaseAddr), *webAddr)
graderService := graderd.NewGraderService(docker_client.NewDockerClient(*dockerAddr, *dockerVersion, 2), *webAddr)
pb.RegisterGraderServer(grpcServer, graderService)

endpoint := *grpcAddr + *grpcPort
Expand All @@ -75,7 +77,7 @@ func serve() error {
if err = pb.RegisterGraderHandler(context.Background(), router, conn); err != nil {
log.Fatalln(errors.Wrap(err, failedRegisterGateway))
}

log.Println("Serving")
return http.ListenAndServeTLS(*grpcPort, *certFile, *keyFile, grpcHandlerFunc(grpcServer, router))
}

Expand All @@ -93,7 +95,7 @@ func grpcHandlerFunc(grpcHandler *grpc.Server, httpHandler http.Handler) http.Ha

func main() {
flag.Parse()

_ = godotenv.Load()
if err := serve(); err != nil {
log.Fatal(err)
}
Expand Down
59 changes: 59 additions & 0 deletions cmd/testbed/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package main
import (
"fmt"
"io/ioutil"
"os"
"io"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/pkg/stdcopy"
"github.com/docker/docker/client"
"golang.org/x/net/context"
)

func main() {
ctx := context.Background()
cli, err := client.NewClientWithOpts(client.FromEnv)
if err != nil {
panic(err)
}

reader, err := cli.ImagePull(ctx, "docker.io/library/alpine", types.ImagePullOptions{})
if err != nil {
panic(err)
}
io.Copy(os.Stdout, reader)

resp, err := cli.ContainerCreate(ctx, &container.Config{
Image: "alpine",
Cmd: []string{"echo", "hello world"},
Tty: true,
}, nil, nil, "")
if err != nil {
panic(err)
}

if err := cli.ContainerStart(ctx, resp.ID, types.ContainerStartOptions{}); err != nil {
panic(err)
}

statusCh, errCh := cli.ContainerWait(ctx, resp.ID, container.WaitConditionNotRunning)
select {
case err := <-errCh:
if err != nil {
panic(err)
}
case <-statusCh:
}

out, err := cli.ContainerLogs(ctx, resp.ID, types.ContainerLogsOptions{ShowStdout: true})
if err != nil {
panic(err)
}
bytes, err := ioutil.ReadAll(out)
fmt.Println(string(bytes))

_,err = stdcopy.StdCopy(os.Stdout, os.Stderr, out)

}

49 changes: 23 additions & 26 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,39 @@ module github.com/Capstone-auto-grader/grader-api-v2

go 1.12

// Put here as per https://github.com/moby/moby/issues/37683, which is an IDIOTIC fix
replace github.com/docker/docker v1.13.2-0.20170601211448-f5ec1e2936dc => github.com/docker/engine v1.4.2-0.20180718150940-a3ef7e9a9bda

require (
cloud.google.com/go v0.47.0 // indirect
cloud.google.com/go/bigquery v1.1.0 // indirect
cloud.google.com/go/storage v1.1.1 // indirect
github.com/creack/pty v1.1.9 // indirect
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 // indirect
github.com/Microsoft/go-winio v0.4.14 // indirect
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 // indirect
github.com/docker/distribution v2.7.1+incompatible // indirect
github.com/docker/docker v1.13.1
github.com/docker/docker v1.13.2-0.20170601211448-f5ec1e2936dc
github.com/docker/engine v1.4.2-0.20190822205725-ed20165a37b4
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.4.0 // indirect
github.com/golang/groupcache v0.0.0-20191002201903-404acd9df4cc // indirect
github.com/gogo/protobuf v1.3.1 // indirect
github.com/golang/protobuf v1.3.2
github.com/google/go-cmp v0.3.1 // indirect
github.com/google/pprof v0.0.0-20191016141926-35da2c455f8f // indirect
github.com/grpc-ecosystem/grpc-gateway v1.11.3
github.com/hashicorp/golang-lru v0.5.3 // indirect
github.com/jstemmer/go-junit-report v0.9.1 // indirect
github.com/kr/pty v1.1.8 // indirect
github.com/gorilla/mux v1.7.3 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.12.1
github.com/joho/godotenv v1.3.0
github.com/kr/pretty v0.1.0 // indirect
github.com/opencontainers/go-digest v1.0.0-rc1 // indirect
github.com/opencontainers/image-spec v1.0.1 // indirect
github.com/pkg/errors v0.8.1
github.com/rogpeppe/fastuuid v1.2.0 // indirect
github.com/rogpeppe/go-internal v1.5.0 // indirect
github.com/urfave/cli v1.22.1 // indirect
go.opencensus.io v0.22.1 // indirect
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 // indirect
golang.org/x/exp v0.0.0-20191014171548-69215a2ee97e // indirect
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8 // indirect
golang.org/x/mobile v0.0.0-20191002175909-6d0d39b2ca82 // indirect
golang.org/x/net v0.0.0-20191021144547-ec77196f6094 // indirect
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e // indirect
github.com/sirupsen/logrus v1.4.2 // indirect
github.com/stretchr/testify v1.4.0 // indirect
github.com/urfave/cli v1.22.1
golang.org/x/net v0.0.0-20191021144547-ec77196f6094
golang.org/x/sys v0.0.0-20191020212454-3e7259c5e7c2 // indirect
golang.org/x/text v0.3.2 // indirect
golang.org/x/time v0.0.0-20190921001708-c4c64cad1fd0 // indirect
golang.org/x/tools v0.0.0-20191018212557-ed542cd5b28a // indirect
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898 // indirect
google.golang.org/appengine v1.6.5 // indirect
google.golang.org/genproto v0.0.0-20191009194640-548a555dbc03
google.golang.org/genproto v0.0.0-20191230161307-f3c370f40bfb
google.golang.org/grpc v1.24.0
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
gopkg.in/yaml.v2 v2.2.4 // indirect
gopkg.in/yaml.v2 v2.2.7 // indirect
gotest.tools v2.2.0+incompatible // indirect

)
Loading