Skip to content
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

Question: Is it possible to use the '--settings' flag for the meteor build process? #5

Closed
CoonHouse opened this issue Sep 22, 2018 · 10 comments

Comments

@CoonHouse
Copy link

Thanks for providing this! It was the first script for me that worked out-of-the-box for creating containerized meteor applications.

For my current project I have an Meteor application that I build with the '--settings' flag. Is it somehow possible to get this done using your docker-file?

Thanks and best regards,

Wilco

@GeoffreyBooth
Copy link
Collaborator

Yes. As noted in the README, you’re meant to copy the example Dockerfile from this repo into your project. You can then edit it however you need, such as to add support for --settings.

Per the docs at https://guide.meteor.com/deployment.html#environment you can pass the settings.json file to production Meteor by setting the stringified JSON as the METEOR_SETTINGS environment variable. So in the example Dockerfile, you could add a line like this just above the ENTRYPOINT line:

RUN export METEOR_SETTINGS="$(cat $APP_BUNDLE_FOLDER/bundle/settings.json)"

@CoonHouse
Copy link
Author

Thanks!
I was already using your docker file, I did not know where to import the settings file.
I got it working now, thanks again.

Wilco

@clemenspeters
Copy link

clemenspeters commented Apr 18, 2020

RUN export METEOR_SETTINGS="$(cat $APP_BUNDLE_FOLDER/bundle/settings.json)"
This was not working for me. 😞

I found a solution on https://medium.com/p/4bccb26f6ff0/responses/show
in package.json:
"scripts": { "start": "METEOR_SETTINGS=$(cat settings.json) node main.js" }

and in the Dockerfile (after copying package.json and settings.json to $APP_BUNDLE_FOLDER/bundle/):
CMD ["npm", "start"]
🙂

@vany0114
Copy link

@clemenspeters would you mind to share your Dockerfile?

@vany0114
Copy link

I was able to run my application using the @clemenspeters workaround (thanks!). However, I see that the console log gets stuck when running the npm run customCommand. Actually I thought it wasn't working and I spent hours trying to find the "error" but when I went to http://localhost:80 it turns out that it was up and running.

Connecting to MongoDB...
(node:6) DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.
Starting app...
> stellaremploydashboard@1.0.0 productionDocker /opt/bundle/bundle
> METEOR_SETTINGS=$(cat settingspdn.json) node main.js

I changed the CMD command for this: CMD npm run ${START_COMMAND}

@GeoffreyBooth any ideas what it could be? it doesn't log anything

@GeoffreyBooth
Copy link
Collaborator

So npm start or npm start <some command> tell npm to spawn the command in a new process. So I would assume that npm remains process 1, and the spawned process is a different process ID; but Docker is capturing the logs only from process 1, and therefore you see no logs from your app. Hence CMD should really be the actual node process that the app runs under and generates logs from, or a shell script that runs node via the exec command (and therefore the new node process takes over PID 1).

The entrypoint.sh in the latest build already has a hook for you to insert custom code. See https://github.com/disney/meteor-base/blob/master/src/docker/entrypoint.sh and the reference to startup.sh. You could implement this by creating a startup.sh that includes

export METEOR_SETTINGS=$(cat settings.json)

and in your Dockerfile add

COPY startup.sh /

@vany0114
Copy link

@GeoffreyBooth That's quite helpful, I'm gonna try it, thanks a lot!

@vany0114
Copy link

@GeoffreyBooth I tried it but didn't work. I copied the startup.sh into $SCRIPTS_FOLDER but it didn't execute it. So I inspected the container and I spotted that the entrypoint.sh is not the same as this one: https://github.com/disney/meteor-base/blob/master/src/docker/entrypoint.sh. This is the one that my container is using:

#!/bin/bash

set -o errexit

cd $SCRIPTS_FOLDER

# Poll until we can successfully connect to MongoDB
echo 'Connecting to MongoDB...'
node <<- 'EOJS'
const mongoClient = require('mongodb').MongoClient;
setInterval(function() {
        mongoClient.connect(process.env.MONGO_URL, function(err, client) {
                if (client) {
                        client.close();
                }
                if (err) {
                        console.error(err);
                } else {
                        process.exit(0);
                }
        });
}, 1000);
EOJS

echo 'Starting app...'
cd $APP_BUNDLE_FOLDER/bundle

exec "$@"

So; I think I'm using the wrong base image, not sure, this is what I have:
FROM geoffreybooth/meteor-base:1.8.1 because I need the 1.8.1 meteor version

@vany0114
Copy link

vany0114 commented Apr 27, 2020

Ok, I made a custom entrypoint script which basically does the same as the original + set the settings according to the environment variable.

@GeoffreyBooth
Copy link
Collaborator

Ok, I made a custom entrypoint script

Glad you figured it out. This is general Docker stuff, not specific to Meteor or this image. Look up "override Docker entrypoint" and you'll find lots of articles on best practices on how to do so.

GeoffreyBooth pushed a commit that referenced this issue Apr 12, 2021
Merge pull request #67 from antwaremx/master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants