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

Support npm that require node-gyp #75

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ ONBUILD ENV APT_GET_INSTALL $APT_GET_INSTALL
ONBUILD ARG NODE_VERSION
ONBUILD ENV NODE_VERSION ${NODE_VERSION:-8.9.0}

ONBUILD ARG INSTALL_NODEGYP
ONBUILD ENV INSTALL_NODEGYP $INSTALL_NODEGYP

ONBUILD ARG NPM_TOKEN
ONBUILD ENV NPM_TOKEN $NPM_TOKEN

Expand All @@ -56,6 +59,7 @@ ONBUILD COPY . $APP_SOURCE_DIR
ONBUILD RUN cd $APP_SOURCE_DIR && \
$BUILD_SCRIPTS_DIR/install-deps.sh && \
$BUILD_SCRIPTS_DIR/install-node.sh && \
$BUILD_SCRIPTS_DIR/install-nodegyp.sh && \
$BUILD_SCRIPTS_DIR/install-phantom.sh && \
$BUILD_SCRIPTS_DIR/install-graphicsmagick.sh && \
$BUILD_SCRIPTS_DIR/install-mongo.sh && \
Expand Down
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ There are several parts of a Meteor development environment that you don't need
.git
.meteor/local
node_modules
packages/*/.git
packages/*/.npm
```

### Run
Expand Down Expand Up @@ -55,7 +57,7 @@ docker run -d \

### Build Options

Meteor Launchpad supports setting custom build options in one of two ways. You can either create a launchpad.conf config file in the root of your app or you can use [Docker build args](https://docs.docker.com/engine/reference/builder/#arg). The currently supported options are to install PhantomJS, GraphicsMagick, MongoDB, or any list of `apt-get` dependencies (Meteor Launchpad is built on `debian:jesse`).
Meteor Launchpad supports setting custom build options in one of two ways. You can either create a launchpad.conf config file in the root of your app or you can use [Docker build args](https://docs.docker.com/engine/reference/builder/#arg). The currently supported options are to install PhantomJS, GraphicsMagick, MongoDB, node-gyp, or any list of `apt-get` dependencies (Meteor Launchpad is built on `debian:jesse`).

If you choose to install Mongo, you can use it by _not_ supplying a `MONGO_URL` when you run your app container. The startup script will then start Mongo inside the container and tell your app to use it. If you _do_ supply a `MONGO_URL`, Mongo will not be started inside the container and the external database will be used instead.

Expand All @@ -82,6 +84,7 @@ NODE_VERSION=8.9.0
INSTALL_MONGO=true
INSTALL_PHANTOMJS=true
INSTALL_GRAPHICSMAGICK=true
INSTALL_NODEGYP=true
```

