R
Railwayβ€’13mo ago
Louis.L

MongoDB with volume fails to authenticate after duplication (environment creation)

Hello there, When i create a new environment, already containing a MongoDB instance on the main env, it tries to duplicates it, without any ENV Variables (?), and once i import all the variables from de main environment, the MongoDB instance fails to authenticate (on the "Data" tab of the MongoDB service). I'm a bit confused of the "duplication" behavior, without env vars, and i don't understand why it does not work after i import the variables as well. Thanks for helping !
No description
No description
No description
Solution:
- in the main environment's mongodb service set a service variable MONGO_DBPATH to ${{RAILWAY_VOLUME_MOUNT_PATH}} - cancel the popup - in the mongodb service settings set this start command /bin/sh -c "docker-entrypoint.sh mongod --dbpath ${MONGO_DBPATH} --ipv6 --bind_ip ::,0.0.0.0" - don't cancel the popup - create your new environment in the projects settings...
Jump to solution
21 Replies
Percy
Percyβ€’13mo ago
Project ID: fa4f3b3c-8eb7-43a6-a995-0619ad7c212c
Louis.L
Louis.LOPβ€’13mo ago
fa4f3b3c-8eb7-43a6-a995-0619ad7c212c
Brody
Brodyβ€’13mo ago
if you want to create a duplicate environment with all variables the same, you want to use forked environments https://docs.railway.app/develop/environments#forking-and-merging-environments
Louis.L
Louis.LOPβ€’13mo ago
Thanks for the reply, i'm not really looking to completely "clone" my environment, just create independant environments "prod, dev, preprod", with the same architecture but with their own data. The problem is the behavior of the MongoDB service with i create a new environment, would you be alright to explain what I need to do with the variables to make it work ?
Brody
Brodyβ€’13mo ago
though i understand they confusion, the reason why the database couldn't be connected to even after adding all the variables back to it is likely because it was already deployed and initialized itself with no variables, this seems like it messed something up internally in the container. in my opinion that flow should not auto deploy anything and instead ask you to setup the variables and then give you a deploy now button for when you have all variables setup
Louis.L
Louis.LOPβ€’13mo ago
Alright ! Thats what i was testing and it seems to be the case, because i also have a volume connected to the service. Problem is if i decide to delete the volume to restart the deployment with the variables, the volumes of all the other environments get deleted as well πŸ˜‚ Is there a possibility to reset a volume on one environment only ?
Brody
Brodyβ€’13mo ago
let me see if i can come up with a flow to solve this
Louis.L
Louis.LOPβ€’13mo ago
The solution i came up with is to stop de deployment as fast as possible to not write anything on the partition, then import the variables, then re-deploy
Brody
Brodyβ€’13mo ago
thats what im thinking, but doing that is hard, docker images deploy fast and mongo could write garbage to the volume before you are able to abort
Louis.L
Louis.LOPβ€’13mo ago
It would be great to have a "Deploy" button floating top right (or any other place) on the dashboard, to click when the user finish to setup the environment Yes, had to do it 3 times before a success
Brody
Brodyβ€’13mo ago
yeah and not have anything auto deploy, because 9 times out of 10 (made up number) a service will fail without any variables set
Louis.L
Louis.LOPβ€’13mo ago
Thanks for the help ! Can I mark this thread as solved ?
Brody
Brodyβ€’13mo ago
not solved yet, i havent come up with a flow that works every time yet
Louis.L
Louis.LOPβ€’13mo ago
Oh you are still on it, thanks !
Brody
Brodyβ€’13mo ago
of course
Solution
Brody
Brodyβ€’13mo ago
- in the main environment's mongodb service set a service variable MONGO_DBPATH to ${{RAILWAY_VOLUME_MOUNT_PATH}} - cancel the popup - in the mongodb service settings set this start command /bin/sh -c "docker-entrypoint.sh mongod --dbpath ${MONGO_DBPATH} --ipv6 --bind_ip ::,0.0.0.0" - don't cancel the popup - create your new environment in the projects settings - the mongodb service in this new environment will crash after a bit, thats expected - import all the variables one by one and cancel the redeploy popup on every variable import except the very last - once the service redeploys from adding the last variable everything should work as expected
Brody
Brodyβ€’13mo ago
certainly not very good dx, but it does work every time @Melissa - room for dx improvements when creating new environments
Louis.L
Louis.LOPβ€’13mo ago
Alright so if i understand well, the env var added to the docker entrypoint serve as a test to fail if the env vars are not imported great solution !
Brody
Brodyβ€’13mo ago
yeah more or less, not pretty but it works
Melissa
Melissaβ€’13mo ago
thanks both, apologies for the poor DX in the current state. we are working to make this experience better! i have referenced this thread in that project
Louis.L
Louis.LOPβ€’13mo ago
Thanks a lot ! It's already insane that the UX of railway is better that GCP xd
Want results from more Discord servers?
Add your server