Skip to content

Commit

Permalink
syncing with original
Browse files Browse the repository at this point in the history
  • Loading branch information
skwasha committed May 8, 2015
2 parents a88adf6 + b706087 commit a441083
Show file tree
Hide file tree
Showing 32 changed files with 244 additions and 89 deletions.
1 change: 0 additions & 1 deletion .dockerignore

This file was deleted.

15 changes: 0 additions & 15 deletions Dockerfile

This file was deleted.

15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ For that, you can use `meteorhacks/meteord` as your base image. Magically, that'
Add following `Dockerfile` into the root of your app:

~~~shell
FROM meteorhacks/meteord
MAINTAINER Your Name
FROM meteorhacks/meteord:onbuild
~~~

Then you can build the docker image with:
Expand All @@ -38,6 +37,12 @@ docker run -d \
yourname/app
~~~

#### Stop downloading Meteor each and every time (mostly in development)

So, with the above method, MeteorD will download and install Meteor each and every time. That's bad specially in development. So, we've a solution for that. Simply use `meteorhacks/meteord:devbuild` as your base image.

> WARNING: Don't use `meteorhacks/meteord:devbuild` for your final build. If you used it, your image will carry the Meteor distribution as well. As a result of that, you'll end up with an image with ~700 MB.
Then you can access your app from the port 8080 of the host system.

### 2. Running a Meteor bundle with Docker
Expand All @@ -53,7 +58,7 @@ docker run -d \
-e MONGO_OPLOG_URL=mongodb://oplog_url \
-v /mybundle_dir:/bundle \
-p 8080:80 \
meteorhacks/meteord
meteorhacks/meteord:base
~~~

With this method, MeteorD looks for the tarball version of the meteor bundle. So, you should build the meteor bundle for `os.linux.x86_64` and put it inside the `/bundle` volume. This is how you can build a meteor bundle.
Expand All @@ -73,7 +78,7 @@ docker run -d \
-e MONGO_OPLOG_URL=mongodb://oplog_url \
-e BUNDLE_URL=http://mybundle_url_at_s3.tar.gz \
-p 8080:80 \
meteorhacks/meteord
meteorhacks/meteord:base
~~~


Expand All @@ -89,5 +94,5 @@ docker run -d \
-e BUNDLE_URL=http://mybundle_url_at_s3.tar.gz \
-e REBULD_NPM_MODULES=1 \
-p 8080:80 \
meteorhacks/meteord
meteorhacks/meteord:binbuild
~~~
10 changes: 10 additions & 0 deletions base/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM debian:wheezy
MAINTAINER MeteorHacks Pvt Ltd.

ENV METEORD_DIR /opt/meteord
COPY scripts $METEORD_DIR

RUN bash $METEORD_DIR/init.sh

EXPOSE 80
ENTRYPOINT bash $METEORD_DIR/run_app.sh
6 changes: 6 additions & 0 deletions base/scripts/init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
set -e

bash $METEORD_DIR/lib/install_base.sh
bash $METEORD_DIR/lib/install_node.sh
bash $METEORD_DIR/lib/install_phantomjs.sh
bash $METEORD_DIR/lib/cleanup.sh
22 changes: 22 additions & 0 deletions base/scripts/lib/build_app.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
set -e

COPIED_APP_PATH=/copied-app
BUNDLE_DIR=/tmp/bundle-dir

# sometimes, directly copied folder cause some wierd issues
# this fixes that
cp -R /app $COPIED_APP_PATH
cd $COPIED_APP_PATH

meteor build --directory $BUNDLE_DIR --server=http://localhost:3000

cd $BUNDLE_DIR/bundle/programs/server/
npm i

mv $BUNDLE_DIR/bundle /built_app

# cleanup
rm -rf $COPIED_APP_PATH
rm -rf $BUNDLE_DIR
rm -rf ~/.meteor
rm /usr/local/bin/meteor
17 changes: 17 additions & 0 deletions base/scripts/lib/cleanup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
## Borrowed from: https://github.com/chriswessels/meteor-tupperware

set -e
# Autoremove any junk
apt-get autoremove -y

# Clean out docs
rm -rf /usr/share/doc /usr/share/doc-base /usr/share/man /usr/share/locale /usr/share/zoneinfo

