From bc6b3736593c24936e77520fc3db98abb294f445 Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Thu, 20 Sep 2018 00:18:04 +0000 Subject: [PATCH] Dockerize and cleanup --- Dockerfile.moth | 20 ++++++---------- src/maintenance.go | 4 ++-- src/mothd.go | 2 +- src/static.go | 58 ++++++++++++++++++++++++++++++++++++++++++---- 4 files changed, 64 insertions(+), 20 deletions(-) diff --git a/Dockerfile.moth b/Dockerfile.moth index 0e8b7e9..43e55e1 100644 --- a/Dockerfile.moth +++ b/Dockerfile.moth @@ -1,14 +1,8 @@ -FROM neale/eris - -RUN apk --no-cache add lua5.1 lua5.2 lua5.3 -RUN ln -s lua5.2 /usr/bin/lua - -# Install MOTH. This could be less obtuse. -COPY www /moth/www/ -COPY bin /moth/bin/ -COPY src/moth-init /moth/init -RUN ln -s ../state/puzzles.json /moth/www/puzzles.json && \ - ln -s ../state/points.json /moth/www/points.json - -CMD ["/moth/init"] +FROM alpine AS builder +RUN apk --no-cache add go libc-dev +COPY src /src +RUN go build -o /mothd /src/*.go +FROM alpine +COPY --from=builder /mothd /mothd +ENTRYPOINT [ "/mothd" ] diff --git a/src/maintenance.go b/src/maintenance.go index fa7b0cd..77a282a 100644 --- a/src/maintenance.go +++ b/src/maintenance.go @@ -125,9 +125,9 @@ func (ctx *Instance) Maintenance(maintenanceInterval time.Duration) { ctx.Tidy() select { case <-ctx.update: - log.Print("Forced update") + // log.Print("Forced update") case <-time.After(maintenanceInterval): - log.Print("Housekeeping...") + // log.Print("Housekeeping...") } } } diff --git a/src/mothd.go b/src/mothd.go index c61af99..790bbf4 100644 --- a/src/mothd.go +++ b/src/mothd.go @@ -47,7 +47,7 @@ func main() { ) listen := flag.String( "listen", - ":80", + ":8000", "[host]:port to bind and listen", ) flag.Parse() diff --git a/src/static.go b/src/static.go index c13a0c9..f7adbdd 100644 --- a/src/static.go +++ b/src/static.go @@ -289,7 +289,7 @@ document.addEventListener("DOMContentLoaded", init); ) } -func staticPuzzles(w http.ResponseWriter) { +func staticPuzzleList(w http.ResponseWriter) { ShowHtml( w, Success, "Open Puzzles", @@ -328,12 +328,12 @@ function render(obj) { l.appendChild(i); if (points === 0) { - i.textContent = "‡"; + i.textContent = "✿"; } else { var a = document.createElement('a'); i.appendChild(a); a.textContent = points; - a.href = cat + "/" + id + "/index.html"; + a.href = "puzzle.html?cat=" + cat + "&points=" + points + "&pid=" + id; } } @@ -359,6 +359,54 @@ document.addEventListener("DOMContentLoaded", init); ) } +func staticPuzzle(w http.ResponseWriter) { + ShowHtml( + w, Success, + "Open Puzzles", + ` +
+
Loading...
+
+
+ + + Team ID:
+ Answer:
+ +
+ + `, + ) +} + func tryServeFile(w http.ResponseWriter, req *http.Request, path string) bool { f, err := os.Open(path) if err != nil { @@ -398,7 +446,9 @@ func ServeStatic(w http.ResponseWriter, req *http.Request, resourcesDir string) case "/scoreboard.html": staticScoreboard(w) case "/puzzle-list.html": - staticPuzzles(w) + staticPuzzleList(w) + case "/puzzle.html": + staticPuzzle(w) default: http.NotFound(w, req) }