Skip to content

Instantly share code, notes, and snippets.

@license2e
Last active July 11, 2018 11:37
Show Gist options
  • Save license2e/720382517a24d40baf3d7a4c6aa5d0be to your computer and use it in GitHub Desktop.
Save license2e/720382517a24d40baf3d7a4c6aa5d0be to your computer and use it in GitHub Desktop.
Manual Meteor to Now.sh deployment

Docker (Mac OSX)

Build a deployment package

## install homebrew if not installed: https://brew.sh/
# brew install cask
## optional, if you want to run/verify the docker image locally
# brew cask install docker kitematic 

npm install -g now
## then run through the now login process
# now --login

# install demeteorizer
npm install -g demeteorizer

# clone the files from the gist
git clone https://gist.github.com/720382517a24d40baf3d7a4c6aa5d0be.git ./private/docker

# edit the ./private/docker/Dockerfile as desired (eg. Add MongoDB, etc)

chmod +x ./private/docker/deploy.sh
./private/docker/deploy.sh

Docker run locally (dev environment)

Note: change <env> in the commands below, also this assumes that you have a file ./settings-<env>.json, for example: staging

docker build -t "myproject:dockerfile" .demeteorized

# verify that the new image exists
docker image ls

# run the new image with staging settings (change as needed)
docker run \
  -e MONGO_URL="$(node -p 'settings=require("./settings-<env>.json");settings.MONGO_URL.MONGOLAB')" \
  -e METEOR_SETTINGS="$(node -p 'settings=require("./settings-<env>.json");JSON.stringify(settings)')" \
  -e SERVER_BASE=/usr/src/app/bundle/programs/server \
  -e ROOT_URL=http://127.0.0.0:3000 \
  -e NODE_ENV=<env> \
  -e PORT=3000 \
  -p 3000:3000 \
  myproject:dockerfile

# then open the url
open http://localhost:3000

Upload to Zeit/Now

Note: change <env> in the commands below, also this assumes that you have a file ./settings-<env>.json, for example: staging

now \
  -e MONGO_URL="$(node -p 'settings=require("./settings-<env>.json");settings.MONGO_URL.MONGOLAB')" \
  -e METEOR_SETTINGS="$(node -p 'settings=require("./settings-<env>.json");JSON.stringify(settings)')" \
  -e SERVER_BASE=/usr/src/app/bundle/programs/server \
  -e ROOT_URL=http://127.0.0.0:3000 \
  -e NODE_ENV=<env> \
  -e PORT=3000 \
  -p 3000:3000 \
  deploy .demeteorized

Alias to ENV

# the url is displayed during the now command above, and in some cases copied to the clipboard
now alias set <url-slug>.now.sh <env>.company.com
#!/usr/bin/env bash
rm -rf .demeteorized
demeteorizer --architecture=os.linux.x86_64 --json="$(node -p 'var include={}; try{include=require("./include.json");}catch(e){} JSON.stringify(include)')"
cd .demeteorized
tar -czf myProject.tar.gz bundle
rm -rf bundle
split -b 999k myProject.tar.gz "myProject.tar.gz.meteor-part-"
rm myProject.tar.gz
cp ../private/docker/* ./
rm ./settings-staging.json
#### Use nodejs v6.3.1
#
FROM nodesource/xenial:6.3.1
#### Update apt-get and install supervisor
#
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
RUN apt-get update
RUN apt-get install -y supervisor yarn
############################################################
##### ADD ANY OTHER DEPENDENCIES (eg. MongoDB, etc)
############################################################
#### Set the NPM_CONFIG_LOGLEVEL to warn
#
ENV NPM_CONFIG_LOGLEVEL warn
#### Add label
#
LABEL name="!!-- CHANGE ME --!!"
#### Copy the meteor output and extract the archive(s)
#
COPY . .
RUN cat *meteor-part* > bundle.tar.gz
RUN rm *meteor-part*
RUN tar -xzf bundle.tar.gz
#### Set the working directory to /usr/src/app/bundle/programs/server
#
WORKDIR /usr/src/app/bundle/programs/server
#### Run npm install and npm rebuild
#
RUN rm -rf ./node_modules
RUN yarn install --force
#### Fix the npm-bcrypt issue..
# set the working directory to: /usr/src/app/bundle/programs/server/npm/node_modules/meteor/npm-bcrypt
#
#WORKDIR /usr/src/app/bundle/programs/server/npm/node_modules/meteor/npm-bcrypt
#RUN rm -rf node_modules/bcrypt
#RUN yarn add bcrypt
#### Set the working directory to /usr/src/app/bundle
#
WORKDIR /usr/src/app/bundle
#### Copy the supervisord config to the correct location
#
RUN cp /usr/src/app/supervisor-app.conf /etc/supervisor/conf.d/
#### Expose port 3000
EXPOSE 3000 3000
#### Execute the supervisor daemon command
# -n Run supervisord in the foreground.
# -e The logging level at which supervisor should write to the activity log. Valid levels are trace, debug, info, warn, error, and critical.
#
CMD ["supervisord", "-n", "-e", "warn"]
{
"settings-before": "...",
"MONGO_URL": {
"MONGOLAB": "mongodb://<user>:<pass>@<random>.mongolab.com:35004/<db>"
},
"settings-after": "..."
}
[program:node]
command=node "/usr/src/app/bundle/main.js"
@license2e
Copy link
Author

Note: These setups don't include MongoDB dependencies, when I have a chance, I will add those in...

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