Closed maryam4s26 closed 9 months ago
Try something like dotenv-webpack. This works with both dotenv file and global variables (with docker).
You can also just have a pre-made config file and copy this into your docker image, or set up a dotenv file before building in the dockerfile.
Hi @andersevenrud
Actually we need to pass the value from docker-compose.yml
file.
For example if we config webpack plugins as below:
new Dotenv({
path: './client.env'
}),
The value is not known in this client.env
, and It will be passed when the container is made through docker-compose
file
// ./client.env
SESSION_EXPIRY_TIMEOUT= process.env.my_yml_env
// ./docker-compose.yml
....
environment:
- my_yml_env = 60000
...
I think there might be an issue with the Webpack version. Did a quick test, and I had to do the following.
My variable was now exposed to the client on build time and was resolved correctly.
# docker-compose.yaml
version: '3'
services:
osjs:
user: node
build:
context: .
volumes:
- .:/usr/src/osjs
ports:
- "${OSJS_NODE_PORT:-8000}:8000"
environment:
- MY_VARIABLE=foo
// webpack.config.js
//...
module.exports = {
plugins: [
// ...
// Standard env variables + explicitly the ones I want
new webpack.EnvironmentPlugin(['NODE_ENV', 'DEBUG', 'MY_VARIABLE']),
// ...
]
}
// config.js
export default {
myVariable: process.env.MY_VARIABLE, // = "foo"
auth: {
login: {
username: 'demo',
password: 'demo'
}
}
};
Many Thanks
Closing because this should be resolved.
How can I set a client config through Dockerfile or docker compose file?
According to the description in the Docker document, we should be able to define a runtime variable using ENV in the Docker file.
Dockerfile
Also, according to Osjs document , we should be able to use this parameter in the client configuration.
src/client/config.js
But unfortunately I get undefined value in client in such situation.
@andersevenrud @ajmeese7