Closed hussam-qasem closed 2 years ago
you can override the users without extending the image simply mounting a volume (-v
docker option)
docker run --rm -p 8080:8080 --name restheart \
-e MONGO_URI="mongodb+srv://dbUser:SECRET@cluster0.xyz.mongodb.net/?retryWrites=true&w=majority" \
-v /local/path/users.yml:/opt/restheart/etc/users.yml \
softinstigate/restheart:6.1.2
@mkjsix can you help on the env variable, seems that it does not pick it up
so the env variable to set is
RH_MONGO_URI
as follows:
Thank you @ujibang for the prompt response. I don't believe this is the correct variable. RH_MONGO_URI
now overrides MONGO_URI
, and I'm unable to connect to MongoDB:
11:21:23.323 [main] WARN o.r.m.MongoServiceConfiguration - >>> Found environment variable 'RH_MONGO_URI': overriding parameter 'mongo-uri' with value '/thinkpink'
11:21:23.328 [main] ERROR org.restheart.plugins.PluginsFactory - Error injecting dependency to Initializer mongoInitializer: The connection string is invalid. Connection strings must start with either 'mongodb://' or 'mongodb+srv://
java.lang.reflect.InvocationTargetException: null
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
Caused by: org.restheart.ConfigurationException: wrong parameter mongo-uri
at org.restheart.mongodb.MongoServiceConfiguration.<init>(MongoServiceConfiguration.java:217)
Caused by: java.lang.IllegalArgumentException: The connection string is invalid. Connection strings must start with either 'mongodb://' or 'mongodb+srv://
at com.mongodb.ConnectionString.<init>(ConnectionString.java:290)
yes @hussam-qasem I misunderstood the problem you reported and deleted my answer!
we are looking into it, your need is clearly to override root-mongo-resource
with an env variable
mongo-mounts:
- what: {{{root-mongo-resource}}}
where: /
we are looking into it, your need is clearly to override
root-mongo-resource
with an env variable
Yes, than you! 🙏🏻
Found the problem:
from https://restheart.org/docs/setup/#environment-variables
It is possible to override any primitive type parameter in restheart.yml with environment variables.
since mongo-mounts
is not a primitive type, you cannot override it with an env var.
However we can easily extend RH to cope with it. We will add this to next release...
As a workaround, you can override the /opt/restheart/etc/restheart.yml
configuration file with docker volumes.
Thank you @ujibang.
Hi,
to this day it is still not possible to override the root-mongo-resource parameter via environment.
Was it planned or did it remain in the limbo of GH issues? :)
Hi @rdonadono
we actually implemented the new configuration override right after your issue but it will be available on RH 7.
The good news is that yesterday we finished all planned new features and going to release RH 7 soon, we just need to do some testing and update the documentation 😩.
You can read about it on https://github.com/SoftInstigate/restheart/discussions/425 (search for "New way to override configuration options with environment variables" in the page)
In short, RESTHeart v7 comes with a default configuration (you can avoid to have a configuration file) and can change it via the RHO
env variable as follows:
$ RHO='/mongo-uri->"mongodb://127.0.0.1";/mongo-mounts[1]->'{"where: "/api", "what": "mydb"}' java -jar restheart.jar
Of course you can still use a configuration file.
Be aware that RH7 has a new configuration file format: https://github.com/SoftInstigate/restheart/blob/master/core/src/main/resources/restheart-default-config.yml
Finally you can try v7 snapshot release
$ docker run -it --rm -p "8080:8080" --env RHO='/mclient/connection-string->"mongodb://host.docker.internal";/http-listener/host->"0.0.0.0";/mongo/mongo-mounts[1]->{"where": "/api", "what": "restheart"}' softinstigate/restheart-snapshot:latest
Note the RHO env var:
RHO='/mclient/connection-string->"mongodb://host.docker.internal";/http-listener/host->"0.0.0.0";/mongo/mongo-mounts[1]->{"where": "/api", "what": "restheart"}'
It defines 3 overrides
/mclient/connection-string->"mongodb://host.docker.internal"
/http-listener/host->"0.0.0.0"
/mongo/mongo-mounts[1]->{"where": "/api", "what": "restheart"}'
You can even add an object to the configuration (so not just overriding), e.g.
/mongo/mongo-mounts[2]->{"where": "/cool", "what": "anotherDb"}'
In the log, you'll see:
09:20:14.233 [main] INFO o.r.configuration.Configuration - Overriding configuration parameters from RHO environment variable:
09:20:14.234 [main] INFO o.r.configuration.Configuration - /mclient/connection-string -> mongodb://host.docker.internal
09:20:14.234 [main] INFO o.r.configuration.Configuration - /http-listener/host -> 0.0.0.0
09:20:14.234 [main] INFO o.r.configuration.Configuration - /mongo/mongo-mounts[1] -> Document{{where=/api, what=restheart}}
09:20:14.235 [main] INFO o.r.configuration.Configuration - /mongo/mongo-mounts[2] -> Document{{where=/cool, what=anotherDb}}
......
09:20:15.835 [main] INFO org.restheart.mongodb.MongoService - URI /api bound to MongoDB resource restheart
09:20:15.835 [main] INFO org.restheart.mongodb.MongoService - URI /cool bound to MongoDB resource anotherDb
RH7 is out. Read about using the new RHO
to override any conf parameter. https://restheart.org/docs/configuration
Beware that the configuration file is now optional and that the format changed
I'm attempting to override the default
/restheart
db by setting aROOT_MONGO_RESOURCE
environment variable.Expected Behavior
URI
/
bound to MongoDB resource other than/restheart
- specified by the$ROOT_MONGO_RESOURCE
env variable.Current Behavior
URI
/
bound to MongoDB resource/restheart
.Context
I am trying to override the default values without extending the Docker image. I tried the following env variables:
$ROOT_MONGO_RESOURCE
$RH_ROOT_MONGO_RESOURCE
$RESTHEART_ROOT_MONGO_RESOURCE
Steps to Reproduce
Run the Docker image:
Current output
As seen in the last line above, MongoDB resource/db
restheart
is created, ignoring the environment variables.Additional question
It would be great if I could also override default passwords in
etc/users.yml
without extending the image.