├── .builddeploy ├── Dockerfile ├── LICENSE.md └── README.md /.builddeploy: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ## Author: Mark Shust 3 | ## Version: 5.0.0 4 | ## Repo: https://github.com/markoshust/docker-meteor 5 | ## Description: Script for bundling, building & deploying a Meteor app with Docker 6 | 7 | TARGET=$1 8 | VERSION=$2 9 | MOBILE_NAME=BAR 10 | BASE_APP_NAME=bar 11 | BUILD_DIR=../build 12 | BASE_DOCKER_TAG=foo/$BASE_APP_NAME 13 | NODE_ENV=production 14 | PORT=80 15 | 16 | PRODUCTION_APP_NAME=$BASE_APP_NAME 17 | PRODUCTION_GIT_TAG=$VERSION 18 | PRODUCTION_DOCKER_TAG=$BASE_DOCKER_TAG:$PRODUCTION_GIT_TAG 19 | PRODUCTION_ROOT_URL=https://bar.com 20 | # following only needed for standard docker deploy 21 | PRODUCTION_SSH_CONN=production@bar.com 22 | PRODUCTION_METEOR_SETTINGS=$(cat ./.config/settings-production.json) 23 | PRODUCTION_MONGO_URL="mongodb://username:password@localhost:27017/bar" 24 | PRODUCTION_MONGO_OPLOG_URL="mongodb://username:password@localhost:27017/local?authSource=admin" 25 | PRODUCTION_CLUSTER_DISCOVERY_URL="mongodb://username:password@localhost:27017/bar" 26 | 27 | STAGING_APP_NAME=$BASE_APP_NAME-staging 28 | STAGING_GIT_TAG=$VERSION-staging 29 | STAGING_DOCKER_TAG=$BASE_DOCKER_TAG:$STAGING_GIT_TAG 30 | STAGING_ROOT_URL=https://staging.bar.com/ 31 | # following only needed for standard docker deploy 32 | STAGING_SSH_CONN=staging@bar.com 33 | STAGING_METEOR_SETTINGS=$(cat ./.config/settings-staging.json) 34 | STAGING_MONGO_URL=$PRODUCTION_MONGO_URL 35 | STAGING_MONGO_OPLOG_URL=$PRODUCTION_MONGO_OPLOG_URL 36 | STAGING_CLUSTER_DISCOVERY_URL=$PRODUCTION_CLUSTER_DISCOVERY_URL 37 | 38 | COMPAT_VERSION=1.0 39 | METEOR_CORDOVA_COMPAT_VERSION_IOS=$COMPAT_VERSION 40 | METEOR_CORDOVA_COMPAT_VERSION_ANDROID=$COMPAT_VERSION 41 | 42 | if [ -z "$TARGET" ]; then 43 | echo 'Missing deployment target. Possible values: production, staging' 44 | exit 0 45 | elif [ -z "$VERSION" ]; then 46 | echo 'Missing version number. Ex. 1.0.0.0 (or "mobile")' 47 | exit 0 48 | fi 49 | 50 | case "$TARGET" in 51 | 'production' | 'staging') 52 | if [ "$TARGET" = 'production' ]; then 53 | APP_NAME=$PRODUCTION_APP_NAME 54 | GIT_TAG=$PRODUCTION_GIT_TAG 55 | DOCKER_TAG=$PRODUCTION_DOCKER_TAG 56 | ROOT_URL=$PRODUCTION_ROOT_URL 57 | SSH_CONN=$PRODUCTION_SSH_CONN 58 | METEOR_SETTINGS=$PRODUCTION_METEOR_SETTINGS 59 | MONGO_URL=$PRODUCTION_MONGO_URL 60 | MONGO_OPLOG_URL=$PRODUCTION_MONGO_OPLOG_URL 61 | CLUSTER_DISCOVERY_URL=$PRODUCTION_CLUSTER_DISCOVERY_URL 62 | elif [ "$TARGET" = 'staging' ]; then 63 | APP_NAME=$STAGING_APP_NAME 64 | GIT_TAG=$STAGING_GIT_TAG 65 | DOCKER_TAG=$STAGING_DOCKER_TAG 66 | ROOT_URL=$STAGING_ROOT_URL 67 | SSH_CONN=$STAGING_SSH_CONN 68 | METEOR_SETTINGS=$STAGING_METEOR_SETTINGS 69 | MONGO_URL=$STAGING_MONGO_URL 70 | MONGO_OPLOG_URL=$STAGING_MONGO_OPLOG_URL 71 | CLUSTER_DISCOVERY_URL=$STAGING_CLUSTER_DISCOVERY_URL 72 | fi 73 | if [ "$VERSION" = 'mobile' ]; then 74 | echo "Building mobile bundle for $TARGET" 75 | else 76 | echo "Building & deploying $DOCKER_TAG to $TARGET" 77 | fi 78 | echo "" 79 | ;; 80 | *) 81 | echo 'Invalid deployment target. Possible values: production, staging' 82 | exit 0 83 | ;; 84 | esac 85 | 86 | rm -rf $BUILD_DIR 87 | 88 | meteor yarn 89 | 90 | echo "Building Meteor bundle to $BUILD_DIR" 91 | METEOR_CORDOVA_COMPAT_VERSION_IOS=$METEOR_CORDOVA_COMPAT_VERSION_IOS \ 92 | METEOR_CORDOVA_COMPAT_VERSION_ANDROID=$METEOR_CORDOVA_COMPAT_VERSION_ANDROID \ 93 | meteor build --architecture=os.linux.x86_64 --server=$ROOT_URL --directory $BUILD_DIR 94 | 95 | if [ "$VERSION" = 'mobile' ]; then 96 | echo 'Halting further build process and opening mobile build' 97 | open $BUILD_DIR/ios/project/$MOBILE_NAME.xcodeproj 98 | exit 0 99 | fi 100 | 101 | echo "Tagging version..." 102 | git tag $GIT_TAG 103 | git push --tags 104 | 105 | echo "Building Dockerfile..." 106 | cp Dockerfile $BUILD_DIR/bundle/ 107 | cd $BUILD_DIR/bundle/ 108 | docker build -t $DOCKER_TAG . 109 | 110 | 111 | ### Standard docker registry and docker deploy 112 | docker push $DOCKER_TAG 113 | 114 | RUN_COMMAND="docker pull $DOCKER_TAG \ 115 | && docker stop $BASE_APP_NAME \ 116 | && docker rm $BASE_APP_NAME \ 117 | && docker run \ 118 | -e NODE_ENV=$NODE_ENV \ 119 | -e PORT=$PORT \ 120 | -e ROOT_URL=$ROOT_URL \ 121 | -e MONGO_URL=\"${MONGO_URL}\" \ 122 | -e MONGO_OPLOG_URL=\"${MONGO_OPLOG_URL}\" \ 123 | -e CLUSTER_DISCOVERY_URL=\"${CLUSTER_DISCOVERY_URL}\" \ 124 | -e METEOR_SETTINGS='${METEOR_SETTINGS}' \ 125 | --name $BASE_APP_NAME \ 126 | -d $DOCKER_TAG" 127 | 128 | ssh $SSH_CONN $RUN_COMMAND 129 | 130 | 131 | ### Google container registry and kubernetes 132 | : ' 133 | gcloud docker -- push $DOCKER_TAG 134 | 135 | echo "Deploying new bundle..." 136 | kubectl set image deployment/$APP_NAME $APP_NAME=$DOCKER_TA 137 | ' 138 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM mhart/alpine-node:8.8 2 | MAINTAINER Mark Shust 3 | 4 | RUN apk update && apk add \ 5 | python \ 6 | make \ 7 | g++ 8 | RUN npm i -g yarn@1.2 9 | 10 | ONBUILD ADD . /opt/app 11 | ONBUILD RUN cd /opt/app/programs/server \ 12 | && yarn 13 | 14 | WORKDIR /opt/app 15 | 16 | ENV PORT 80 17 | EXPOSE 80 18 | 19 | CMD ["node", "main.js"] 20 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 Mark Shust 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # markoshust/meteor 2 | 3 | Standard Dockerfile for deploying bundled Meteor apps. 4 | 5 | ## Description 6 | 7 | This is a simple onbuild Dockerfile for running Meteor 1.3+ with Docker. 8 | 9 | ## Versions 10 | 11 | The following tags are available, and correspond to the related Node.JS version supported by Meteor: 12 | 13 | - `8.8`, `latest` 14 | - `4.8-1`, `4.8` 15 | - `4.7` 16 | - `4.6` 17 | - `4.5` 18 | - `4.4` 19 | - `0.10` 20 | 21 | ## Usage 22 | 23 | Just create a new `Dockerfile` in the root of your application, specifying the version of Node that your Meteor install is setup to use (find this out with `meteor node --version`): 24 | 25 | ``` 26 | FROM markoshust/meteor:8.8 27 | ``` 28 | 29 | Then, build your Docker image by running: 30 | 31 | ``` 32 | docker build -t foo/bar:1.0.0.0 . 33 | ``` 34 | 35 | This image uses yarn to install node modules, so it is highly recommended to use yarn when developing and installing modules locally. You can do this by running `meteor npm i -g yarn@1.2`, and then use `meteor yarn` instead of `meteor npm install`. 36 | 37 | ## Advanced Usage 38 | 39 | Place the [.builddeploy](https://github.com/markoshust/docker-meteor/blob/master/.builddeploy) in the root of your Meteor directory, update it's contents where appropriate, make it executable, then run the command: 40 | 41 | ``` 42 | ./.builddeploy production 1.0.0.0 43 | ``` 44 | 45 | This will build a Docker image for the appropriate environment (production or staging) and the appropriate tag (ex. 1.0.0.0), push it to a Docker registry, then start a container on your production server with your desired configuration. 46 | --------------------------------------------------------------------------------