I got it running with the help of this tutorial Dynamically set Angular Environment Variables in Docker.
I case somebody else wants to run the backend with docker and a configurable UI_WEBSOCKET here are the steps I did.
- Create a
env.jsfile in directory/ui/src/assets/env.jswith following content
(function(window) {
window["env"] = window["env"] || {};
// Environment variables
window["env"]["websocket"] = "ws://localhost:8082";
})(this);
- Create a
env.template.jsfile in directory/ui/src/assets/env.template.jswith following content
(function(window) {
window.env = window.env || {};
// Environment variables
window["env"]["websocket"] = "${UI_WEBSOCKET}";
})(this);
- Adjust file
backend-docker.tsto following
// @ts-strict-ignore
import {Environment} from "src/environments";
import {theme} from "./theme";
window["env"] = window["env"] || {};
export const environment: Environment = {
...theme, ...{
backend: 'OpenEMS Backend',
url: window["env"]["websocket"] || "ws://" + location.hostname + ":8082",
production: true,
debugMode: false,
},
};
- Uncomment Line 13 in following file
index.html. This line should be uncommented
<script src="assets/env.js" onerror="null"></script>
- Adjust the Dockerfile for the UI, add following command at the end of the file
CMD ["/bin/sh", "-c", "envsubst < /usr/share/nginx/html/assets/env.template.js > /usr/share/nginx/html/assets/env.js && exec nginx -g 'daemon off;'"]
- After that build your own docker image as descriped in the
README.
I´m pretty sure this is not the “OpenEMS” way to do it … but it works for me ![]()
Greetings!