Skip to content

# Building Docker Images for Reactor

These instructions are a work in progress, and written for those familiar with docker and building images, and I've got my hands full with feature coding and device support, so I will not troubleshoot custom container builds at this time.

DO NOT PUBLISH!

DO NOT publish your image to any repository. It is a violation of the Reactor Software Preview License Agreement to do so. The image you create is for your use alone and may not be disseminated or distributed.

## Files and Prerequisites

You're going to need three files:

1. A Reactor generic release archive, which you can download from the project's MantisBT bug tracker.
2. A Dockerfile to build the image (see below).
3. If you want to use docker-compose to run your image, a docker-compose.yaml file (see below).

You will also need to have docker installed, and if you wish, docker-compose (recommended).

### File: `Dockerfile`

Here's a sample Dockerfile for building your image. You may need to change the base (in `FROM` at the top) for your particular needs. Whatever changes you make, make sure you include nodejs version 14.15 or higher and npm.

    FROM node:alpine

    # Where Reactor lives in the container
    ENV REACTOR_HOME="/opt/reactor"

    # Container stores all variable data under /var/reactor
    ENV REACTOR_DATA_PREFIX="/var/reactor"

    # Default port
    ENV PORT=8111

    # Update node and npm (if you change FROM, you may need to adjust this)
    RUN apk add --no-cache --update nodejs npm

    # Creates directory if doesn't exist
    WORKDIR ${REACTOR_HOME}

    LABEL description="Reactor (Multi-Hub)"
    LABEL version="###BUILDVERSION###"
    LABEL copyright="Copyright (C) 2020-2022 Kedron Holdings LLC, All Rights Reserved"
    LABEL cicd="reactor"

    COPY reactor ./

    RUN rm -rf node_modules && \
        npm set progress=false && \
        npm set depth 0 && \
        npm install --loglevel error --no-save

    WORKDIR ${REACTOR_DATA_PREFIX}
    VOLUME ${REACTOR_DATA_PREFIX}

    EXPOSE ${PORT}
    STOPSIGNAL SIGTERM

    HEALTHCHECK --interval=5m --timeout=15s CMD curl -f http://localhost:${PORT}/api/v1/alive || exit 1

    WORKDIR ${REACTOR_HOME}
    CMD ["node", "app.js"]

### File: `docker-compose.yaml`

This is a prototypical `docker-compose.yaml` file. You will need to modify the entry in the `volumes` section to map the `/var/reactor` directory inside the container to a directory in a writable filesystem where your configuration files and logs can be stored. This allows you to update the docker image without losing your configuration and rule data. The syntax of this line is `your-directorypath:/var/reactor`. Make sure you do not lose the `:/var/reactor` at the end of the line.

docker-compose.yml

    # Multi-System Reactor template docker-compose.yml (version 26168)
    #
    # Change the lines indicated by "DO"...
    #
    version: '3'

    services:
      reactor:
        container_name: reactor
        environment:
          # DO change the TZ: line to set your local time zone.
          # See valid TZ list: https://grokipedia.com/page/List_of_tz_database_time_zones
          TZ: America/New_York

        # DO change the image below to the one you are using (e.g. arm64 for RPi 4/5)
        image: toggledbits/reactor:latest-amd64

        restart: "always"
        expose:
          - 8111
          - 8554
        ports:
          - 8111:8111
          - 8554:8554
        volumes:
            # DO change the /home/username/reactor/ paths below to the directories you created for
            # your local data and extensions; DO NOT change the /var/reactor or /opt/reactor parts
          - /home/username/reactor/data:/var/reactor
          - /home/username/reactor/reactor-ext:/opt/reactor/ext
          - /etc/localtime:/etc/localtime:ro
        tmpfs: /tmp

## Building the Image

1. Create a clean, new directory in which to do the build, and make it your current working directory.

2. Unarchive the Reactor release archive you will use for the build:

       tar -x -v -f reactor-0.1-xxxxx-zzzzzzzz.tar.gz

   You should now have a `reactor` subdirectory in your working directory.

3. Copy the above Dockerfile contents to a file called `Dockerfile-orig`. Make any changes to it you need to before continuing.

4. Stamp the docker file with the release version (on the `LABEL version=` line) and save it to a new file. You can do this by hand with your favorite text editor, or use the `bash` command shown here. The release version can be found in a file called `buildstamp` in the `reactor` subdirectory:

       sed "s/###BUILDVERSION###/$(head -1 reactor/buildstamp)/" <Dockerfile-orig >/tmp/dockerfile

5. Build the image using the stamped dockerfile:

       docker build -f /tmp/dockerfile -t toggledbits/reactor .

6. Before starting your new image/container, make sure you have created the directory that will hold the Reactor configuration, logs, and data. This is the directory named in the `volumes` section of `docker-compose.yaml` for the container's mount point `/var/reactor`. When the Reactor "Getting Started" instructions and other references direct you to either the `logs` or `config` directories, this is the parent directory in which you will find them.

7. At this point, you are ready to create and start your Reactor docker container. If you are using docker-compose:

       docker-compose up -d

DO NOT PUBLISH!

DO NOT publish your image to any repository. It is a violation of the Reactor Software License Agreement to do so. The image you create is for your use alone and may not be disseminated or distributed.

Updated: 2022-May-24