Skip to content

Commit a9b0877

Browse files
dev20210630
1 parent 2f9aa71 commit a9b0877

File tree

14 files changed

+144
-24
lines changed

14 files changed

+144
-24
lines changed

Dockerfile

Lines changed: 0 additions & 22 deletions
This file was deleted.

backend/Dockerfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM ubuntu:21.04
2+
3+
RUN apt-get update
4+
RUN apt-get -y upgrade
5+
6+
RUN apt-get -y install build-essential curl golang ca-certificates docker.io
7+
8+
RUN update-ca-certificates
9+
10+
WORKDIR /code-grader
11+
COPY . .
12+
13+
EXPOSE 8080
14+
ENV GIN_MODE=release
15+
16+
ENTRYPOINT [ "/code-grader/backend/backend" ]

backend/cmd/CompileUserCode.go renamed to backend/cmd/compile_user_code.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
)
1515

1616
const CompilationMemoryLimit = 50 * 1024 * 1024
17-
const imageName = "runtime-compile:latest"
17+
const imageName = "markhuang1212/code-grader/runtime-compile"
1818

1919
var InternalError = errors.New("internal error")
2020
var CompilationFailure = errors.New("compilation error")
File renamed without changes.
File renamed without changes.

backend/cmd/setup_router.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package cmd
2+
3+
import (
4+
"net/http"
5+
6+
"github.com/gin-gonic/gin"
7+
)
8+
9+
func SetupRouter() *gin.Engine {
10+
r := gin.Default()
11+
r.GET("/ping", func(c *gin.Context) {
12+
c.String(http.StatusOK, "pong")
13+
})
14+
15+
return r
16+
}

backend/cmd/setup_router_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package cmd_test
2+
3+
import (
4+
"net/http"
5+
"net/http/httptest"
6+
"testing"
7+
8+
"github.com/markhuang1212/code-grader/backend/cmd"
9+
"github.com/stretchr/testify/assert"
10+
)
11+
12+
func TestPingRoute(t *testing.T) {
13+
router := cmd.SetupRouter()
14+
15+
w := httptest.NewRecorder()
16+
req, _ := http.NewRequest("GET", "/ping", nil)
17+
router.ServeHTTP(w, req)
18+
19+
assert.Equal(t, http.StatusOK, w.Code)
20+
assert.Equal(t, "pong", w.Body.String())
21+
}

backend/main.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package main
22

3-
func main() {
3+
import (
4+
"github.com/markhuang1212/code-grader/backend/cmd"
5+
)
46

7+
func main() {
8+
r := cmd.SetupRouter()
9+
r.Run(":8080")
510
}

docker-compose.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
version: "3.9"
2+
services:
3+
backend:
4+
build:
5+
context: .
6+
dockerfile: backend/Dockerfile
7+
image: markhuang1212/code-grader/backend
8+
ports:
9+
- "8080:8080"
10+
- "8443:8443"
11+
volumes:
12+
- /var/run/docker.sock:/var/run/docker.sock
13+
deploy:
14+
resources:
15+
limits:
16+
memory: 4G
17+
cpus: '1.0'
18+
restart_policy:
19+
condition: on-failure
20+
delay: 5s
21+
max_attempts: 3
22+
window: 120s
23+
runtime-compile:
24+
build:
25+
context: .
26+
dockerfile: runtime-compile/Dockerfile
27+
image: markhuang1212/code-grader/runtime-compile
28+
entrypoint: ["/usr/bin/true"]
29+
runtime-exec:
30+
build:
31+
context: .
32+
dockerfile: runtime-exec/Dockerfile
33+
image: markhuang1212/code-grader/runtime-exec
34+
entrypoint: ["/usr/bin/true"]

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ require (
66
github.com/containerd/containerd v1.5.2 // indirect
77
github.com/docker/docker v20.10.7+incompatible // indirect
88
github.com/docker/go-connections v0.4.0 // indirect
9+
github.com/gin-gonic/gin v1.7.2 // indirect
910
github.com/pkg/errors v0.9.1 // indirect
1011
github.com/sirupsen/logrus v1.8.1 // indirect
12+
github.com/stretchr/testify v1.7.0 // indirect
1113
google.golang.org/grpc v1.38.0 // indirect
1214
)

0 commit comments

Comments
 (0)