From c1a01764682bacf35df35114b44eff40d15a1014 Mon Sep 17 00:00:00 2001 From: Owen Carter Date: Wed, 6 Apr 2022 11:04:53 +0200 Subject: [PATCH 1/7] Docker working on multiple arch and with udev --- DOCKER.md | 22 ++++++++++++++++++++++ Dockerfile | 17 +++++++++++++++-- 2 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 DOCKER.md diff --git a/DOCKER.md b/DOCKER.md new file mode 100644 index 0000000..fe95455 --- /dev/null +++ b/DOCKER.md @@ -0,0 +1,22 @@ +# lw.comm-server Docker Builds + +This guide assumes some familiarity with [Docker](https://www.docker.com/), if you are new to Docker please start at: https://docs.docker.com/get-started/ + +Docker user targets: +- dev + +## Dev (development snapshot) +You can run the current developement version of the app in Docker using the commands below. +- build development image: +``` +docker build -t lw.comm-server . +``` +- run image: +``` +docker run -it --device=/dev/ttyUSB0 --rm -p 8000:8000 lw.comm-server +``` +- connect to app: http://localhost:8000 + +## Run in background +If you add `-d` to the docker run command it will start the container in detached mode. +You can use `docker logs -f ` to follow the output of this, and `docker stop ` to stop it. diff --git a/Dockerfile b/Dockerfile index f2379f6..516c352 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,26 @@ -FROM resin/raspberrypi3-node:10 +FROM node:16-bullseye AS base +#FROM resin/raspberrypi3-node:10 ADD config.js grblStrings.js firmwareFeatures.js LICENSE lw.comm-server.service package.json README.md server.js version.txt /laserweb/ ADD app /laserweb/app/ -RUN cd /laserweb && npm install +# Set up Apt, install build tooling and udev +RUN apt update +RUN apt install -y build-essential udev +# Expose the port the container will serve on EXPOSE 8000 +FROM base AS comm-server + +# Build lw.comm-server +RUN cd /laserweb && npm install + +FROM comm-server AS dev + +# Add the start script ADD docker_entrypoint.sh / +# Entrypoint (defaulted) ENTRYPOINT ["/docker_entrypoint.sh"] CMD [] From 7f7ddcf76c9383366481d44e5250a0f97f20d720 Mon Sep 17 00:00:00 2001 From: Owen Carter Date: Wed, 6 Apr 2022 11:30:10 +0200 Subject: [PATCH 2/7] Allow the container to re-nice --- DOCKER.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/DOCKER.md b/DOCKER.md index fe95455..a9b64cb 100644 --- a/DOCKER.md +++ b/DOCKER.md @@ -3,17 +3,17 @@ This guide assumes some familiarity with [Docker](https://www.docker.com/), if you are new to Docker please start at: https://docs.docker.com/get-started/ Docker user targets: -- dev +- dev (default) -## Dev (development snapshot) -You can run the current developement version of the app in Docker using the commands below. +## Dev +You can build and run lw.comm-server in Docker using the commands below. - build development image: ``` docker build -t lw.comm-server . ``` - run image: ``` -docker run -it --device=/dev/ttyUSB0 --rm -p 8000:8000 lw.comm-server +docker run -it --device=/dev/ttyUSB0 --rm -p 8000:8000 --cap-add=sys_nice lw.comm-server ``` - connect to app: http://localhost:8000 From 97dcfdfba969a3641e3901a9a97744763f57bff2 Mon Sep 17 00:00:00 2001 From: Owen Date: Thu, 7 Apr 2022 16:15:38 +0200 Subject: [PATCH 3/7] note on devices and priviliged mode --- DOCKER.md | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/DOCKER.md b/DOCKER.md index a9b64cb..4ec9d3f 100644 --- a/DOCKER.md +++ b/DOCKER.md @@ -15,8 +15,22 @@ docker build -t lw.comm-server . ``` docker run -it --device=/dev/ttyUSB0 --rm -p 8000:8000 --cap-add=sys_nice lw.comm-server ``` -- connect to app: http://localhost:8000 +- Connect to app: http://localhost:8000 + +- Change the `--device=` to point to the correct USB device if necesscary, eg `--device=/dev/ttyACM0` etc. +- To use a different port change the port mapping in the `docker run` command to `:8000` and adjust the url you connect to appropriately. ## Run in background If you add `-d` to the docker run command it will start the container in detached mode. You can use `docker logs -f ` to follow the output of this, and `docker stop ` to stop it. + +## Allow hot plugging & selection of connected devices +**This is NOT recommended, since it involves running the container in `--privileged` mode, which is a [potential security risk](https://docs.docker.com/engine/reference/run/#runtime-privilege-and-linux-capabilities).** +- run image: +_..you have been warned.._ + +``` +docker run -it -v /dev:/dev --rm -p 8000:8000 --cap-add=sys_nice lw.comm-server +``` +- when you conenct the app you should be able to see all USB devices in the selection list + From 7a2403f7e6fb33b8ce7b3e5f3a3a68aa2fd2c4de Mon Sep 17 00:00:00 2001 From: Owen Carter Date: Thu, 7 Apr 2022 16:20:11 +0200 Subject: [PATCH 4/7] Formatting fix --- DOCKER.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/DOCKER.md b/DOCKER.md index 4ec9d3f..ac98982 100644 --- a/DOCKER.md +++ b/DOCKER.md @@ -26,9 +26,10 @@ You can use `docker logs -f ` to follow the output of this, and `docker st ## Allow hot plugging & selection of connected devices **This is NOT recommended, since it involves running the container in `--privileged` mode, which is a [potential security risk](https://docs.docker.com/engine/reference/run/#runtime-privilege-and-linux-capabilities).** -- run image: + _..you have been warned.._ +- run image: ``` docker run -it -v /dev:/dev --rm -p 8000:8000 --cap-add=sys_nice lw.comm-server ``` From 1cf0f0ae18e861ff154caae824387328ecec7889 Mon Sep 17 00:00:00 2001 From: Owen Carter Date: Thu, 7 Apr 2022 16:23:37 +0200 Subject: [PATCH 5/7] important omission --- DOCKER.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DOCKER.md b/DOCKER.md index ac98982..ab703eb 100644 --- a/DOCKER.md +++ b/DOCKER.md @@ -31,7 +31,7 @@ _..you have been warned.._ - run image: ``` -docker run -it -v /dev:/dev --rm -p 8000:8000 --cap-add=sys_nice lw.comm-server +docker run -it -v /dev:/dev --rm -p 8000:8000 --cap-add=sys_nice --privileged lw.comm-server ``` - when you conenct the app you should be able to see all USB devices in the selection list From 44386bba48e26d3256b93f3cdb9d784ed8d6b980 Mon Sep 17 00:00:00 2001 From: Owen Date: Thu, 7 Apr 2022 17:03:15 +0200 Subject: [PATCH 6/7] Add debug bash shell --- Dockerfile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Dockerfile b/Dockerfile index 516c352..33ddc7f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,3 +24,7 @@ ADD docker_entrypoint.sh / # Entrypoint (defaulted) ENTRYPOINT ["/docker_entrypoint.sh"] CMD [] + +# Bash shell for debug +from comm-server as bash +ENTRYPOINT ["/bin/bash"] From cd20c3fcb9950a68f04b9536c07d7f4e9fcae742 Mon Sep 17 00:00:00 2001 From: Owen Date: Thu, 7 Apr 2022 17:09:14 +0200 Subject: [PATCH 7/7] spelling --- DOCKER.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DOCKER.md b/DOCKER.md index ab703eb..07aa4ec 100644 --- a/DOCKER.md +++ b/DOCKER.md @@ -33,5 +33,5 @@ _..you have been warned.._ ``` docker run -it -v /dev:/dev --rm -p 8000:8000 --cap-add=sys_nice --privileged lw.comm-server ``` -- when you conenct the app you should be able to see all USB devices in the selection list +- when you connect the app you should be able to see all USB devices in the selection list