Skip to content

Commit 738e91d

Browse files
authored
Merge pull request #1 from c-jimenez/dev/dockerize_simulators
Now docker is used by default to build the project. DISABLE_DOCKER ma…
2 parents 44cff3b + 930b6e1 commit 738e91d

File tree

7 files changed

+116
-7
lines changed

7 files changed

+116
-7
lines changed

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@ These 3 applications are communicating using the MQTT protocol and the simulated
2121
## Install and build
2222

2323
### Pre-requisites
24+
The project can be be built using ether docker or natively.
25+
26+
### With Docker
27+
Docker must be installed.
28+
29+
Run the makefile target:
30+
```
31+
make docker-build-images
32+
```
33+
34+
### Without Docker
2435

2536
* Open OCPP library (see [Build and installation procedure](https://github.com/c-jimenez/open-ocpp#build))
2637
* [Paho MQTT library](https://www.eclipse.org/paho/) 1.3.8 or greater
@@ -38,7 +49,7 @@ On Debian the pre-requisites (except for Open OCPP) can be installed using the f
3849

3950
```
4051
sudo apt install python3 python3-pip mosquitto libpaho-mqtt-dev
41-
python3 -m pip install kivy paho-mqtt
52+
python3 -m pip install -r requirements.txt
4253
```
4354

4455
### Build options
@@ -55,6 +66,8 @@ An helper makefile is available at project's level to simplify the use of CMake.
5566

5667
```make gcc-native``` or ```make clang-native``` or ```make gcc-native BUILD_TYPE=Debug``` or ```make clang-native BUILD_TYPE=Debug```
5768

69+
The option ```DISABLE_DOCKER=1``` allows to build natively without docker.
70+
5871
This makefile also contains the corresponding cleaning targets :
5972

6073
```make clean-gcc-native``` or ```make clean-clang-native```

docker/Dockerfile

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
FROM debian:bullseye-slim AS open-ocpp-simu-compile
2+
3+
SHELL ["/bin/bash", "-c"]
4+
5+
ARG user=default
6+
ARG group=default
7+
ARG uid=1000
8+
ARG gid=1000
9+
10+
# -y by default for apt-get
11+
RUN echo "APT::Get::Assume-Yes "true";" >> /etc/apt/apt.conf.d/aptconf
12+
13+
14+
RUN apt-get update && apt-get install build-essential clang cmake python3 python3-pip python3-venv wget libpaho-mqtt-dev git openssl libssl-dev sqlite3 libsqlite3-dev\
15+
&& apt-get -q autoremove && rm -rf "/var/lib/apt/lists/*"
16+
17+
RUN git clone https://github.com/c-jimenez/open-ocpp.git
18+
19+
RUN cd open-ocpp && make gcc-native && make install-gcc-native
20+
21+
RUN apt-get update && apt-get install pkg-config && apt-get -q autoremove && rm -rf "/var/lib/apt/lists/*"
22+
23+
# Ensure user exist within container with same uid/gid
24+
RUN groupadd -g ${gid} ${group} && useradd -m -u ${uid} -g ${gid} ${user}
25+
26+
USER ${uid}:${gid}
27+
ENTRYPOINT ["/bin/bash"]

docker/Dockerfile_cp_simulator

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
FROM open-ocpp-simu-compile
2+
3+
ARG simu_user=cp_simu
4+
ARG simu_group=cp_simu
5+
ARG simu_uid=1001
6+
ARG simu_gid=1001
7+
8+
USER root
9+
# Ensure user exist within container with same uid/gid
10+
RUN groupadd -g ${simu_gid} ${simu_group} && useradd -m -u ${simu_uid} -g ${simu_gid} ${simu_user}
11+
RUN mkdir -p /var/chargepoint
12+
RUN chown ${simu_uid}:${simu_gid} /var/chargepoint
13+
COPY gcc_native/config.ini /var/chargepoint/config.ini
14+
RUN chown ${simu_uid}:${simu_gid} /var/chargepoint/config.ini
15+
16+
COPY gcc_native /cp_simulator
17+
18+
USER cp_simu
19+
20+
WORKDIR "/var/chargepoint"
21+
22+
ENTRYPOINT ["/cp_simulator/chargepoint"]

docker/Entrypoint/entrypoint.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
set -e
3+
export PATH=/usr/bin/:$PATH
4+
$1 ${@:2}

makefile

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,39 @@ PARALLEL_BUILD?=-j 4
1515
# Build type can be either Debug or Release
1616
BUILD_TYPE?=Debug
1717

18+
# If set to 1, compilation is done natively on the current os otherwise a dedicated docker container is used to build the project
19+
DISABLE_DOCKER?=0
20+
21+
22+
DOCKER_COMPILE_IMAGE=open-ocpp-simu-compile
23+
24+
1825
# Default target
1926
default: gcc-native
2027

2128
# Silent makefile
22-
.SILENT:
29+
#.SILENT:
2330

2431
# Install prefix
2532
ifneq ($(strip $(INSTALL_PREFIX)),)
2633
CMAKE_INSTALL_PREFIX:=-D CMAKE_INSTALL_PREFIX=$(INSTALL_PREFIX)
2734
CMAKE_INSTALL_PREFIX_CMD:=--prefix $(INSTALL_PREFIX)
2835
endif
2936

37+
38+
INTERACTIVE:=$(shell [ -t 0 ] && echo 1)
39+
ifdef INTERACTIVE
40+
DOCKER_INTERACTIVE=-ti
41+
else
42+
DOCKER_INTERACTIVE=-i
43+
endif
44+
ifeq ($(DISABLE_DOCKER),0)
45+
DOCKER_RUN=docker run $(DOCKER_INTERACTIVE) --rm -v $(ROOT_DIR):$(ROOT_DIR):rw -w $(ROOT_DIR) -e http_proxy="${http_proxy}" -e https_proxy="${https_proxy}" -e no_proxy="${no_proxy}" $(DOCKER_COMPILE_IMAGE) docker/Entrypoint/entrypoint.sh
46+
else
47+
DOCKER_RUN=
48+
endif
49+
50+
3051
# Build/clean all targets
3152
all: gcc-native clang-native
3253
clean: clean-gcc-native clean-clang-native
@@ -38,7 +59,7 @@ GCC_NATIVE_BIN_DIR:=$(BIN_DIR)/gcc_native
3859
gcc-native: $(GCC_NATIVE_BUILD_DIR)/Makefile
3960
@echo "Starting gcc-native build..."
4061
@mkdir -p $(GCC_NATIVE_BIN_DIR)
41-
@make --silent -C $(GCC_NATIVE_BUILD_DIR) $(VERBOSE) $(PARALLEL_BUILD)
62+
${DOCKER_RUN} eval "make --silent -C $(GCC_NATIVE_BUILD_DIR) $(VERBOSE) $(PARALLEL_BUILD)"
4263
@echo "gcc-native build done!"
4364

4465
clean-gcc-native:
@@ -50,7 +71,8 @@ $(GCC_NATIVE_BUILD_DIR)/Makefile:
5071
@echo "Generating gcc-native makefiles..."
5172
@mkdir -p $(GCC_NATIVE_BUILD_DIR)
5273
@mkdir -p $(GCC_NATIVE_BIN_DIR)
53-
@cd $(GCC_NATIVE_BUILD_DIR) && export CC=gcc && export CXX=g++ && cmake -D CMAKE_BUILD_TYPE=$(BUILD_TYPE) -D TARGET=native -D BIN_DIR=$(GCC_NATIVE_BIN_DIR) $(CMAKE_INSTALL_PREFIX) $(ROOT_DIR)
74+
${DOCKER_RUN} eval "cd $(GCC_NATIVE_BUILD_DIR) && CC=gcc CXX=g++ cmake -D CMAKE_BUILD_TYPE=$(BUILD_TYPE) -D TARGET=native -D BIN_DIR=$(GCC_NATIVE_BIN_DIR) $(CMAKE_INSTALL_PREFIX) $(ROOT_DIR)"
75+
5476

5577

5678
# Targets for clang-native build
@@ -59,7 +81,7 @@ CLANG_NATIVE_BIN_DIR:=$(BIN_DIR)/clang_native
5981
clang-native: $(CLANG_NATIVE_BUILD_DIR)/Makefile
6082
@echo "Starting clang native build..."
6183
@mkdir -p $(CLANG_NATIVE_BIN_DIR)
62-
@make --silent -C $(CLANG_NATIVE_BUILD_DIR) $(VERBOSE) $(PARALLEL_BUILD)
84+
@${DOCKER_RUN} eval "make --silent -C $(CLANG_NATIVE_BUILD_DIR) $(VERBOSE) $(PARALLEL_BUILD)"
6385
@echo "clang native build done!"
6486

6587
clean-clang-native:
@@ -71,4 +93,23 @@ $(CLANG_NATIVE_BUILD_DIR)/Makefile:
7193
@echo "Generating clang-native makefiles..."
7294
@mkdir -p $(CLANG_NATIVE_BUILD_DIR)
7395
@mkdir -p $(CLANG_NATIVE_BIN_DIR)
74-
@cd $(CLANG_NATIVE_BUILD_DIR) && export CC=clang && export CXX=clang++ && cmake -D CMAKE_BUILD_TYPE=$(BUILD_TYPE) -D TARGET=native -D _CMAKE_TOOLCHAIN_PREFIX=llvm- -D BIN_DIR=$(CLANG_NATIVE_BIN_DIR) $(CMAKE_INSTALL_PREFIX) $(ROOT_DIR)
96+
@${DOCKER_RUN} eval "cd $(CLANG_NATIVE_BUILD_DIR) && CC=clang CXX=clang++ cmake -D CMAKE_BUILD_TYPE=$(BUILD_TYPE) -D TARGET=native -D _CMAKE_TOOLCHAIN_PREFIX=llvm- -D BIN_DIR=$(CLANG_NATIVE_BIN_DIR) $(CMAKE_INSTALL_PREFIX) $(ROOT_DIR)"
97+
98+
99+
DOCKER_BUILD=docker build --build-arg http_proxy="${http_proxy}" --build-arg https_proxy="${https_proxy}" --build-arg no_proxy="${no_proxy}" --build-arg uid=$$(id -u) --build-arg gid=$$(id -g)
100+
DOCKER_SIMULATOR_IMAGE=open-ocpp-cp-simulator
101+
docker-build-images: docker-build-simu-compile docker-build-cp-simulator
102+
103+
docker-build-simu-compile:
104+
@${DOCKER_BUILD} -f docker/Dockerfile -t $(DOCKER_COMPILE_IMAGE) $(ROOT_DIR)/docker
105+
106+
docker-build-cp-simulator:
107+
@${DOCKER_BUILD} -f docker/Dockerfile_cp_simulator -t $(DOCKER_SIMULATOR_IMAGE) $(ROOT_DIR)/bin/
108+
109+
110+
run-simu:
111+
docker run $(DOCKER_INTERACTIVE) --rm --network=host --name ocpp-simu $(DOCKER_SIMULATOR_IMAGE)
112+
113+
run-launcher:
114+
docker run $(DOCKER_INTERACTIVE) --rm --network=host --name ocpp-launcher --entrypoint /cp_simulator/launcher $(DOCKER_SIMULATOR_IMAGE)
115+

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
kivy
2+
paho-mqtt

src/chargepoint/config/config.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ CallRequestTimeout=2000
1919
ChargeBoxSerialNumber=S/N9876543210
2020
ChargePointModel=Open OCPP Simulated CP
2121
ChargePointSerialNumber=S/N0123456789
22-
ChargePointVendor=Open OCPP
22+
ChargePointVendor=OpenOCPP
2323
FirmwareVersion=0.1
2424
Iccid=
2525
Imsi=

0 commit comments

Comments
 (0)