... | ... | @@ -45,6 +45,13 @@ If you still want to use another image you can add `--build-arg MVN_IMAGE=your_i |
|
|
**Be sure to always use an image that provides the JRE 11!**
|
|
|
The JDK is not necessary.
|
|
|
|
|
|
```Dockerfile
|
|
|
ARG IS_SENSOR
|
|
|
```
|
|
|
In this line we create an empty variable called `IS_SENSOR`.
|
|
|
If any value for this variable is set in the build arguments it will install the necessary packages for handling the sensors.
|
|
|
By leaving it empty it will just install the requirements for Java and MQTT.
|
|
|
|
|
|
### Build Stage
|
|
|
|
|
|
```Dockerfile
|
... | ... | @@ -105,12 +112,15 @@ WORKDIR /root/app |
|
|
Again, this sets the current working directory inside the container.
|
|
|
|
|
|
```Dockerfile
|
|
|
RUN apt-get update && apt-get install -y mosquitto-clients libgpiod2 python3 python3-pip && rm -rf /var/lib/apt/lists/*
|
|
|
RUN apt-get update && if [[ -z "$IS_SENSOR" ]]; then apt-get install -y mosquitto-clients; else apt-get install -y mosquitto-clients libgpiod2 python3 python3-pip build-essential python3-dev gpiod; fi && rm -rf /var/lib/apt/lists/*
|
|
|
```
|
|
|
Here all necessary dependencies we may use later.
|
|
|
If the `IS_SENSOR` argument is set in the build arguments many Python packages are installed to communicate with GPIO and the sensors.
|
|
|
Else only `mosquitto-clients` is installed to communicate with the MQTT broker.
|
|
|
- `mosquitto-clients`: used for communication with out mqtt server
|
|
|
- `libgpiod2`: GPIO library
|
|
|
- `python3` & `python3-pip`: our sensors use Python scripts, so we need Python too. Pip because we want to install some packages.
|
|
|
- `build-essential` & `python3-dev` & `gpiod`: when installing some pip-packages some of them require these to build.
|
|
|
|
|
|
```Dockerfile
|
|
|
COPY --from=build /root/.m2 /root/.m2
|
... | ... | @@ -121,9 +131,9 @@ Here all files we need from the build stage are copied to our container. |
|
|
|
|
|
```Dockerfile
|
|
|
COPY ./docker-scripts/requirements.txt requirements.txt
|
|
|
RUN python3 -m pip install -r requirements.txt && rm requirements.txt
|
|
|
RUN if [[ -z "$IS_SENSOR" ]]; then python3 -m pip install -r requirements.txt; fi && rm requirements.txt
|
|
|
```
|
|
|
Here the Python packages from the `requirements.txt` are installed.
|
|
|
Here the Python packages from the `requirements.txt` are installed but only if `IS_SENSOR` is set.
|
|
|
|
|
|
```Dockerfile
|
|
|
COPY ./docker-scripts/sensors ./sensor-scripts
|
... | ... | |