From e67199a30dad5660a4cb0650ba6f55699225fb5d Mon Sep 17 00:00:00 2001 From: Nircek Date: Tue, 5 Jan 2021 18:16:20 +0100 Subject: [PATCH 1/3] Add Dockerfile with interrupting system --- Dockerfile | 9 +++++++++ run.sh | 16 ++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 Dockerfile create mode 100755 run.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..3fc24ebf --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM hayd/alpine-deno:1.6.2 +EXPOSE 8000 +WORKDIR /app +USER deno +COPY deps.ts . +RUN deno cache deps.ts +ADD . . +RUN deno cache server.ts # --unstable? +CMD ["./run.sh"] diff --git a/run.sh b/run.sh new file mode 100755 index 00000000..9c904577 --- /dev/null +++ b/run.sh @@ -0,0 +1,16 @@ +#!/bin/sh +trap interrupt TERM INT +interrupt () { + echo "Interrupting with SIGINT and waiting 5s... " + kill $pid + timeout 5 sh -c "while kill -0 $pid &>/dev/null; do :; done" + exit +} + +( + deno run --allow-net --allow-read=/app server.ts & + trap "kill -SIGINT $!; wait $!" TERM + wait $! +) & +pid=$! +wait From a5112355483d91f4c937c5027aaba5957f06e575 Mon Sep 17 00:00:00 2001 From: Marcin Zepp Date: Fri, 8 Jan 2021 20:55:55 +0100 Subject: [PATCH 2/3] docker watchtower test --- server.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/server.ts b/server.ts index 8917c416..b9821a9a 100644 --- a/server.ts +++ b/server.ts @@ -2,6 +2,23 @@ import { Application, send } from "./deps.ts"; const app = new Application(); +// src: https://github.com/oakserver/oak + +// Logger +app.use(async (ctx, next) => { + await next(); + const rt = ctx.response.headers.get("X-Response-Time"); + console.log(`${ctx.request.method} ${ctx.request.url} - ${rt}`); +}); + +// Timing +app.use(async (ctx, next) => { + const start = Date.now(); + await next(); + const ms = Date.now() - start; + ctx.response.headers.set("X-Response-Time", `${ms}ms`); +}); + app.use(async (context) => { await send(context, context.request.url.pathname, { root: `${Deno.cwd()}/frontend`, From f17f56bb4659fe3a1d369017597c84d1f11114f0 Mon Sep 17 00:00:00 2001 From: Marcin Zepp Date: Sat, 9 Jan 2021 23:48:59 +0100 Subject: [PATCH 3/3] Add README with the installation instructions Revert "docker watchtower test" This reverts commit a5112355483d91f4c937c5027aaba5957f06e575. --- README.md | 35 +++++++++++++++++++++++++++++++++++ server.ts | 17 ----------------- 2 files changed, 35 insertions(+), 17 deletions(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 00000000..2b25bd6f --- /dev/null +++ b/README.md @@ -0,0 +1,35 @@ +# Pikne Zadania + + +## Installation + +[Install Docker](https://docs.docker.com/engine/install/) if it's not installed. If you are on Unix-based distro, you can try: + +```sh +# use the docker/docker-install script when you are lazy +curl -fsSL https://get.docker.com | sh +``` + +and don't forget to start `docker` service (with `service` or `systemctl`): + +```sh +# start the docker service if it's not started +sudo service docker start +# enable it if you want to run docker at the boot +sudo service docker enable +``` + +Run our container (use `sudo` if you are not in `docker` group): + +```sh +PORT=80 +docker run --name pikne-zadania -dp $PORT:8000 nircek/pikne-zadania +# or if you want to run it at the boot +docker run --name pikne-zadania -dp $PORT:8000 --restart unless-stopped nircek/pikne-zadania +``` + +Perform updates automatically with the [Watchtower](https://github.com/containrrr/watchtower): + +```sh +docker run --name watchtower -dv /var/run/docker.sock:/var/run/docker.sock containrrr/watchtower +``` diff --git a/server.ts b/server.ts index b9821a9a..8917c416 100644 --- a/server.ts +++ b/server.ts @@ -2,23 +2,6 @@ import { Application, send } from "./deps.ts"; const app = new Application(); -// src: https://github.com/oakserver/oak - -// Logger -app.use(async (ctx, next) => { - await next(); - const rt = ctx.response.headers.get("X-Response-Time"); - console.log(`${ctx.request.method} ${ctx.request.url} - ${rt}`); -}); - -// Timing -app.use(async (ctx, next) => { - const start = Date.now(); - await next(); - const ms = Date.now() - start; - ctx.response.headers.set("X-Response-Time", `${ms}ms`); -}); - app.use(async (context) => { await send(context, context.request.url.pathname, { root: `${Deno.cwd()}/frontend`,