Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Meteor build -> Docker (custom image, from bundle)
#!/bin/bash
VERSION=$1
ORG=myorg
APP=myapp
TAG=dev
CURRENT_DIR=`basename $PWD`
BUILD_DIR=../$CURRENT_DIR-build
DOCKER_TAG="${ORG}/${APP}/${TAG}"
SERVER="http://${APP}.${ORG}.com"
# ----- about ------
# builds the meteor app to a bundle dir
# copies DockerfileForBuilt -> bundle dir Dockerfile
# builds the docker image from the bundle
# the image should "just work" after that
# ----- usage ------
# cd <meteor-app-root>
# bash ./build2docker.sh
# ----- source -----
# https://markshust.com/2016/02/01/creating-custom-production-docker-image-meteor-13
set -e
rm -rf $BUILD_DIR
echo "Building to $BUILD_DIR"
meteor build --architecture=os.linux.x86_64 --server=$SERVER --directory $BUILD_DIR
cp DockerfileForBundle $BUILD_DIR/bundle/Dockerfile
touch .dockerignore package.json
cp package.json $BUILD_DIR/bundle/
cp .dockerignore $BUILD_DIR/bundle/
cd $BUILD_DIR/bundle/
echo "Building Dockerfile..."
docker build -t ${DOCKER_TAG}:${VERSION} .
# gcloud docker push ${DOCKER_TAG}:${VERSION}
# kubectl rolling-update ${CURRENT_DIR} --update-period=15s --image=${DOCKER_TAG}:${VERSION}
FROM node:4.4.7-slim
MAINTAINER Alan Blount <alan@zeroasterisk.com>
RUN npm install -g npm@3 pm2 \
&& npm cache clear
# TODO: remove when https://github.com/npm/npm/issues/9863 is fixed
RUN cd $(npm root -g)/npm \
&& npm install fs-extra \
&& sed -i -e s/graceful-fs/fs-extra/ -e s/fs\.rename/fs.move/ ./lib/utils/rename.js
# ---------
# -- APP --
# ---------
ADD . /opt/app
WORKDIR /opt/app/programs/server
RUN npm install \
&& npm cache clear \
&& mv /opt/app/programs/server/node_modules /opt/
RUN mv /opt/app/package.json /opt
WORKDIR /opt
RUN npm install --production --unsafe-perm \
&& npm cache clear
RUN ln -s node_modules app/programs/server/node_modules
RUN ln -s node_modules app/programs/web.browser/node_modules
# RUN ln -s node_modules app/programs/web.cordova/node_modules
WORKDIR /opt/app
ENV PORT 80
EXPOSE 80
CMD ["node", "main.js"]
@QHose
Copy link

QHose commented Jul 4, 2017

nice script, thanks a lot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment