<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Sylwester Mielniczuk</title>
    <description>The latest articles on Forem by Sylwester Mielniczuk (@sylwesterdigital).</description>
    <link>https://forem.com/sylwesterdigital</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F440008%2F8edcd104-5c23-4741-988c-4f99a1308e18.jpeg</url>
      <title>Forem: Sylwester Mielniczuk</title>
      <link>https://forem.com/sylwesterdigital</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/sylwesterdigital"/>
    <language>en</language>
    <item>
      <title>Immersive Web, Docker and problem with symbolic links for SSL certificates.</title>
      <dc:creator>Sylwester Mielniczuk</dc:creator>
      <pubDate>Fri, 10 Jun 2022 09:53:19 +0000</pubDate>
      <link>https://forem.com/samsunginternet/immersive-web-docker-and-problem-with-symbolic-links-for-ssl-certificates-45o0</link>
      <guid>https://forem.com/samsunginternet/immersive-web-docker-and-problem-with-symbolic-links-for-ssl-certificates-45o0</guid>
      <description>&lt;h2&gt;
  
  
  Interactive Wall at GAM in Turin
&lt;/h2&gt;

&lt;p&gt;As an &lt;strong&gt;Immersive Web Developer&lt;/strong&gt; from time to time, there is a need to play the role of &lt;strong&gt;DevOps engineer&lt;/strong&gt;. Mostly because the prototype of my research project needed to be deployed to production cloud infrastructure &lt;strong&gt;(&lt;a href="https://www.5g-eve.eu/"&gt;5G EVE&lt;/a&gt;)&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Despite the complexity of the overall 5G research, my web application is relatively weak, called &lt;strong&gt;"Interactive Wall"&lt;/strong&gt; is designed for a multi-device experience with blazing fast animation purposes WebGL canvas (&lt;a href="https://pixijs.io/"&gt;PixiJS&lt;/a&gt;). Depending on the provided parameters there are two types of UIs: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;For students (kids or other pupils) - (multiplayer)&lt;/li&gt;
&lt;li&gt;The teacher(s) (or other guardians) - (single user)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The first one is displayed on the wall via projector, the second can be opened via QR code on the mobile device, wearable or any other desktop running Chromium-based browsers. Realtime communication between both interfaces is established via &lt;a href="https://github.com/websockets/ws"&gt;WebSocket&lt;/a&gt; server.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lsI75HAi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/soend0j23ozzh82p6wvv.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lsI75HAi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/soend0j23ozzh82p6wvv.gif" alt="Immersive Web" width="640" height="360"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The GIF above showcases a WebSocket connection between 2 tabs of the browser, mobile and wearable device. The latency between them is about and above 30ms but depends on the hardware and network characteristics. We were aiming to measure all the advantages of having 20 times faster connections than 4G.&lt;/p&gt;

&lt;h2&gt;
  
  
  Connecting to uncommon HID devices.
&lt;/h2&gt;

&lt;p&gt;Paired and connected via Bluetooth thanks to &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/WebHID_API"&gt;WebHID API&lt;/a&gt; - old good and forgotten almighty Nintendo Wiimote. Its camera for direction reports is calibrated by IR Bar, and all the motion, acceleration and input data from 11 buttons are sent via Bluetooth to the browser. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;What is actually WebHID?&lt;/em&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;sup&gt;"HID consists of two fundamental concepts: reports and report descriptors. Reports are the data that is exchanged between a device and a software client. The report descriptor describes the format and meaning of data that the device supports.&lt;br&gt;
An HID (Human Interface Device) is a type of device that takes input from or provides output to humans. It also refers to the HID protocol, a standard for bi-directional communication between a host and a device that is designed to simplify the installation procedure. The HID protocol was originally developed for USB devices, but has since been implemented over many other protocols, including Bluetooth." - &lt;a href="https://web.dev/hid/"&gt;https://web.dev/hid/&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I was able to use simultaneously more than 4 controllers. Originally developed for one Wiimote by a former colleague at Samsung &lt;a href="https://picchikevin.github.io/wiimote-webhid/"&gt;Kevin Picchi&lt;/a&gt;. I have developed a multiuser version for &lt;a href="http://5gtours.eu/"&gt;5G Tours consortium&lt;/a&gt;. It's a really long story. &lt;/p&gt;

&lt;h2&gt;
  
  
  Portable Deployment
&lt;/h2&gt;

&lt;p&gt;In general, the browser UI can be statically provided separately from the WebSocket server but for the sake of portability, decided to pack everything all together as &lt;a href="https://nodejs.org/"&gt;Node.JS&lt;/a&gt; project, perfect for scalable web applications. Portable deployment should be easy with &lt;a href="https://www.docker.com/resources/what-container/"&gt;Docker&lt;/a&gt;. There is super simple &lt;a href="https://nodejs.org/en/docs/guides/nodejs-docker-webapp/"&gt;tutorial how to do bake nodejs-docker-webapp&lt;/a&gt;. Basic use of Docker is free and you can install it on Mac, Windows and Linux. You need to write a relatively simple Dockerfile.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# The name of the image for your container
FROM node:16

# Create app directory, copy configuration assets
WORKDIR /usr/src/app
COPY package*.json ./

# Install npm
RUN npm install

# Bundle app source
COPY . .

# Optional exposed app ports
EXPOSE 8080

# Available commands from CLI
CMD [ "node", "index-wall.js" ]

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To build the image run this command from the folder where your Dockerfile and assets are located. &lt;br&gt;
&lt;code&gt;$ docker build . -t flaboy/node-wall&lt;/code&gt;&lt;br&gt;
flaboy/node-wall is the given name of image, when it's created you can push and pull this like git repo to the docker.io repository.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ docker push flaboy/node-wall&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If you need to share image file this is the way you can export tarball:&lt;br&gt;
&lt;code&gt;$ docker save flaboy/node-wall &amp;gt; node-vr.tar&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Later someone can load the archived image as follows:&lt;br&gt;
&lt;code&gt;$ docker load &amp;lt; node-vr.tar&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Deploying such an image seems to be super simple. On the server with a fully qualified domain and web server and reverse proxy &lt;a href="https://nginx.org/"&gt;Nginx&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;The only little problem is those files required by server web application via HTTPS, ie SSL certificates. Where they are located? It depends on how you managed such certificates. I use &lt;a href="https://letsencrypt.org/"&gt;letsEncrypt&lt;/a&gt; Certbot. &lt;/p&gt;

&lt;p&gt;Your browser lock at the location bar says:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SwsdiLoj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w82kljpi0a0537o4jsmt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SwsdiLoj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w82kljpi0a0537o4jsmt.png" alt="This is what you see" width="777" height="659"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;These chains of trust hierarchy technically have this structure:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hGrJ6VGC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/40mikmhsum3c7lqtjetv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hGrJ6VGC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/40mikmhsum3c7lqtjetv.png" alt="Chain of Trust" width="880" height="587"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  Let's Encrypt Certbot hints
&lt;/h1&gt;

&lt;p&gt;Installation:&lt;br&gt;
&lt;code&gt;$ sudo apt install certbot python3-certbot-nginx&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Get your domain SSL certificates:&lt;br&gt;
&lt;code&gt;$ sudo certbot --nginx -d your.domain.name&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The architecture is organized by certbot in this folder: &lt;code&gt;/etc/letsencrypt&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YRvUjI5j--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/64w5o61mtw93o3yvla8q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YRvUjI5j--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/64w5o61mtw93o3yvla8q.png" alt="/etc/letsencrypt/" width="816" height="329"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And the domain name specific files are saved to &lt;code&gt;/etc/letsencrypt/archive/your.domain.name&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;So these files are archived under the following numbers (because certbot already renewed cert files so far several times). The latest ones are exposed to the &lt;code&gt;/etc/letsencrypt/live/&lt;/code&gt; folder. as symbolic links (&lt;a href="https://man7.org/linux/man-pages/man2/symlink.2.html"&gt;symlinks&lt;/a&gt;) without numbers in their names.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;sup&gt;- Symbolic links are interpreted at run time as if the contents of the link had been substituted into the path being followed to find a file or directory. - Symbolic links may contain ..  path components, which (if used at the start of the link) refer to the parent directories of that in which the link resides. - A symbolic link (also known as a soft link) may point to an existing file or to a nonexistent one; the latter case is known as a dangling link..&lt;/sup&gt;&lt;br&gt;
&lt;/p&gt;


&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;root [letsencrypt] $ more /etc/letsencrypt/live/your.domain.name/README 
This directory contains your keys and certificates.

`privkey.pem`  : the private key for your certificate.
`fullchain.pem`: the certificate file used in most server software.
`chain.pem`    : used for OCSP stapling in Nginx &amp;gt;=1.3.7.
`cert.pem`     : will break many server configurations, and should not be used
                 without reading further documentation (see link below).

WARNING: DO NOT MOVE OR RENAME THESE FILES!
         Certbot expects these files to remain in this location in order
         to function properly!

We recommend not moving these files. For more information, see the Certbot
User Guide at https://certbot.eff.org/docs/using.html#where-are-my-certificates.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Coming back to the Docker. We have pulled the image and we would love to run the web app. The problem is that the container needs to read SSL certificates (exposed as symbolic links) from the outside of the Docker virtual container. They are required to run the web app securely via HTTPS. The paths to the key and certificate are provided in the main Node.js app file: &lt;code&gt;index-wall.js&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const server = https.createServer({
    key: fs.readFileSync('/ssl/privkey.pem'),
    cert: fs.readFileSync('/ssl/fullchain.pem')
}, app);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here is how it can not be run with mounted volumes -v ( --volume). &lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ docker run -v /etc/letsencrypt/live/your.domain.name:/ssl -d -p 4444:8080 flaboy/node-wall node index-wall.js&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Docker unfortunately is not able to read symlinks from provided volumes (-v). You can check the error logs this way:&lt;br&gt;
&lt;code&gt;$ docker logs containerid&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;root [letsencrypt] $ docker logs 8d2b81a25359
node:internal/fs/utils:345
    throw err;
    ^

