diff --git a/Dockerfile b/Dockerfile index d90093e..58d3e9c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,8 +22,14 @@ RUN cmake --build ./build -j 16 --target mo_simulator -j 16 # Grant execute permissions to the shell script RUN chmod +x /MicroOcppSimulator/build/mo_simulator -# Expose port 8000 -EXPOSE 8000 +# Copy pre-built frontend public folder for runtime API configuration +COPY public /public + +# Copy entrypoint script for runtime environment setup +COPY entrypoint.sh /entrypoint.sh +RUN chmod +x /entrypoint.sh -# Run the shell script inside the container +ENTRYPOINT ["/entrypoint.sh"] CMD ["./build/mo_simulator"] + +EXPOSE 8000 diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..0b71a34 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,21 @@ +#!/bin/sh +set -e + +# Runtime API endpoint configuration +TARGET_FILE="./public/bundle.html.gz" +TEMP_HTML="/tmp/bundle.html" + +if [ -z "$API_ROOT" ]; then + echo "[warn] API_ROOT environment variable not detected, frontend will use {{API_ROOT}} placeholder" +else + echo "[info] Runtime replacement: {{API_ROOT}} → $API_ROOT" + # Decompress to temporary file + gzip -d -c "$TARGET_FILE" > "$TEMP_HTML" + # Replace all placeholders + sed -i "s|{{API_ROOT}}|$API_ROOT|g" "$TEMP_HTML" + # Recompress back to original path + gzip -9 -c "$TEMP_HTML" > "$TARGET_FILE" +fi + +# Start the C++ simulator +exec "./build/mo_simulator" \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 0e945fd..56f2aec 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -101,10 +101,20 @@ void load_ocpp_version(std::shared_ptr filesystem) } void app_setup(MicroOcpp::Connection& connection, std::shared_ptr filesystem) { + // Configure charger credentials from environment variables or use defaults + const char *envId = std::getenv("CHARGER_ID"); + const char *envKey = std::getenv("CHARGER_KEY"); + std::string chargerId = envId ? envId : "MicroOcpp Simulator"; + std::string chargerKey = envKey ? envKey : "MicroOcpp"; + + // Log runtime configuration values for debugging + std::cout << "[INFO] Charger ID: " << chargerId << std::endl; + std::cout << "[INFO] Charger Key: " << chargerKey << std::endl; + mocpp_initialize(connection, g_isOcpp201 ? - ChargerCredentials::v201("MicroOcpp Simulator", "MicroOcpp") : - ChargerCredentials("MicroOcpp Simulator", "MicroOcpp"), + ChargerCredentials::v201(chargerId.c_str(), chargerKey.c_str()) : + ChargerCredentials(chargerId.c_str(), chargerKey.c_str()), filesystem, false, g_isOcpp201 ? diff --git a/webapp-src b/webapp-src index 015a0e8..0775451 160000 --- a/webapp-src +++ b/webapp-src @@ -1 +1 @@ -Subproject commit 015a0e816ca4fc617e67acdbe7d067688d6b3939 +Subproject commit 07754510f369e2a71d76b86ad8ee4525458db687