Skip to content

Latest commit

 

History

History
76 lines (60 loc) · 6.67 KB

DEPENDENCIES.md

File metadata and controls

76 lines (60 loc) · 6.67 KB

Quick links : Home - Part 1 - Part 2 - Part 3 - Part 4 - Part 5


Part 5 - Codebase - Dependencies - Config - Backing services - Build, release, run - Processes - Port binding - Concurrency - Disposability - Dev/prod parity - Logs - Admin processes


Explicitly declare and isolate dependencies

Node-RED is similar to Node.js applications here.

All dependencies are specified in the package.json file. When adding additional nodes to the Node-RED pallet, ensure they are added to the package.json file rather than using the pallet management feature within the editor.

However, there are still 'hidden' dependencies that can creep into a project when a package has some native dependencies that need to be installed in the host system running the application.

To get round this the starter project has a Dockerfile which will build the source from the revision control system and build a container containing the application. The Dockerfile captures all hidden dependencies.

The provided Dockerfile in the starter project initially creates a build container to build the required software, then creates an applications image, copying built content from the build container. This way a fully defined build environment is created and used, but the build tooling is not part of the production container image.

The example below uses the new build feature in Docker, which makes it easier to create multi-architecture containers.

Building the application

Before building the app we will add another few nodes to add a Web endpoint, so we can test an app when we have Node-RED deployed in Docker.

  1. Import the following JSON to add the /hello endpoint:

    • to import the flow select the main menu (☰), then the import option from the menu main menu

    • copy and paste the JSON below into the Import nodes window, then press the Import button to import the nodes import nodes

      [{"id":"55dd0376.f7c64c","type":"http in","z":"3af82246.3634ae","name":"","url":"/hello","method":"get","upload":false,"swaggerDoc":"","x":130,"y":420,"wires":[["c656aba7.944288"]]},{"id":"c2380ca8.0463","type":"http response","z":"3af82246.3634ae","name":"","statusCode":"","headers":{},"x":470,"y":420,"wires":[]},{"id":"c656aba7.944288","type":"change","z":"3af82246.3634ae","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"text\":\"Hello\"}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":300,"y":420,"wires":[["c2380ca8.0463"]]}]
    • press the Deploy button to make the new nodes live (you can now access the new endpoint running on your local Node-RED instance http://localhost:1880/hello

  2. Commit and push the change to git

  3. Enable experimental features in Docker:

    • Linux
      • Environment variable DOCKER_CLI_EXPERIMENTAL should be set to enabled
    • MacOS and Windows
      • Start Docker if it is not running
      • Click the Docker icon (usually in bottom notification popup on Windows, top menu bar on MacOS) and select settings or Preferences then the Command Line section. Enable Experimental features
  4. Open a command window then :

    • navigate to your home directory
    • navigate to the .node-red/projects/Node-RED-Docker subdirectory. This directory should contain the Dockerfile.
      You will use the new docker buildx command to build and push a multi-arch image to dockerhub.
  5. Before you can build a container you need to create a new builder. Enter the command:
    docker buildx create --name NRbuilder --use

  6. Inspect the builder with command :
    docker buildx inspect --bootstrap
    which will also start the builder if it is not running. The output of this command will show the target architectures supported by the builder.

  7. You can check you have a builder running using the ls command, which also outputs the list of supported architectures :
    docker buildx ls

  8. Now the builder is up and running you can build a multi-arch container and push it to your dockerhub account. First ensure you are logged into dockerhub :
    docker login

  9. Build and push the image :
    docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t binnes/node-red-docker-sample --push .
    replace binnes with your docker username. Here you see we are asking to build an image for 3 different architectures. AMD/Intel 64 bit, ARM 64bit and ARM 32bit v7 (Raspberry Pi 3/4). You can also add additional architectures, such as linux/s390x to add support for IBM Z systems or linux/ppc64le for IBM POWER systems

  10. Inspect the image using command
    docker buildx imagetools inspect docker.io/binnes/node-red-docker-sample:latest

  11. Stop your local Node-RED using Ctrl-C in the command line window you started Node-RED in, then run the container using command :
    docker run -dit -p 1880:1880 --name dockerNR binnes/node-red-docker-sample:latest

  12. Test your container.

    • You will not be able to launch at the Editor on the base URL, as this has been modified in the sample project settings.js file. The editor can be launched at /admin. In a production Node-RED container you should not be able to alter the application, so the editor needs to be disabled. This can be achieved by setting the httpAdminRoot property in the settings.js file to false. Details of the Node-RED configuration options can be found in the Node-RED documentation.
    • You should be able to access the /hello endpoint
  13. If you have a Raspberry Pi or other ARM 32-bit or ARM 64-bit system you can also test that the ARM containers also work.


Part 5 - Codebase - Dependencies - Config - Backing services - Build, release, run - Processes - Port binding - Concurrency - Disposability - Dev/prod parity - Logs - Admin processes


Quick links : Home - Part 1 - Part 2 - Part 3 - Part 4 - Part 5