#!/usr/bin/env -S bash -c "docker run -p 8080:8080 -it --rm \$(docker build --progress plain -f \$0 . 2>&1 | tee /dev/stderr | grep -oP 'sha256:[0-9a-f]*')" # syntax = docker/dockerfile:1.4.0 FROM node:20 WORKDIR /root RUN npm install sqlite3 RUN </root/schema.sql CREATE TABLE IF NOT EXISTS clicks ( id INTEGER PRIMARY KEY AUTOINCREMENT, time INTEGER NOT NULL ); EOF RUN </root/server.js const fs = require("fs"); const http = require("http"); const sqlite3 = require("sqlite3"); const db = new sqlite3.Database(":memory:"); db.run(fs.readFileSync("/root/schema.sql", "utf8")); const html = fs.readFileSync("/root/index.html", "utf8"); const server = http.createServer((req, res) => { db.run("INSERT INTO clicks(time) VALUES(unixepoch())"); const data = []; db.each( "SELECT time as t, COUNT(*) as n FROM clicks WHERE t > unixepoch()-4*60*60 GROUP BY t-t%60", (_, { t, n }) => data.push([Math.floor(t/60), n]), () => { res.writeHead(200, { "content-type": "text/html" }); res.end(html.replace("__DATA__", JSON.stringify(data))); }, ); }); server.listen(8080, "", () => console.log("serving :8080...")); EOF RUN </root/index.html #!/usr/bin/env docker run
Page loads over time (last 4 hours) 0 EOF CMD node /root/server.js