# Clean out package management dirs
rm -rf /var/lib/cache /var/lib/log

# Clean out /tmp
rm -rf /tmp/*

# Clear npm cache
npm cache clear
4 changes: 4 additions & 0 deletions base/scripts/lib/install_base.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
set -e
apt-get update -y
apt-get install -y curl bzip2
3 changes: 3 additions & 0 deletions base/scripts/lib/install_meteor.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
set -e

curl https://install.meteor.com | /bin/sh
10 changes: 2 additions & 8 deletions scripts/install_node.sh → base/scripts/lib/install_node.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash

set -e
NODE_VERSION=0.10.36
NODE_ARCH=x64

Expand All @@ -8,16 +8,10 @@ NODE_ARCH=x64
NODE_DIST=node-v${NODE_VERSION}-linux-${NODE_ARCH}

cd /tmp
wget http://nodejs.org/dist/v${NODE_VERSION}/${NODE_DIST}.tar.gz
curl -O -L http://nodejs.org/dist/v${NODE_VERSION}/${NODE_DIST}.tar.gz
tar xvzf ${NODE_DIST}.tar.gz
rm -rf /opt/nodejs
mv ${NODE_DIST} /opt/nodejs

ln -sf /opt/nodejs/bin/node /usr/bin/node
ln -sf /opt/nodejs/bin/npm /usr/bin/npm

# for npm module re-building
apt-get -y install build-essential libssl-dev git python
npm install -g node-gyp
# pre-install node source code for faster building
node-gyp install ${NODE_VERSION}
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
# Install PhantomJS
set -e
apt-get -y install libfreetype6 libfreetype6-dev fontconfig
ARCH=`uname -m`
PHANTOMJS_VERSION=1.9.8
PHANTOMJS_TAR_FILE=phantomjs-${PHANTOMJS_VERSION}-linux-${ARCH}.tar.bz2

cd /usr/local/share/
wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-${PHANTOMJS_VERSION}-linux-${ARCH}.tar.bz2
tar xjf phantomjs-${PHANTOMJS_VERSION}-linux-${ARCH}.tar.bz2
curl -L -O https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-${PHANTOMJS_VERSION}-linux-${ARCH}.tar.bz2
tar xjf $PHANTOMJS_TAR_FILE
ln -s -f /usr/local/share/phantomjs-${PHANTOMJS_VERSION}-linux-${ARCH}/bin/phantomjs /usr/local/share/phantomjs
ln -s -f /usr/local/share/phantomjs-${PHANTOMJS_VERSION}-linux-${ARCH}/bin/phantomjs /usr/local/bin/phantomjs
ln -s -f /usr/local/share/phantomjs-${PHANTOMJS_VERSION}-linux-${ARCH}/bin/phantomjs /usr/bin/phantomjs

rm $PHANTOMJS_TAR_FILE
5 changes: 5 additions & 0 deletions base/scripts/on_build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
set -e

bash $METEORD_DIR/lib/install_meteor.sh
bash $METEORD_DIR/lib/build_app.sh
36 changes: 36 additions & 0 deletions base/scripts/run_app.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
set -e

if [ -d /bundle ]; then
cd /bundle
tar xzf *.tar.gz
cd /bundle/bundle/programs/server/
npm i
cd /bundle/bundle/
elif [[ $BUNDLE_URL ]]; then
cd /tmp
curl -L -o bundle.tar.gz $BUNDLE_URL
tar xzf bundle.tar.gz
cd /tmp/bundle/programs/server/
npm i
cd /tmp/bundle/
elif [ -d /built_app ]; then
cd /built_app
else
echo "=> You don't have an meteor app to run in this image."
exit 1
fi

if [[ $REBULD_NPM_MODULES ]]; then
if [ -f /opt/meteord/rebuild_npm_modules.sh ]; then
cd programs/server
bash /opt/meteord/rebuild_npm_modules.sh
cd ../../
else
echo "=> Use meteorhacks/meteord:bin-build for binary bulding."
exit 1
fi
fi

export PORT=80
echo "=> Starting meteor app on port:$PORT"
node main.js
7 changes: 7 additions & 0 deletions binbuild/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM meteorhacks/meteord:base
MAINTAINER MeteorHacks Pvt Ltd.

COPY scripts/install_binbuild_tools.sh $METEORD_DIR/install_binbuild_tools.sh
COPY scripts/rebuild_npm_modules.sh $METEORD_DIR/rebuild_npm_modules.sh

RUN bash $METEORD_DIR/install_binbuild_tools.sh
8 changes: 8 additions & 0 deletions binbuild/scripts/install_binbuild_tools.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
set -e
# for npm module re-building
apt-get -y install build-essential libssl-dev git python
npm install -g node-gyp
# pre-install node source code for faster building
node-gyp install ${NODE_VERSION}

bash $METEORD_DIR/lib/cleanup.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
set -e
gyp_rebuild_inside_node_modules () {
for npmModule in ./*; do
cd $npmModule
Expand Down
6 changes: 6 additions & 0 deletions devbuild/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM meteorhacks/meteord:base
MAINTAINER MeteorHacks Pvt Ltd.

ONBUILD RUN bash $METEORD_DIR/lib/install_meteor.sh
ONBUILD COPY ./ /app
ONBUILD RUN bash $METEORD_DIR/lib/build_app.sh
5 changes: 5 additions & 0 deletions onbuild/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM meteorhacks/meteord:base
MAINTAINER MeteorHacks Pvt Ltd.

ONBUILD COPY ./ /app
ONBUILD RUN bash $METEORD_DIR/on_build.sh
4 changes: 0 additions & 4 deletions scripts/install_base.sh

This file was deleted.

3 changes: 0 additions & 3 deletions scripts/install_meteor.sh

This file was deleted.

15 changes: 0 additions & 15 deletions scripts/meteord-build.sh

This file was deleted.

28 changes: 0 additions & 28 deletions scripts/run_app.sh

This file was deleted.

5 changes: 4 additions & 1 deletion tests/build_it.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
#!/bin/bash
docker build -t meteord ../
docker build -t meteorhacks/meteord:base ../base
docker build -t meteorhacks/meteord:onbuild ../onbuild
docker build -t meteorhacks/meteord:devbuild ../devbuild
docker build -t meteorhacks/meteord:binbuild ../binbuild
7 changes: 5 additions & 2 deletions tests/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ set -e
bash ./build_it.sh

bash ./test_meteor_app.sh
bash ./test_meteor_app_with_devbuild.sh
bash ./test_bundle_local_mount.sh
bash ./test_bundle_web.sh
bash ./test_binary_build.sh
bash ./test_phantomjs.sh
bash ./test_binary_build_on_base.sh
bash ./test_binary_build_on_bin_build.sh
bash ./test_phantomjs.sh
bash ./test_no_app.sh
27 changes: 27 additions & 0 deletions tests/test_binary_build_on_base.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

function clean() {
docker rm -f binary_build
}

cd /tmp
clean

docker run -d \
--name binary_build \
-e ROOT_URL=http://binary_build_app \
-e BUNDLE_URL=https://s3.amazonaws.com/zeema-data/aa.tar.gz \
-e REBULD_NPM_MODULES=1 \
-p 9090:80 \
meteorhacks/meteord:base

echo "Waiting for binary building is happening"
sleep 10

appContent=`docker logs binary_build`
clean

if [[ $appContent != *"meteorhacks/meteord:bin-build"* ]]; then
echo "Failed: Trying to binary building on the base image"
exit 1
fi
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ docker run -d \
-e BUNDLE_URL=https://s3.amazonaws.com/zeema-data/aa.tar.gz \
-e REBULD_NPM_MODULES=1 \
-p 9090:80 \
meteord
meteorhacks/meteord:binbuild

echo "Waiting for binary building is happening"
sleep 20
Expand Down
2 changes: 1 addition & 1 deletion tests/test_bundle_local_mount.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ docker run -d \
-e ROOT_URL=http://localmount_app \
-v /tmp/localmount:/bundle \
-p 9090:80 \
meteord
meteorhacks/meteord:base

sleep 5

Expand Down
2 changes: 1 addition & 1 deletion tests/test_bundle_web.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ docker run -d \
-e ROOT_URL=http://web_app \
-e BUNDLE_URL=https://s3.amazonaws.com/zeema-data/aa.tar.gz \
-p 9090:80 \
meteord
meteorhacks/meteord:base

sleep 8

Expand Down
Loading

0 comments on commit a441083

Please sign in to comment.