mirror of https://github.com/dirtbags/moth.git
Dockerize and cleanup
This commit is contained in:
parent
7ff206cbda
commit
bc6b373659
|
@ -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" ]
|
||||
|
|
|
@ -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...")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ func main() {
|
|||
)
|
||||
listen := flag.String(
|
||||
"listen",
|
||||
":80",
|
||||
":8000",
|
||||
"[host]:port to bind and listen",
|
||||
)
|
||||
flag.Parse()
|
||||
|
|
|
@ -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",
|
||||
`
|
||||
<section>
|
||||
<div id="body">Loading...</div>
|
||||
</section>
|
||||
<form action="answer" method="post">
|
||||
<input type="hidden" name="cat">
|
||||
<input type="hidden" name="points">
|
||||
Team ID: <input type="text" name="id"> <br>
|
||||
Answer: <input type="text" name="answer"> <br>
|
||||
<input type="submit" value="Submit">
|
||||
</form>
|
||||
<script>
|
||||
function render(obj) {
|
||||
let body = document.getElementById("body");
|
||||
body.innerHTML = obj.body;
|
||||
console.log("XXX: Munge relative URLs (src= and href=) in body")
|
||||
}
|
||||
function init() {
|
||||
let params = new URLSearchParams(window.location.search);
|
||||
let categoryName = params.get("cat");
|
||||
let points = params.get("points");
|
||||
let puzzleId = params.get("pid");
|
||||
|
||||
let fn = "content/" + categoryName + "/" + puzzleId + "/puzzle.json";
|
||||
|
||||
fetch(fn)
|
||||
.then(function(resp) {
|
||||
return resp.json();
|
||||
}).then(function(obj) {
|
||||
render(obj);
|
||||
}).catch(function(err) {
|
||||
console.log("Error", err);
|
||||
});
|
||||
|
||||
document.querySelector("body > h1").innerText = categoryName + " " + points
|
||||
document.querySelector("input[name=cat]").value = categoryName;
|
||||
document.querySelector("input[name=points]").value = points;
|
||||
}
|
||||
document.addEventListener("DOMContentLoaded", init);
|
||||
</script>
|
||||
`,
|
||||
)
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue