jshimko / meteor-launchpad

A base Docker image for Meteor applications.
https://hub.docker.com/r/jshimko/meteor-launchpad/
MIT License
276 stars 152 forks source link

Is there proper way to pass meteor settings json file to docker container? #15

Closed yurist38 closed 8 years ago

yurist38 commented 8 years ago

Hi! Thanks for this docker image, the only working with latest meteor I've found... Tell me please, do you know how can I easily pass settings json file to my container on build step? I've found this one https://github.com/meteorhacks/meteord/issues/16 but it looks so terrible to me :see_no_evil: Thanks a lot!

jshimko commented 8 years ago

Do you need the settings file at build time? I think what you're looking for is run time. In that case, you can stringify the settings.json and set it as a METEOR_SETTINGS environment variable.

echo $(cat settings.json) 

Or if you're on a Mac, you can send that straight to your clipboard with...

echo $(cat settings.json) | pbcopy

Then just set METEOR_SETTINGS to the string value you get from that (don't forget to surround the whole string with single quotes).

That said, because Docker is the only deployment solution I use and I don't want to always deal with the above steps, I try avoid using the Meteor settings API in my apps and instead insert my configurations with environment variables. Certainly not a right/wrong thing, but I find it much easier to not be tied to an API that can't easily be manipulated at run time. Environment variables are a much more universally supported solution for injecting configuration values.

But... perhaps I should add a little magic in this container to read Meteor settings files at build time and set that var for you. Perhaps the file location could be specified by an environment variable like METEOR_SETTINGS_FILE and then a script in the container can turn that into the METEOR_SETTINGS var for you.

Let me get back to you on that. In the meantime, you have the above stringify option to get you up and running.

yurist38 commented 8 years ago

Thanks for so detailed response! :+1: I've tried to use METEOR_SETTINGS_FILE and METEOR_SETTINGS_PATH but seems like nothing works on runtime. So I'm using this way now:

export METEOR_SETTINGS=$(cat /path/to/settings.json)
docker run -d \
    ...
    -e METEOR_SETTINGS="$METEOR_SETTINGS" \
    ...

It works for me. Probably will keep it. Thanks again. Issue can be closed I think...

jshimko commented 8 years ago

METEOR_SETTINGS_FILE and METEOR_SETTINGS_PATH don't exist. I was just saying that something like that could be a possible option in the future so you could just add one line to your Dockerfile. Something like...

FROM jshimko/meteor-launchpad:latest

ENV METEOR_SETTINGS_FILE /path/to/settings.json

By the way, you probably could've done your above example in one step.

docker run -d \
    -e METEOR_SETTINGS="$(cat /path/to/settings.json)" \
    ...
jonasscherer commented 6 years ago

Is there a way to provide a settings file at build time right now? METEOR_SETTINGS_FILE is not implemented yet, right?

jshimko commented 6 years ago

Meteor settings doesn't get used at build time and an app container should never contain state or private configs. You should pass any state or configuration in at run time with environment variables. See the examples above.

docker run -d  -e METEOR_SETTINGS="$(cat /path/to/settings.json)" ...