Error: ENOENT: no such file or directory, open '/ssl/privkey.pem'
    at Object.openSync (node:fs:585:3)
    at Object.readFileSync (node:fs:453:35)
    at Object.&amp;lt;anonymous&amp;gt; (/usr/src/app/index-wall.js:18:13)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
    at node:internal/main/run_main_module:17:47 {
  errno: -2,
  syscall: 'open',
  code: 'ENOENT',
  path: '/ssl/privkey.pem'
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  You need to use bind mounts
&lt;/h1&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;What are bind mounts?&lt;/strong&gt;&lt;/em&gt; As per &lt;a href="https://docs.docker.com/storage/bind-mounts/"&gt;Docker documentation&lt;/a&gt;, we can read that:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;[...] Bind mounts have limited functionality compared to volumes. When you use a bind mount, a file or directory on the host machine is mounted into a container. The file or directory is referenced by its absolute path on the host machine. By contrast, when you use a volume, a new directory is created within Docker’s storage directory on the host machine, and Docker manages that directory’s contents.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Detailed instruction on the bind mounts syntax:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;--mount&lt;/strong&gt;: Consists of multiple key-value pairs, separated by commas and each consisting of a &lt;code&gt;&amp;lt;key&amp;gt;=&amp;lt;value&amp;gt;&lt;/code&gt; tuple. - The --mount syntax is more verbose than &lt;code&gt;-v&lt;/code&gt; or &lt;code&gt;--volume&lt;/code&gt;, but the order of the keys is not significant, and the value of the flag is easier to understand.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The type of the mount, which can be bind, volume, or tmpfs. [...] The type is always bind.&lt;/li&gt;
&lt;li&gt;The source of the mount. For bind mounts, this is the path to the file or directory on the Docker daemon host. May be specified as source or src.&lt;/li&gt;
&lt;li&gt;The destination takes as its value the path where the file or directory is mounted in the container. May be specified as destination, dst, or target.&lt;/li&gt;
&lt;li&gt;The readonly option, if present, causes the bind mount to be mounted into the container as read-only.&lt;/li&gt;
&lt;li&gt;The bind-propagation option, if present, changes the bind propagation. May be one of rprivate, private, rshared, shared, rslave, slave.&lt;/li&gt;
&lt;li&gt;The --mount flag does not support z or Z options for modifying selinux labels.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;So let's try to mount 2 cert files (&lt;strong&gt;sources&lt;/strong&gt;):&lt;br&gt;
&lt;code&gt;/etc/letsencrypt/live/your.domain.name/privkey.pem&lt;/code&gt;&lt;br&gt;
and &lt;code&gt;/etc/letsencrypt/live/your.domain.name/fullchain.pem&lt;/code&gt; as they would exist inside docker container inside &lt;code&gt;/ssl/&lt;/code&gt; folder (&lt;strong&gt;target&lt;/strong&gt;).&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ docker run --mount type=bind,source=/etc/letsencrypt/live/your.domain.name/privkey.pem,target=/ssl/privkey.pem --mount type=bind,source=/etc/letsencrypt/live/your.domain.name/fullchain.pem,target=/ssl/fullchain.pem -d -p 4444:8080 flaboy/node-wall node index-wall.js&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Is the app running?&lt;br&gt;
&lt;code&gt;$ docker ps -a&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;9990433c624d   flaboy/node-wall   "docker-entrypoint.s…"   4 minutes ago   Up 4 minutes                 0.0.0.0:4444-&amp;gt;8080/tcp, :::4444-&amp;gt;8080/tcp   hardcore_nash
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Yes! That's all people!
&lt;/h2&gt;

&lt;p&gt;Here is my video on how it did not work properly with -v&lt;br&gt;
&lt;a href="https://www.youtube.com/watch?v=doS0L6nBeKg"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ohz0F_34--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://img.youtube.com/vi/doS0L6nBeKg/0.jpg" alt="Here is how it did not work with -v" width="480" height="360"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And here is working properly with the latest SSL&lt;br&gt;
&lt;a href="https://www.youtube.com/watch?v=1rRZRmLt7s4"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dcSi2AMW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://img.youtube.com/vi/1rRZRmLt7s4/0.jpg" alt="And here is working properly SSL" width="480" height="360"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you would love to play with &lt;a href="https://xr.workwork.fun:4444"&gt;Interactive Wall&lt;/a&gt;, it's deployed to: &lt;a href="https://xr.workwork.fun:4444"&gt;https://xr.workwork.fun:4444&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The app works on Mac, and Windows (you might need also Nintendo &lt;br&gt;
 emulator &lt;strong&gt;&lt;a href="https://dolphin-emu.org/"&gt;Dolphin&lt;/a&gt;)&lt;/strong&gt;. You just need a Chromium-based browser (Edge, Brave, Chrome), also get your &lt;strong&gt;original Wiimote(s) Plus&lt;/strong&gt; (cheap, the third party rather does not work). Do not forget to charge your batteries. Infrared direction calibrator &lt;strong&gt;Mayflash W010 Dolphin Bar&lt;/strong&gt; is necessary, get it from the &lt;a href="https://www.amazon.co.uk/Mayflash-W010-Dolphin-Bar-Wireless/dp/B00HZWEB74"&gt;Amazon&lt;/a&gt;. The WebHID API and amount of Bluetooth devices might be limited on Windows but Bluetooth standard might allow connecting lots of devices so having multiple input devices connected to the web browser interface at the same time is an amazing opportunity for multiplayer experiences without any game-server involved. &lt;em&gt;Just think about this a little bit!&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The Students UI&lt;br&gt;
&lt;a href="https://xr.workwork.fun:4444"&gt;https://xr.workwork.fun:4444&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The Teachers UI (open from provided QR code)&lt;br&gt;
&lt;a href="https://xr.workwork.fun:4444/?u=teacher&amp;amp;p=pass1"&gt;https://xr.workwork.fun:4444/?u=teacher&amp;amp;p=pass1&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OdjgTlLv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/teopgxe6dta37kbkx5op.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OdjgTlLv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/teopgxe6dta37kbkx5op.png" alt="Image description" width="880" height="428"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;More about &lt;strong&gt;5GTours&lt;/strong&gt; project you can find in D4.4 public document on &lt;a href="http://5gtours.eu/deliverables/"&gt;http://5gtours.eu/deliverables/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webhidapi</category>
      <category>immersiveweb</category>
      <category>smartcity</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Immersive Web, Docker and problem with sym-linked SSL certs (hardcore_nash).</title>
      <dc:creator>Sylwester Mielniczuk</dc:creator>
      <pubDate>Wed, 08 Jun 2022 17:18:15 +0000</pubDate>
      <link>https://forem.com/sylwesterdigital/immersive-web-docker-and-problem-with-sym-linked-ssl-certs-hardcorenash-4gnm</link>
      <guid>https://forem.com/sylwesterdigital/immersive-web-docker-and-problem-with-sym-linked-ssl-certs-hardcorenash-4gnm</guid>
      <description>&lt;h2&gt;
  
  
  Interactive Wall at GAM in Turin
&lt;/h2&gt;

&lt;p&gt;As an &lt;strong&gt;Immersive Web Developer&lt;/strong&gt; from time to time, there is a need to play the role of &lt;strong&gt;DevOps engineer&lt;/strong&gt;. Mostly because the prototype of my research project needed to be deployed to production cloud infrastructure &lt;strong&gt;(&lt;a href="https://www.5g-eve.eu/"&gt;5G EVE&lt;/a&gt;)&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Despite the complexity of the overall 5G research, my web application is relatively weak, called &lt;strong&gt;"Interactive Wall"&lt;/strong&gt; is designed for a multi-device experience with blazing fast animation purposes WebGL canvas (&lt;a href="https://pixijs.io/"&gt;PixiJS&lt;/a&gt;). Depending on the provided parameters there are two types of UIs: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;For students (kids or other pupils) - (multiplayer)&lt;/li&gt;
&lt;li&gt;The teacher(s) (or other guardians) - (single user)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The first one is displayed on the wall via projector, the second can be opened via QR code on the mobile device, wearable or any other desktop running Chromium-based browsers. Realtime communication between both interfaces is established via &lt;a href="https://github.com/websockets/ws"&gt;WebSocket&lt;/a&gt; server.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lsI75HAi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/soend0j23ozzh82p6wvv.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lsI75HAi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/soend0j23ozzh82p6wvv.gif" alt="Immersive Web" width="640" height="360"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The GIF above showcases a WebSocket connection between 2 tabs of the browser, mobile and wearable device. The latency between them is about and above 30ms but depends on the hardware and network characteristics. We were aiming to measure all the advantages of having 20 times faster connections than 4G.&lt;/p&gt;

&lt;h2&gt;
  
  
  Connecting to uncommon HID devices
&lt;/h2&gt;

&lt;p&gt;Paired and connected via Bluetooth thanks to &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/WebHID_API"&gt;WebHID API&lt;/a&gt; - old good and forgotten almighty Nintendo Wiimote. Its camera for direction reports is calibrated by IR Bar, and all the motion, acceleration and input data from 11 buttons are sent via Bluetooth to the browser. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;What is actually WebHID?&lt;/em&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;sup&gt;"HID consists of two fundamental concepts: reports and report descriptors. Reports are the data that is exchanged between a device and a software client. The report descriptor describes the format and meaning of data that the device supports.&lt;br&gt;
An HID (Human Interface Device) is a type of device that takes input from or provides output to humans. It also refers to the HID protocol, a standard for bi-directional communication between a host and a device that is designed to simplify the installation procedure. The HID protocol was originally developed for USB devices, but has since been implemented over many other protocols, including Bluetooth." - &lt;a href="https://web.dev/hid/"&gt;https://web.dev/hid/&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I was able to use simultaneously more than 4 controllers. Originally developed for one Wiimote by a former colleague at Samsung &lt;a href="https://picchikevin.github.io/wiimote-webhid/"&gt;Kevin Picchi&lt;/a&gt;. I have developed a multiuser version for &lt;a href="http://5gtours.eu/"&gt;5G Tours consortium&lt;/a&gt;. It's a really long story. &lt;/p&gt;

&lt;h2&gt;
  
  
  Portable Deployment
&lt;/h2&gt;

&lt;p&gt;In general, the browser UI can be statically provided separately from the WebSocket server but for the sake of portability, decided to pack everything all together as &lt;a href="https://nodejs.org/"&gt;Node.JS&lt;/a&gt; project, perfect for scalable web applications. Portable deployment should be easy with &lt;a href="https://www.docker.com/resources/what-container/"&gt;Docker&lt;/a&gt;. There is super simple &lt;a href="https://nodejs.org/en/docs/guides/nodejs-docker-webapp/"&gt;tutorial how to do bake nodejs-docker-webapp&lt;/a&gt;. Basic use of Docker is free and you can install it on Mac, Windows and Linux. You need to write a relatively simple Dockerfile.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# The name of the image for your container
FROM node:16

# Create app directory, copy configuration assets
WORKDIR /usr/src/app
COPY package*.json ./

# Install npm
RUN npm install

# Bundle app source
COPY . .

# Optional exposed app ports
EXPOSE 8080

# Available commands from CLI
CMD [ "node", "index-wall.js" ]

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To build the image run this command from the folder where your Dockerfile and assets are located. &lt;br&gt;
&lt;code&gt;$ docker build . -t flaboy/node-wall&lt;/code&gt;&lt;br&gt;
flaboy/node-wall is the given name of image, when it's created you can push and pull this like git repo to the docker.io repository.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ docker push flaboy/node-wall&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If you need to share image file this is the way you can export tarball:&lt;br&gt;
&lt;code&gt;$ docker save flaboy/node-wall &amp;gt; node-vr.tar&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Later someone can load the archived image as follows:&lt;br&gt;
&lt;code&gt;$ docker load &amp;lt; node-vr.tar&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Deploying such an image seems to be super simple. On the server with a fully qualified domain and web server and reverse proxy &lt;a href="https://nginx.org/"&gt;Nginx&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;The only little problem is those files required by server web application via HTTPS, ie SSL certificates. Where they are located? It depends on how you managed such certificates. I use &lt;a href="https://letsencrypt.org/"&gt;letsEncrypt&lt;/a&gt; Certbot. &lt;/p&gt;

&lt;p&gt;Your browser lock at the location bar says:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SwsdiLoj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w82kljpi0a0537o4jsmt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SwsdiLoj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w82kljpi0a0537o4jsmt.png" alt="This is what you see" width="777" height="659"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;These chains of trust hierarchy technically have this structure:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hGrJ6VGC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/40mikmhsum3c7lqtjetv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hGrJ6VGC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/40mikmhsum3c7lqtjetv.png" alt="Chain of Trust" width="880" height="587"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  Let's Encrypt Certbot hints
&lt;/h1&gt;

&lt;p&gt;Installation:&lt;br&gt;
&lt;code&gt;$ sudo apt install certbot python3-certbot-nginx&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Get your domain SSL certificates:&lt;br&gt;
&lt;code&gt;$ sudo certbot --nginx -d your.domain.name&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The architecture is organized by certbot in this folder: &lt;code&gt;/etc/letsencrypt&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YRvUjI5j--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/64w5o61mtw93o3yvla8q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YRvUjI5j--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/64w5o61mtw93o3yvla8q.png" alt="/etc/letsencrypt/" width="816" height="329"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And the domain name specific files are saved to &lt;code&gt;/etc/letsencrypt/archive/your.domain.name&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;So these files are archived under the following numbers (because certbot already renewed cert files so far several times). The latest ones are exposed to the &lt;code&gt;/etc/letsencrypt/live/&lt;/code&gt; folder. as symbolic links (&lt;a href="https://man7.org/linux/man-pages/man2/symlink.2.html"&gt;symlinks&lt;/a&gt;) without numbers in their names.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;sup&gt;- Symbolic links are interpreted at run time as if the contents of the link had been substituted into the path being followed to find a file or directory. - Symbolic links may contain ..  path components, which (if used at the start of the link) refer to the parent directories of that in which the link resides. - A symbolic link (also known as a soft link) may point to an existing file or to a nonexistent one; the latter case is known as a dangling link..&lt;/sup&gt;&lt;br&gt;
&lt;/p&gt;


&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;root [letsencrypt] $ more /etc/letsencrypt/live/your.domain.name/README 
This directory contains your keys and certificates.

`privkey.pem`  : the private key for your certificate.
`fullchain.pem`: the certificate file used in most server software.
`chain.pem`    : used for OCSP stapling in Nginx &amp;gt;=1.3.7.
`cert.pem`     : will break many server configurations, and should not be used
                 without reading further documentation (see link below).

WARNING: DO NOT MOVE OR RENAME THESE FILES!
         Certbot expects these files to remain in this location in order
         to function properly!

We recommend not moving these files. For more information, see the Certbot
User Guide at https://certbot.eff.org/docs/using.html#where-are-my-certificates.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Coming back to the Docker. We have pulled the image and we would love to run the web app. The problem is that the container needs to read SSL certificates (exposed as symbolic links) from the outside of the Docker virtual container. They are required to run the web app securely via HTTPS. The paths to the key and certificate are provided in the main Node.js app file: &lt;code&gt;index-wall.js&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const server = https.createServer({
    key: fs.readFileSync('/ssl/privkey.pem'),
    cert: fs.readFileSync('/ssl/fullchain.pem')
}, app);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here is how it can not be run with mounted volumes -v ( --volume). &lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ docker run -v /etc/letsencrypt/live/your.domain.name:/ssl -d -p 4444:8080 flaboy/node-wall node index-wall.js&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Docker unfortunately is not able to read symlinks from provided volumes (-v). You can check the error logs this way:&lt;br&gt;
&lt;code&gt;$ docker logs containerid&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;root [letsencrypt] $ docker logs 8d2b81a25359
node:internal/fs/utils:345
    throw err;
    ^

