diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b3d6683 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,21 @@ +FROM node:6.9.1-alpine + +ENV BUILD_PACKAGES="python make gcc g++ git curl tar bzip2" \ + NODE_ENV=production + +WORKDIR / + +RUN apk add --update --no-cache ${BUILD_PACKAGES} && \ + npm install -g node-gyp && \ + node-gyp install + +COPY scripts /scripts + +ONBUILD COPY .build / +ONBUILD RUN sh /scripts/build.sh +ONBUILD RUN sh /scripts/rebuild_bin_npm_modules.sh +ONBUILD RUN sh /scripts/clean.sh + +EXPOSE 80 + +ENTRYPOINT sh /scripts/run.sh diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..0a4c6dc --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2016 Tomasz Hamerla + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..a8f7cf2 --- /dev/null +++ b/README.md @@ -0,0 +1,58 @@ +# Alpine meteor + +Utilizes [Alpine Linux](https://alpinelinux.org/) to provide a [Docker](https://www.docker.com/) image just tiny enough to run a Meteor-based application. + +## Tags + +`:latest` + +`:1.4.3` + +Tag is just a Meteor version that the image was prepared for. If your application was bundled using the same version, you may be sure that the build will go smoothly. Otherwise, compatibility issues may occur. + +## What's included? + +This is an ultra minimal image. Only packages essential to build a Meteor application image are added. Bash is not included (only POSIX-compatible shell is installed). PhantomJS or other packages (and their install scripts) that you may find useful are not included either. + +## Usage + +**Note**: Due to Docker's limitations, only one way of building is supported. However, you may use either a tarball or a directory. Just make sure it's put inside the `.build` folder. Bear in mind that a directory has a higer priority. + +For a use case, see [this repository](https://github.com/nonyy/siteace). + +### Recommended build steps: + +- Ensure that the application bundle is inside `.build` directory. The following command may be used to generate the bundle: + + `meteor build --directory --server-only --architecture os.linux.x86_64 .build` + +- Create a Dockerfile with the following text inside: + + `FROM nonyy/alpine-meteor` + +- **(Optional)** If the build is done inside the source code directory, it's recommended to add the following `.dockerignore` to speed up the process, ignoring all the files except the bundle: + + ``` + * + !.build + ``` + +- Build using the following command: + + `docker build -t NAME .` + + where NAME is the image name you want to use +- Test using the following commands: + + ``` + docker run -d --name mongo mvertes/alpine-mongo:3.2.10-3 + docker run -d --link mongo:db --name meteor -p 3000:80 NAME + ``` + + where NAME is the image name you want to use. You may use the official mongo image or any other implementation you find useful. + + **Note**: As different Meteor versions may support different mongo versions - please make sure the correct one is used... or that the correct README is read. Run options may be overwritten using the -e parameter to the run command. + +## Acknowledgements + +Heavily influenced by [Martin Bucko's alpine-meteor image](https://github.com/Treecom/alpine-meteor). Thanks for the inspiration! diff --git a/scripts/build.sh b/scripts/build.sh new file mode 100644 index 0000000..3a9ee48 --- /dev/null +++ b/scripts/build.sh @@ -0,0 +1,24 @@ +#!/bin/sh + +set -e + +export PYTHONPATH=/usr/lib/python2.7 +export GYP_DEFINES="linux_use_gold_flags=0" + +TARBALL=$(ls / | grep '\.tar\.gz') + +if [[ -d /bundle ]]; then + echo "Using bundle directory" + +elif [[ -f $TARBALL ]]; then + echo "Using bundle tarball" + tar xzf $TARBALL + rm $TARBALL + +else + echo "Application bundle not provided" + exit 1 +fi + +cd /bundle/programs/server +npm install diff --git a/scripts/clean.sh b/scripts/clean.sh new file mode 100644 index 0000000..fd5cee7 --- /dev/null +++ b/scripts/clean.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +set -e + +apk del --purge ${BUILD_PACKAGES} wget + +npm uninstall -g node-gyp +npm cache clear +npm uninstall -g npm + +rm -rf /tmp/* /var/cache/apk/* /root/.node-gyp ./root/.npm diff --git a/scripts/rebuild_bin_npm_modules.sh b/scripts/rebuild_bin_npm_modules.sh new file mode 100644 index 0000000..23f3d94 --- /dev/null +++ b/scripts/rebuild_bin_npm_modules.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +export PYTHONPATH=/usr/lib/python2.7 +export GYP_DEFINES="linux_use_gold_flags=0" + +BINARY_MODULES=$(find /bundle -name 'binding\.gyp' -exec dirname {} \; | grep -v fibers) + +for BINARY_MODULE in $BINARY_MODULES; do + cd $BINARY_MODULE + node-gyp rebuild +done diff --git a/scripts/run.sh b/scripts/run.sh new file mode 100644 index 0000000..305b413 --- /dev/null +++ b/scripts/run.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +set -e + +: ${DB:="meteor"} +: ${MONGO_URL:="mongodb://${DB_PORT_27017_TCP_ADDR}:${DB_PORT_27017_TCP_PORT}/${DB}"} +: ${PORT:="80"} +: ${ROOT_URL:="http://localhost"} + +export MONGO_URL +export PORT +export ROOT_URL + +cd /bundle +echo "=> Starting meteor app on port :$PORT" +node main.js