diff --git a/Caddyfile.example b/Caddyfile.example new file mode 100644 index 0000000000000..d899cf0fca0d3 --- /dev/null +++ b/Caddyfile.example @@ -0,0 +1,4 @@ +readme-stats.example.com { + reverse_proxy readme_stats:9000 +} + diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000000..1b1458fec2f01 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +FROM node:lts-alpine + +# setup folder within the docker container with this app's files +WORKDIR /app +COPY . . + +# add express.js as dependency and download node modules +RUN npm install express.js + +# start the app, on the supplied port +EXPOSE $port +CMD [ "node", "express.js" ] + diff --git a/docker-compose.yml.example b/docker-compose.yml.example new file mode 100644 index 0000000000000..f49c1cba1925f --- /dev/null +++ b/docker-compose.yml.example @@ -0,0 +1,22 @@ +services: + readme_stats: + build: . + container_name: readme_stats + restart: unless-stopped + env_file: + - .env + expose: + - $port + + caddy: + image: caddy + restart: unless-stopped + ports: + - "80:80" + - "443:443" + - "443:443/udp" + depends_on: + - readme_stats + volumes: + - ./Caddyfile:/etc/caddy/Caddyfile:ro + diff --git a/env.example b/env.example new file mode 100644 index 0000000000000..849d93dc7b1e2 --- /dev/null +++ b/env.example @@ -0,0 +1,5 @@ +# github token +PAT_1= +# port to listen on +port=9000 + diff --git a/express.js b/express.js index 92a7fb1673908..65de51bc842f5 100644 --- a/express.js +++ b/express.js @@ -18,6 +18,14 @@ router.get("/gist", gistCard); app.use("/api", router); const port = process.env.PORT || process.env.port || 9000; -app.listen(port, "0.0.0.0", () => { +const server = app.listen(port, "0.0.0.0", () => { console.log(`Server running on port ${port}`); }); + +/* stop gracefully when requested */ +process.on("SIGTERM", () => { + console.log("stopping, received SIGTERM signal"); + server.close(() => { + process.exit(); + }); +}); diff --git a/readme-docker.md b/readme-docker.md new file mode 100644 index 0000000000000..5a792bcb95855 --- /dev/null +++ b/readme-docker.md @@ -0,0 +1,35 @@ +Get dynamically generated GitHub stats on your READMEs, with the ease of docker! + +Fork of [https://github.com/anuraghazra/github-readme-stats](https://github.com/anuraghazra/github-readme-stats), gently wrapped in docker. + +**Steps to setup:** +* clone this repo into a folder. +* copy docker-compose.yml.example to docker-compose.yml. +* copy env.example to .env and update. +* copy Caddyfile.example to Caddyfile and update. +* and start with `docker compose up -d`. + +docker-compose.yml.example has a very simple Caddy reverse proxy, for automatic https. + +Files have example in their name, so that when you update, your local settings won't be overridden. + +``` +git clone https://code.digitaladapt.com/andrew/github-readme-stats.git +cd github-readme-stats +cp docker-compose.yml.example docker-compose.yml +cp env.example .env +vim .env +# add your github token + +cp Caddyfile.example Caddyfile +vim Caddyfile +# configure your domain + +docker compose up -d +``` + +You might ask, why should I trust your docker image? + +The answer is, you don't have to, there isn't an image, +just a few commands in the Dockerfile, which you can and should look at. +