Error: ENOENT: no such file or directory, open '/ssl/privkey.pem'
    at Object.openSync (node:fs:585:3)
    at Object.readFileSync (node:fs:453:35)
    at Object.&amp;lt;anonymous&amp;gt; (/usr/src/app/index-wall.js:18:13)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
    at node:internal/main/run_main_module:17:47 {
  errno: -2,
  syscall: 'open',
  code: 'ENOENT',
  path: '/ssl/privkey.pem'
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  You need to use bind mounts
&lt;/h1&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;What are bind mounts?&lt;/strong&gt;&lt;/em&gt; As per &lt;a href="https://docs.docker.com/storage/bind-mounts/"&gt;Docker documentation&lt;/a&gt;, we can read that:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;[...] Bind mounts have limited functionality compared to volumes. When you use a bind mount, a file or directory on the host machine is mounted into a container. The file or directory is referenced by its absolute path on the host machine. By contrast, when you use a volume, a new directory is created within Docker’s storage directory on the host machine, and Docker manages that directory’s contents.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Detailed instruction on the bind mounts syntax:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;--mount&lt;/strong&gt;: Consists of multiple key-value pairs, separated by commas and each consisting of a &lt;code&gt;&amp;lt;key&amp;gt;=&amp;lt;value&amp;gt;&lt;/code&gt; tuple. - The --mount syntax is more verbose than &lt;code&gt;-v&lt;/code&gt; or &lt;code&gt;--volume&lt;/code&gt;, but the order of the keys is not significant, and the value of the flag is easier to understand.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The type of the mount, which can be bind, volume, or tmpfs. [...] The type is always bind.&lt;/li&gt;
&lt;li&gt;The source of the mount. For bind mounts, this is the path to the file or directory on the Docker daemon host. May be specified as source or src.&lt;/li&gt;
&lt;li&gt;The destination takes as its value the path where the file or directory is mounted in the container. May be specified as destination, dst, or target.&lt;/li&gt;
&lt;li&gt;The readonly option, if present, causes the bind mount to be mounted into the container as read-only.&lt;/li&gt;
&lt;li&gt;The bind-propagation option, if present, changes the bind propagation. May be one of rprivate, private, rshared, shared, rslave, slave.&lt;/li&gt;
&lt;li&gt;The --mount flag does not support z or Z options for modifying selinux labels.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;So let's try to mount 2 cert files (&lt;strong&gt;sources&lt;/strong&gt;):&lt;br&gt;
&lt;code&gt;/etc/letsencrypt/live/your.domain.name/privkey.pem&lt;/code&gt;&lt;br&gt;
and &lt;code&gt;/etc/letsencrypt/live/your.domain.name/fullchain.pem&lt;/code&gt; as they would exist inside docker container inside &lt;code&gt;/ssl/&lt;/code&gt; folder (&lt;strong&gt;target&lt;/strong&gt;).&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ docker run --mount type=bind,source=/etc/letsencrypt/live/your.domain.name/privkey.pem,target=/ssl/privkey.pem --mount type=bind,source=/etc/letsencrypt/live/your.domain.name/fullchain.pem,target=/ssl/fullchain.pem -d -p 4444:8080 flaboy/node-wall node index-wall.js&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Is the app running?&lt;br&gt;
&lt;code&gt;$ docker ps -a&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;9990433c624d   flaboy/node-wall   "docker-entrypoint.s…"   4 minutes ago   Up 4 minutes                 0.0.0.0:4444-&amp;gt;8080/tcp, :::4444-&amp;gt;8080/tcp   hardcore_nash
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Yes! That's all people!
&lt;/h2&gt;

&lt;p&gt;Here is my video on how it did not work properly with -v&lt;br&gt;
&lt;a href="https://www.youtube.com/watch?v=doS0L6nBeKg"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ohz0F_34--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://img.youtube.com/vi/doS0L6nBeKg/0.jpg" alt="Here is how it did not work with -v" width="480" height="360"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And here is working properly with the latest SSL&lt;br&gt;
&lt;a href="https://www.youtube.com/watch?v=1rRZRmLt7s4"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dcSi2AMW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://img.youtube.com/vi/1rRZRmLt7s4/0.jpg" alt="And here is working properly SSL" width="480" height="360"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you would love to play with &lt;a href="https://xr.workwork.fun:4444"&gt;Interactive Wall&lt;/a&gt;, it's deployed to: &lt;a href="https://xr.workwork.fun:4444"&gt;https://xr.workwork.fun:4444&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The app works on Mac, and Windows (you might need also Nintendo &lt;br&gt;
 emulator &lt;strong&gt;&lt;a href="https://dolphin-emu.org/"&gt;Dolphin&lt;/a&gt;)&lt;/strong&gt;. You just need a Chromium-based browser (Edge, Brave, Chrome), also get your &lt;strong&gt;original Wiimote(s) Plus&lt;/strong&gt; (cheap, the third party rather does not work). Do not forget to charge your batteries. Infrared direction calibrator &lt;strong&gt;Mayflash W010 Dolphin Bar&lt;/strong&gt; is necessary, get it from the &lt;a href="https://www.amazon.co.uk/Mayflash-W010-Dolphin-Bar-Wireless/dp/B00HZWEB74"&gt;Amazon&lt;/a&gt;. The WebHID API and amount of Bluetooth devices might be limited on Windows but Bluetooth standard might allow connecting lots of devices so having multiple input devices connected to the web browser interface at the same time is an amazing opportunity for multiplayer experiences without any game-server involved. &lt;em&gt;Just think about this a little bit!&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The Students UI&lt;br&gt;
&lt;a href="https://xr.workwork.fun:4444"&gt;https://xr.workwork.fun:4444&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The Teachers UI (open from provided QR code)&lt;br&gt;
&lt;a href="https://xr.workwork.fun:4444/?u=teacher&amp;amp;p=pass1"&gt;https://xr.workwork.fun:4444/?u=teacher&amp;amp;p=pass1&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OdjgTlLv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/teopgxe6dta37kbkx5op.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OdjgTlLv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/teopgxe6dta37kbkx5op.png" alt="Image description" width="880" height="428"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;More about &lt;strong&gt;5GTours&lt;/strong&gt; project you can find in D4.4 public document on &lt;a href="http://5gtours.eu/deliverables/"&gt;http://5gtours.eu/deliverables/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>pixij</category>
      <category>webhid</category>
      <category>virtualization</category>
    </item>
  </channel>
</rss>
