Skip to content

feat: enhance multi-container deployment support #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
21 changes: 21 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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"
14 changes: 12 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,20 @@ void load_ocpp_version(std::shared_ptr<MicroOcpp::FilesystemAdapter> filesystem)
}

void app_setup(MicroOcpp::Connection& connection, std::shared_ptr<MicroOcpp::FilesystemAdapter> 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 ?
Expand Down
2 changes: 1 addition & 1 deletion webapp-src