From 26c3a426229b6a729e77fe9951aea432bd5834c3 Mon Sep 17 00:00:00 2001 From: stn_ptr <34418806+stn-ptr@users.noreply.github.com> Date: Sun, 16 Nov 2025 11:56:27 +0100 Subject: [PATCH 1/8] copy current directory layout into container --- Dockerfile | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1e5396e..5150125 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,13 @@ FROM node:22.17.1-alpine -RUN mkdir -p /home/app +WORKDIR /opt/task/srv -COPY . /home/app +COPY package.json package-lock.json /opt/task/srv/ +RUN npm install -WORKDIR /home/app +COPY index.js /opt/task/srv +COPY app /opt/task/srv/app +COPY task /opt/task/srv/task +COPY persistence /opt/task/srv/persistence -CMD ["node", "/home/app/index.js", "--ConfigurationFile=/home/app/tasks.json"] +CMD ["node", "/opt/task/srv/index.js", "--ConfigurationFile=/opt/task/srv/tasks.json"] From fb6dc21cb5602984a9ccbf125b6603499fd03aac Mon Sep 17 00:00:00 2001 From: stn_ptr <34418806+stn-ptr@users.noreply.github.com> Date: Sun, 16 Nov 2025 11:57:12 +0100 Subject: [PATCH 2/8] use port 3000 --- Readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Readme.md b/Readme.md index 41b683c..5aa61f5 100644 --- a/Readme.md +++ b/Readme.md @@ -44,9 +44,9 @@ This repository contains a Dockerfile to build a container with the task service To run the container, use the following command: - docker run -p 8000:1337 task-service + docker run -p 3000:3000 task-service -The container will be available on port 8000. +The container will be available on port 3000. ## Features From 95102f585db780acf1ad0c13382b7b13d64d49b9 Mon Sep 17 00:00:00 2001 From: stn_ptr <34418806+stn-ptr@users.noreply.github.com> Date: Sun, 16 Nov 2025 13:32:57 +0100 Subject: [PATCH 3/8] create data directory --- app/config.js | 7 +++++++ index.js | 3 ++- persistence/file/task.js | 5 +++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/config.js b/app/config.js index 402a584..3e01003 100644 --- a/app/config.js +++ b/app/config.js @@ -1,4 +1,5 @@ const fs = require("fs"); +const persistence = require("../persistence/file/task.js") const configFileOptions = { encoding: "utf8" }; @@ -25,4 +26,10 @@ function getConfig() { } } } + +function setup() { + persistence.setup(); +} + +exports.setup = setup; exports.getConfig = getConfig; diff --git a/index.js b/index.js index c7fff9c..a3d8fa2 100644 --- a/index.js +++ b/index.js @@ -1,10 +1,11 @@ "use strict"; const fs = require("fs"); -const { getConfig } = require("./app/config.js"); +const { getConfig, setup } = require("./app/config.js"); const { app } = require("./app/app.js"); const config = getConfig(); +setup(); let httpOptions, server; if (config !== undefined && config["HttpsOptions"] !== undefined) { diff --git a/persistence/file/task.js b/persistence/file/task.js index 57ae83f..59cec18 100644 --- a/persistence/file/task.js +++ b/persistence/file/task.js @@ -3,6 +3,10 @@ const fs = require("node:fs"); const defaultDataDir = "./data/task/" const extension = ".json" +function setup() { + fs.mkdirSync(defaultDataDir, {recursive: true}); +} + function save(task, callback) { fs.writeFile( defaultDataDir + task.id + extension, @@ -55,3 +59,4 @@ exports.save = save exports.load = load exports.remove = remove exports.list = list +exports.setup = setup From 43a638c2146e9cb1ef1a455f7ad4dd83b9fdcc9c Mon Sep 17 00:00:00 2001 From: stn_ptr <34418806+stn-ptr@users.noreply.github.com> Date: Sun, 7 Dec 2025 23:00:04 +0100 Subject: [PATCH 4/8] install in more FHS compliant directories --- Dockerfile | 14 +++++++------- Readme.md => README.md | 5 ++--- 2 files changed, 9 insertions(+), 10 deletions(-) rename Readme.md => README.md (89%) diff --git a/Dockerfile b/Dockerfile index 5150125..a920f46 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,13 @@ FROM node:22.17.1-alpine -WORKDIR /opt/task/srv +WORKDIR /usr/local/lib/task-service -COPY package.json package-lock.json /opt/task/srv/ +COPY package.json package-lock.json /usr/local/lib/task-service/ RUN npm install -COPY index.js /opt/task/srv -COPY app /opt/task/srv/app -COPY task /opt/task/srv/task -COPY persistence /opt/task/srv/persistence +COPY index.js ./ +COPY app/ ./app/ +COPY task/ ./task/ +COPY persistence/ ./persistence/ -CMD ["node", "/opt/task/srv/index.js", "--ConfigurationFile=/opt/task/srv/tasks.json"] +CMD ["node", "/usr/local/lib/task-service/index.js", "--ConfigurationFile=/etc/task-service/tasks.json"] diff --git a/Readme.md b/README.md similarity index 89% rename from Readme.md rename to README.md index 5aa61f5..ed55930 100644 --- a/Readme.md +++ b/README.md @@ -6,8 +6,7 @@ This is project is meant for learning, practicing and trying out things, not for ## Requirements -- Node 18.15.0 -- ~~Node 0.10.48 - Ancient, but this version runs on my NAS, which is ancient as well.~~ +- Node 22.17.1 ## Setup @@ -44,7 +43,7 @@ This repository contains a Dockerfile to build a container with the task service To run the container, use the following command: - docker run -p 3000:3000 task-service + docker run --rm --detach --name task-service --port 3000:3000 --volume ${PWD}/tasks.json:/etc/task-service/tasks.json:ro --volume ${PWD}/localhost.key:/usr/local/lib/task-service/localhost.key:ro --volume ${PWD}/localhost.crt:/usr/local/lib/task-service/localhost.crt:ro task-service The container will be available on port 3000. From 9b901f376e7b67213c9a240ad643f6c81c7f3373 Mon Sep 17 00:00:00 2001 From: stn_ptr <34418806+stn-ptr@users.noreply.github.com> Date: Sun, 7 Dec 2025 23:19:34 +0100 Subject: [PATCH 5/8] move all app code into app/ and tests to test/ to simplify dockerfile --- Dockerfile | 5 +---- app/config.js | 2 +- app/handler.js | 2 +- index.js => app/index.js | 4 ++-- {persistence => app/persistence}/file/task.js | 0 {task => app/task}/task.js | 0 {task => tests/task}/task.test.js | 0 7 files changed, 5 insertions(+), 8 deletions(-) rename index.js => app/index.js (87%) rename {persistence => app/persistence}/file/task.js (100%) rename {task => app/task}/task.js (100%) rename {task => tests/task}/task.test.js (100%) diff --git a/Dockerfile b/Dockerfile index a920f46..96ec1d1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,9 +5,6 @@ WORKDIR /usr/local/lib/task-service COPY package.json package-lock.json /usr/local/lib/task-service/ RUN npm install -COPY index.js ./ -COPY app/ ./app/ -COPY task/ ./task/ -COPY persistence/ ./persistence/ +COPY app/ . CMD ["node", "/usr/local/lib/task-service/index.js", "--ConfigurationFile=/etc/task-service/tasks.json"] diff --git a/app/config.js b/app/config.js index 3e01003..cdf0def 100644 --- a/app/config.js +++ b/app/config.js @@ -1,5 +1,5 @@ const fs = require("fs"); -const persistence = require("../persistence/file/task.js") +const persistence = require("./persistence/file/task.js") const configFileOptions = { encoding: "utf8" }; diff --git a/app/handler.js b/app/handler.js index 289abab..6497352 100644 --- a/app/handler.js +++ b/app/handler.js @@ -1,4 +1,4 @@ -const task = require("../task/task.js"); +const task = require("./task/task.js"); const { authenticate } = require("./auth/auth.js"); function postTask(req, res) { diff --git a/index.js b/app/index.js similarity index 87% rename from index.js rename to app/index.js index a3d8fa2..49b0219 100644 --- a/index.js +++ b/app/index.js @@ -1,8 +1,8 @@ "use strict"; const fs = require("fs"); -const { getConfig, setup } = require("./app/config.js"); -const { app } = require("./app/app.js"); +const { getConfig, setup } = require("./config.js"); +const { app } = require("./app.js"); const config = getConfig(); setup(); diff --git a/persistence/file/task.js b/app/persistence/file/task.js similarity index 100% rename from persistence/file/task.js rename to app/persistence/file/task.js diff --git a/task/task.js b/app/task/task.js similarity index 100% rename from task/task.js rename to app/task/task.js diff --git a/task/task.test.js b/tests/task/task.test.js similarity index 100% rename from task/task.test.js rename to tests/task/task.test.js From 8aaa4ce152abf7413d989b0073a22ab081df5ce4 Mon Sep 17 00:00:00 2001 From: stn_ptr <34418806+stn-ptr@users.noreply.github.com> Date: Sun, 14 Dec 2025 14:15:44 +0100 Subject: [PATCH 6/8] include volume for data and fix parameter name --- README.md | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ed55930..b653972 100644 --- a/README.md +++ b/README.md @@ -43,13 +43,24 @@ This repository contains a Dockerfile to build a container with the task service To run the container, use the following command: - docker run --rm --detach --name task-service --port 3000:3000 --volume ${PWD}/tasks.json:/etc/task-service/tasks.json:ro --volume ${PWD}/localhost.key:/usr/local/lib/task-service/localhost.key:ro --volume ${PWD}/localhost.crt:/usr/local/lib/task-service/localhost.crt:ro task-service + docker run + --rm + --detach + --name task-service + --publish 3000:3000 + --volume tasks:/usr/local/lib/task-service/data + --volume ${PWD}/tasks.json:/etc/task-service/tasks.json:ro + --volume ${PWD}/localhost.key:/usr/local/lib/task-service/localhost.key:ro + --volume ${PWD}/localhost.crt:/usr/local/lib/task-service/localhost.crt:ro + task-service The container will be available on port 3000. ## Features - Supports HTTPS +- Authentication + - Basic - Not much more yet 😃 ## Testing @@ -98,5 +109,5 @@ Invoke-WebRequest "http://localhost:3000/task/99e587e6-6550-4601-9e2a-d40d2a2dce Delete a task ```powershell -Invoke-WebRequest "http://localhost:1337/task/99e587e6-6550-4601-9e2a-d40d2a2dce7b" -Credential $credential -AllowUnencryptedAuthentication -Method Delete +Invoke-WebRequest "http://localhost:3000/task/99e587e6-6550-4601-9e2a-d40d2a2dce7b" -Credential $credential -AllowUnencryptedAuthentication -Method Delete ``` From 5b6c2fd480017bb6f3bc781b886e5b48992df623 Mon Sep 17 00:00:00 2001 From: stn_ptr <34418806+stn-ptr@users.noreply.github.com> Date: Sun, 14 Dec 2025 14:24:11 +0100 Subject: [PATCH 7/8] ignore local environments --- docs/bruno/environments/.gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 docs/bruno/environments/.gitignore diff --git a/docs/bruno/environments/.gitignore b/docs/bruno/environments/.gitignore new file mode 100644 index 0000000..b698f76 --- /dev/null +++ b/docs/bruno/environments/.gitignore @@ -0,0 +1 @@ +*.local.bru From c81a127970703de22a2cc33be8dc760420703f94 Mon Sep 17 00:00:00 2001 From: stn_ptr <34418806+stn-ptr@users.noreply.github.com> Date: Sun, 14 Dec 2025 15:19:51 +0100 Subject: [PATCH 8/8] add line breaks for Bash and PowerShell --- README.md | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index b653972..0c7e461 100644 --- a/README.md +++ b/README.md @@ -43,16 +43,35 @@ This repository contains a Dockerfile to build a container with the task service To run the container, use the following command: - docker run - --rm - --detach - --name task-service - --publish 3000:3000 - --volume tasks:/usr/local/lib/task-service/data - --volume ${PWD}/tasks.json:/etc/task-service/tasks.json:ro - --volume ${PWD}/localhost.key:/usr/local/lib/task-service/localhost.key:ro - --volume ${PWD}/localhost.crt:/usr/local/lib/task-service/localhost.crt:ro - task-service +In Bash + +```bash +docker run \ + --rm \ + --detach \ + --name task-service \ + --publish 3000:3000 \ + --volume tasks:/usr/local/lib/task-service/data \ + --volume ${PWD}/tasks.json:/etc/task-service/tasks.json:ro \ + --volume ${PWD}/localhost.key:/usr/local/lib/task-service/localhost.key:ro \ + --volume ${PWD}/localhost.crt:/usr/local/lib/task-service/localhost.crt:ro \ + task-service +``` + +In PowerShell + +```powershell +docker run ` + --rm ` + --detach ` + --name task-service ` + --publish 3000:3000 ` + --volume tasks:/usr/local/lib/task-service/data ` + --volume ${PWD}/tasks.json:/etc/task-service/tasks.json:ro ` + --volume ${PWD}/localhost.key:/usr/local/lib/task-service/localhost.key:ro ` + --volume ${PWD}/localhost.crt:/usr/local/lib/task-service/localhost.crt:ro ` + task-service +``` The container will be available on port 3000.