**Option #2 - Docker Build Args**
Expand All @@ -104,6 +107,27 @@ You can provide your [NPM auth token](http://blog.npmjs.org/post/118393368555/de
docker build --build-arg NPM_TOKEN="<your token>" -t myorg/myapp:latest .
```

## Installing Private Meteor Packages

You can provide private Meteor packages by copying them to the [`packages/`](https://guide.meteor.com/writing-atmosphere-packages.html#local-packages) folder per the standard Meteor docs. Please note the recommended `.dockerignore` for Meteor Launchpad excludes the `packages/<package>/.npm` directory.

```
MeteorApp
├──.meteor
├──client
├──server
├──packages
| |--privatePackage1
| | ├──.npm
| | └─ <stuff>
| └--privatePackage2
| ├──.npm
| └─ <stuff>
├── <etc>
├──package.json
└──launchpad.conf
```

## Development Builds

You can optionally avoid downloading Meteor every time when building regularly in development. Add the following to your Dockerfile instead...
Expand Down
32 changes: 20 additions & 12 deletions dev.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ ENV BUILD_SCRIPTS_DIR /opt/build_scripts
COPY scripts $BUILD_SCRIPTS_DIR
RUN chmod -R 750 $BUILD_SCRIPTS_DIR

# install base dependencies, build app, cleanup
RUN bash $BUILD_SCRIPTS_DIR/install-deps.sh && \
bash $BUILD_SCRIPTS_DIR/post-install-cleanup.sh
RUN bash $BUILD_SCRIPTS_DIR/install-deps.sh

# define all --build-arg options
ONBUILD ARG APT_GET_INSTALL
Expand All @@ -36,6 +34,12 @@ ONBUILD ENV APT_GET_INSTALL $APT_GET_INSTALL
ONBUILD ARG NODE_VERSION
ONBUILD ENV NODE_VERSION ${NODE_VERSION:-8.9.0}

ONBUILD ARG INSTALL_NODEGYP
ONBUILD ENV INSTALL_NODEGYP $INSTALL_NODEGYP

ONBUILD ARG NPM_TOKEN
ONBUILD ENV NPM_TOKEN $NPM_TOKEN

ONBUILD ARG INSTALL_MONGO
ONBUILD ENV INSTALL_MONGO ${INSTALL_MONGO:-true}

Expand All @@ -45,21 +49,25 @@ ONBUILD ENV INSTALL_PHANTOMJS ${INSTALL_PHANTOMJS:-true}
ONBUILD ARG INSTALL_GRAPHICSMAGICK
ONBUILD ENV INSTALL_GRAPHICSMAGICK ${INSTALL_GRAPHICSMAGICK:-true}

# optionally custom apt dependencies at app build time
ONBUILD RUN if [ "$APT_GET_INSTALL" ]; then apt-get update && apt-get install -y $APT_GET_INSTALL; fi

# optionally install Mongo or Phantom at app build time
ONBUILD RUN bash $BUILD_SCRIPTS_DIR/install-phantom.sh
ONBUILD RUN bash $BUILD_SCRIPTS_DIR/install-mongo.sh
ONBUILD RUN bash $BUILD_SCRIPTS_DIR/install-graphicsmagick.sh

# Node flags for the Meteor build tool
ONBUILD ARG TOOL_NODE_FLAGS
ONBUILD ENV TOOL_NODE_FLAGS $TOOL_NODE_FLAGS

# optionally custom apt dependencies at app build time
ONBUILD RUN if [ "$APT_GET_INSTALL" ]; then apt-get update && apt-get install -y $APT_GET_INSTALL; fi

# copy the app to the container
ONBUILD COPY . $APP_SOURCE_DIR
WORKDIR $APP_SOURCE_DIR

# install base dependencies, build app, cleanup
ONBUILD RUN bash $BUILD_SCRIPTS_DIR/install-deps.sh
ONBUILD RUN bash $BUILD_SCRIPTS_DIR/install-node.sh
ONBUILD RUN bash $BUILD_SCRIPTS_DIR/install-nodegyp.sh
ONBUILD RUN bash $BUILD_SCRIPTS_DIR/install-phantom.sh
ONBUILD RUN bash $BUILD_SCRIPTS_DIR/install-graphicsmagick.sh
ONBUILD RUN bash $BUILD_SCRIPTS_DIR/install-mongo.sh
ONBUILD RUN bash $BUILD_SCRIPTS_DIR/install-meteor.sh
ONBUILD COPY . $APP_SOURCE_DIR
ONBUILD RUN bash $BUILD_SCRIPTS_DIR/build-meteor.sh

# Default values for Meteor environment variables
Expand Down
12 changes: 12 additions & 0 deletions scripts/install-nodegyp.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

set -e

if [ -f $APP_SOURCE_DIR/launchpad.conf ]; then
source <(grep INSTALL_NODEGYP $APP_SOURCE_DIR/launchpad.conf)
fi

if [ "$INSTALL_NODEGYP" = true ]; then
printf "\n[-] Installing node-gyp ...\n\n"
npm install -g node-gyp --unsafe-perms
fi