Skip to content

Commit

Permalink
Extend everest docker image with OCPP 2.0.1 compatibility (#129)
Browse files Browse the repository at this point in the history
* Make build date a optional parameter: --build-date
* Add missing libevent-dev
* Add script to initialize OCPP 2.0.1 device model

This uses the init_device_model_db.py from libocpp and associated files, so copy over the libocpp/config/v201 directory into the resulting image as well

* Add --build-date option to README
* Add .gitignore for logs directory
* Add docker-compose.yml, sample configs for OCPP 2.0.1 and run script
* Add example nodered dockerfile
* Add admin panel ports
* Properly expose admin panel port
* Add --no-ssh parameter

This can remove the "--ssh default" parameter from docker build

* Add --container-runtime parameter

This makes the container runtime used for building and saving the image selectable
Defaults to "docker" but can be used to e.g. select "podman" as well

* Add --additional-cmake-parameters parameter

This allows additional CMake parameters to be passed to the EVerest build

* Add additional log output

This logs the build date, used container runtime and used additional CMake parameters

* Add trap for build error

* Log a error message if the OCPP 2.0.1 config directory could not be copied

* Update Dockerfile from debian 11 to debian 12

* Update readme

---------

Signed-off-by: Kai-Uwe Hermann <[email protected]>
  • Loading branch information
hikinggrass authored Jul 26, 2024
1 parent dc09ddf commit b1d74b3
Show file tree
Hide file tree
Showing 11 changed files with 4,026 additions and 15 deletions.
31 changes: 22 additions & 9 deletions docker/everest-docker-image/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# syntax=docker/dockerfile:1
FROM debian:11 AS builder
FROM debian:12-slim AS builder

ARG REPO
ARG BRANCH
ARG EVEREST_CONFIG
ARG OCPP_CONFIG
ARG ADDITIONAL_CMAKE_PARAMETERS

RUN apt-get update \
&& apt-get install --no-install-recommends -y \
Expand All @@ -20,7 +21,7 @@ RUN apt-get update \
cppcheck \
libboost-all-dev \
maven \
openjdk-11-jdk \
openjdk-17-jdk \
nodejs \
npm \
libsqlite3-dev \
Expand All @@ -29,6 +30,7 @@ RUN apt-get update \
libcurl4-openssl-dev \
libpcap-dev \
libcap-dev \
python3-venv \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

Expand All @@ -43,7 +45,9 @@ RUN ssh-keyscan github.com > ~/.ssh/known_hosts

RUN mkdir -p /workspace/everest/cpm_source_cache
ENV CPM_SOURCE_CACHE="/workspace/everest/cpm_source_cache"

ENV EVEREST_VENV=/workspace/everest/venv
RUN python3 -m venv ${EVEREST_VENV}
ENV PATH="${EVEREST_VENV}/bin:${PATH}"
RUN git clone https://github.com/EVerest/everest-cmake.git
RUN git clone https://github.com/EVerest/everest-utils.git
WORKDIR /workspace/everest/everest-utils/ev-dev-tools
Expand All @@ -54,6 +58,8 @@ WORKDIR /workspace/everest/everest-dev-environment/dependency_manager
RUN python3 -m pip install .
WORKDIR /workspace/everest
RUN git clone https://github.com/EVerest/ext-switchev-iso15118.git
WORKDIR /workspace/everest/ext-switchev-iso15118/
RUN pip install -r requirements.txt

WORKDIR /workspace/everest

Expand All @@ -65,9 +71,11 @@ RUN rm -rf "/workspace/everest/$(basename "${REPO}" .git)/build" && \
git checkout "${BRANCH}" && \
mkdir "/workspace/everest/$(basename "${REPO}" .git)/build" && \
cd "/workspace/everest/$(basename "${REPO}" .git)/build" && \
cmake .. -DEVEREST_BUILD_ALL_MODULES=ON -DCMAKE_INSTALL_PREFIX=/opt/everest && \
cmake .. -DCMAKE_INSTALL_PREFIX=/opt/everest ${ADDITIONAL_CMAKE_PARAMETERS} && \
make -j"$(nproc)" install

# Try to copy the OCPP 2.0.1 config directory to have the init_device_model_db.py script available for (re-)initialization of the device model
RUN cp -R "$(grep -m 1 "ocpp_SOURCE_DIR:STATIC=" "/workspace/everest/$(basename "${REPO}" .git)/build/CMakeCache.txt" | sed "s/ocpp_SOURCE_DIR:STATIC=//")/config/v201" /opt/everest/ocpp201config || echo "Could not copy OCPP 2.0.1 config directory"
RUN mkdir -p /opt/everest/config/user-config
COPY "${EVEREST_CONFIG}" /opt/everest/config/
COPY "${OCPP_CONFIG}" /opt/everest/config/
Expand All @@ -77,11 +85,11 @@ RUN if [ "${OCPP_CONFIG}" != "ocpp-config.json" ]; then mv /opt/everest/config/"
COPY logging.ini /opt/everest/config

# syntax=docker/dockerfile:1
FROM debian:11-slim
FROM debian:12-slim

RUN apt-get update \
&& apt-get install --no-install-recommends -y \
openjdk-11-jre \
openjdk-17-jre \
nodejs \
npm \
python3-pip \
Expand All @@ -90,17 +98,22 @@ RUN apt-get update \
libboost-log1.74.0 \
libboost-chrono1.74.0 \
libboost-system1.74.0 \
libssl1.1 \
libssl3 \
libcurl4 \
libcap2 \
less \
libevent-dev \
python3-venv \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

COPY --from=builder /workspace/everest/ext-switchev-iso15118/requirements.txt ./
RUN pip install --user -r requirements.txt
ENV EVEREST_VENV=/workspace/everest/venv
RUN python3 -m venv ${EVEREST_VENV}
ENV PATH="${EVEREST_VENV}/bin:${PATH}"
COPY --from=builder /workspace/everest/venv /workspace/everest/venv

WORKDIR /opt/everest
COPY --from=builder /opt/everest ./
COPY ./scripts/initialize.sh /opt/everest

CMD [ "/opt/everest/bin/manager", "--conf", "/opt/everest/config/config.yaml" ]
8 changes: 6 additions & 2 deletions docker/everest-docker-image/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ a docker image of everest-core will be created using the given EVerest configura
Specify the following options to create your desired docker image of EVerest:

* repo: Git repository (e.g. https://github.com/EVerest/everest-core.git) - Optional, defaults to: https://github.com/EVerest/everest-core.git
* branch: Git branch or tag name (e.g main or 2022-11.0) - Optional, defaults to: main
* branch: Git branch or tag name (e.g main or 2024.6.0) - Optional, defaults to: main
* conf: Path to EVerest config file (e.g. /home/$(whoami)/checkout/everest-workspace/everest-core/config/ config-sil.yaml) - Required.
* ocpp-conf: Path to EVerest OCPP config file (e.g. /home/$(whoami)/checkout/everest-workspace/libocpp/aux/config-docker.json) - Optional, defaults to: ocpp-config.json
* name: Name of the docker image (e.g everest-core) - Optional, defaults to: everest-core
* build-date: Build date of the docker image, is reflected in its name and can have an effect on caching - Optional, defaults to the current datetime

```bash
./build.sh [--repo <GIT-REPOSITORY>] [--branch <BRANCH-NAME>] [--conf <EVEREST-CONFIG>] [--ocpp-conf <OCPP-CONFIG>] [--name <IMAGE-NAME>]
./build.sh [--repo <GIT-REPOSITORY>] [--branch <BRANCH-NAME>] [--conf <EVEREST-CONFIG>] [--ocpp-conf <OCPP-CONFIG>] [--name <IMAGE-NAME>] [--build-date 2042]
```
Remember to provide an ocpp configuration file if you use an EVerest config that loads the OCPP module. Be aware that the provided OCPP config file will always be named `ocpp-config.json` inside the docker container. Consider this when configuring the OCPP module within the EVerest config and to set the ChargePointConfigPath accordingly.

Expand All @@ -35,3 +36,6 @@ To run the image in a docker container, run the following commands
docker load < <YOUR_IMAGE-TIMESTAMP.tar.gz>
docker run --rm -it --network host <IMAGE_NAME>
```

## Run EVerest with OCPP 2.0.1 in docker
To run EVerest with OCPP 2.0.1 you can use the provided docker-compose.yaml with the example run-config-fallback.sh script
37 changes: 33 additions & 4 deletions docker/everest-docker-image/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,17 @@ usage() {
echo -e "\t--conf: Path to EVerest config file - Required"
echo -e "\t--ocpp-conf: Path to EVerest OCPP config file - Optional, no default"
echo -e "\t--name: Name of the docker image - Optional, defaults to: everest-core"
echo -e "\t--build-date: Build date of the docker image, is reflected in its name and can have an effect on caching - Optional, defaults to the current datetime"
echo -e "\t--no-ssh: Do not append \"--ssh default\" to docker build - Optional"
echo -e "\t--container-runtime: Set container runtime (e.g. docker or podman) for build - Optional"
echo -e "\t--additional-cmake-parameters: Set additional cmake parameters for build - Optional, default \"-DEVEREST_BUILD_ALL_MODULES=ON\""
exit 1
}

ssh_param="--ssh=default"
container_runtime="docker"
additional_cmake_parameters="-DEVEREST_BUILD_ALL_MODULES=ON"

while [ ! -z "$1" ]; do
if [ "$1" == "--repo" ]; then
repo="${2}"
Expand All @@ -26,6 +34,18 @@ while [ ! -z "$1" ]; do
elif [ "$1" == "--branch" ]; then
branch="${2}"
shift 2
elif [ "$1" == "--build-date" ]; then
build_date="${2}"
shift 2
elif [ "$1" == "--no-ssh" ]; then
ssh_param=""
shift 1
elif [ "$1" == "--container-runtime" ]; then
container_runtime="${2}"
shift 2
elif [ "$1" == "--additional-cmake-parameters" ]; then
additional_cmake_parameters="${2}"
shift 2
else
usage
break
Expand Down Expand Up @@ -60,13 +80,22 @@ if [ -z "${branch}" ]; then
branch="main"
fi


NOW=$(date +"%Y-%m-%d-%H-%M-%S")
DOCKER_BUILDKIT=1 docker build \

if [ -n "${build_date}" ]; then
NOW="${build_date}"
fi

echo "Build date: ${NOW}"
echo "Using container runtime \"${container_runtime}\" for building. Version: $(${container_runtime} --version)"
echo "Additional CMake parameters for EVerest build: \"${additional_cmake_parameters}\""
trap 'echo "Build not successful"; exit 1' ERR
DOCKER_BUILDKIT=1 ${container_runtime} build \
--build-arg BUILD_DATE="${NOW}" \
--build-arg REPO="${repo}" \
--build-arg EVEREST_CONFIG="${conf}" \
--build-arg OCPP_CONFIG="${ocpp_conf}" \
--build-arg BRANCH="${branch}" \
-t "${name}" --ssh default .
docker save "${name}":latest | gzip >"$name-${NOW}.tar.gz"
--build-arg ADDITIONAL_CMAKE_PARAMETERS="${additional_cmake_parameters}" \
-t "${name}" "${ssh_param}" .
${container_runtime} save "${name}":latest | gzip >"$name-${NOW}.tar.gz"
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
active_modules:
system:
module: System

x-module-layout: {}
Loading

0 comments on commit b1d74b3

Please sign in to comment.