Skip to content

How can set a client config through Dockerfile #208

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

Closed
maryam4s26 opened this issue Dec 25, 2023 · 6 comments
Closed

How can set a client config through Dockerfile #208

maryam4s26 opened this issue Dec 25, 2023 · 6 comments
Labels
question Further information is requested

Comments

@maryam4s26
Copy link

maryam4s26 commented Dec 25, 2023

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

ENV session_timeout=600000

Also, according to Osjs document , we should be able to use this parameter in the client configuration.

src/client/config.js

export default {
  sessionTimeout: process.env.session_timeout,
};

But unfortunately I get undefined value in client in such situation.

@andersevenrud
@ajmeese7

@maryam4s26 maryam4s26 changed the title How can set a client config through docker file How can set a client config through Dockerfile Dec 25, 2023
@andersevenrud
Copy link
Member

Try something like dotenv-webpack. This works with both dotenv file and global variables (with docker).

@andersevenrud
Copy link
Member

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.

@mahsashadi
Copy link
Contributor

mahsashadi commented Dec 26, 2023

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
   ...

@andersevenrud
Copy link
Member

andersevenrud commented Dec 26, 2023

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'
    }
  }
};

@mahsashadi
Copy link
Contributor

mahsashadi commented Dec 27, 2023

Many Thanks

@andersevenrud
Copy link
Member

Closing because this should be resolved.

@andersevenrud andersevenrud added the question Further information is requested label Jan 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants