Git Product home page Git Product logo

Comments (10)

clemenspeters avatar clemenspeters commented on July 28, 2024 3

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"]
πŸ™‚

from meteor-base.

GeoffreyBooth avatar GeoffreyBooth commented on July 28, 2024 1

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 /

from meteor-base.

GeoffreyBooth avatar GeoffreyBooth commented on July 28, 2024

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)"

from meteor-base.

CoonHouse avatar CoonHouse commented on July 28, 2024

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

from meteor-base.

vany0114 avatar vany0114 commented on July 28, 2024

@clemenspeters would you mind to share your Dockerfile?

from meteor-base.

vany0114 avatar vany0114 commented on July 28, 2024

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...
> [email protected] 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

from meteor-base.

vany0114 avatar vany0114 commented on July 28, 2024

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

from meteor-base.

vany0114 avatar vany0114 commented on July 28, 2024

@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

from meteor-base.

vany0114 avatar vany0114 commented on July 28, 2024

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

from meteor-base.

GeoffreyBooth avatar GeoffreyBooth commented on July 28, 2024

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.

from meteor-base.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.