... | ... | @@ -10,14 +10,39 @@ I chose a multistage approach. |
|
|
This means first in a dedicated container all dependencies get resolved and files compiled.
|
|
|
They are copied to a second container which serves the purpose of the runtime environment.
|
|
|
|
|
|
### General Configuration
|
|
|
|
|
|
```Dockerfile
|
|
|
ARG MVN_IMAGE=arm32v7/maven:3-eclipse-temurin-11
|
|
|
```
|
|
|
Here we define a build argument named `MVN_IMAGE`.
|
|
|
The argument defines which image is to be used in the [build stage](#build-stage).
|
|
|
Because we maybe want to build on the Raspberry Pis (`armv7` architecture) we can't just use the default [Apache Maven container](https://hub.docker.com/_/maven).
|
|
|
But we can use a [port for `armv7`](https://hub.docker.com/r/arm32v7/maven/).
|
|
|
|
|
|
If you want to build the container on your own `amd64` or `x86` machine you have to choose another image, eg. the [official Apache Maven image](https://hub.docker.com/_/maven).
|
|
|
You can do this by adding `--build-arg MVN_IMAGE=maven:3-jdk-11-slim` to the [`docker build` command](#building-the-container) or the `docker-compose` configuration.
|
|
|
|
|
|
**Be sure to always use an image that uses Java 11!**
|
|
|
|
|
|
```Dockerfile
|
|
|
ARG JRE_IMAGE=eclipse-temurin:11-jre
|
|
|
```
|
|
|
This does the same as above and the defined argument is used as image in the [runtime stage](#runtime-stage).
|
|
|
The image defined as default should work fine on `armv7`, `amd64` and `x86` systems, so you probably wont need to change it.
|
|
|
If you still want to use another image you can add `--build-arg MVN_IMAGE=your_image` to the [`docker build` command](#building-the-container) or the `docker-compose` configuration.
|
|
|
|
|
|
**Be sure to always use an image that provides the JRE 11!**
|
|
|
The JDK is not necessary.
|
|
|
|
|
|
### Build Stage
|
|
|
|
|
|
```Dockerfile
|
|
|
FROM maven:3-jdk-11-slim as build
|
|
|
FROM $MVN_IMAGE as build
|
|
|
```
|
|
|
In the first line is defined which container we use for our (build) stage.
|
|
|
In this line is defined which container we use for the build stage.
|
|
|
The `as build` names the stage.
|
|
|
Because the project uses Maven as dependency manager and Java 11 as the version we use the [Apache Maven container](https://hub.docker.com/_/maven) with the tag (a tag is like a version) `3-jdk-11-slim`.
|
|
|
For more info read [above](#general-configuration).
|
|
|
|
|
|
```Dockerfile
|
|
|
WORKDIR /root/app
|
... | ... | @@ -60,9 +85,9 @@ It follows the container definition for our final container. |
|
|
### Runtime Stage
|
|
|
|
|
|
```Dockerfile
|
|
|
FROM openjdk:11-jre
|
|
|
FROM $JRE_IMAGE
|
|
|
```
|
|
|
For this container, we use the [OpenJDK container](https://hub.docker.com/_/openjdk) as the base. And because everything is already compiled we only need the `jre` variant.
|
|
|
For this container, we use the base image defined by the `JRE_IMAGE` argument defined in the [general configuration](#general-configuration).
|
|
|
|
|
|
```Dockerfile
|
|
|
WORKDIR /root/app
|
... | ... | @@ -104,10 +129,14 @@ To build the container change the working directory to the `basyx.lichterkette` |
|
|
The tag `basyx-lichterkette` can be anything.
|
|
|
If you change it, be sure to replace the tag name in any following command in this documentation.
|
|
|
|
|
|
To change the used images for the build and runtime stages, add `--build-args MVN_IMAGE=...` and/or `build-args JRE_IMG=...` to the build command.
|
|
|
|
|
|
It is also possible to use `docker-compose` to build the container.
|
|
|
```console
|
|
|
# docker-compose [-f filename.yml] build
|
|
|
```
|
|
|
To change the used images for in the build with `docker-compose`, you have to add the arguments to the config.
|
|
|
See [here](https://docs.docker.com/compose/compose-file/compose-file-v3/#args) how to do this.
|
|
|
|
|
|
## Running the Container
|
|
|
### Components without GPIO Access
|
... | ... | @@ -115,10 +144,11 @@ It is also possible to use `docker-compose` to build the container. |
|
|
Starting the container for any component that does not need access to the GPIO pins of the Raspberry Pi is straightforward:
|
|
|
|
|
|
```console
|
|
|
# docker run -d -e COMPONENT=registry basyx-lichterkette
|
|
|
# docker run -d -e COMPONENT=registry -e PORT=4000 -e ... basyx-lichterkette
|
|
|
```
|
|
|
- `-d` detaches the container, if you want to run it in the foreground omit it.
|
|
|
- `-e COMPONENT=registry` sets the environment variable `COMPONENT`. **This determines which component is started, be sure to set it to the correct component!**
|
|
|
- `-e ...` sets all other environment variables. See the [run_demo.sh documentation](implementation/run_demo.sh) for more information.
|
|
|
|
|
|
#### Stopping the Container
|
|
|
If you run the container in the foreground just press `Ctrl+C`.
|
... | ... | @@ -139,12 +169,13 @@ For the other components, Docker needs access to the system resources of the Ras |
|
|
The easiest way to do this (and the only one I found working) is to use the following command:
|
|
|
|
|
|
```console
|
|
|
# docker run -d -e COMPONENT=lights -v "/usr/bin/raspi-gpio:/bin/raspi-gpio" --privileged basyx-lichterkette
|
|
|
# docker run -d -e COMPONENT=lights -e PORT=4005 -e ... -v "/usr/bin/raspi-gpio:/bin/raspi-gpio" --privileged basyx-lichterkette
|
|
|
```
|
|
|
- `-d` same as above
|
|
|
- `-e COMPONENT=lights` same as above
|
|
|
- `-v "/usr/bin/raspi-gpio:/bin/raspi-gpio"` mounts the `raspi-gpio` executable inside the container. **You have to have `raspi-gpio` installed on the host system!**
|
|
|
- `--privileged` ensures access to host devices (eg. GPIO)
|
|
|
- `-e ...` sets all other environment variables. See the [run_demo.sh documentation](implementation/run_demo.sh) for more information.
|
|
|
|
|
|
For how to stop the container see above.
|
|
|
|
... | ... | |