- VM Setup (Ubuntu 16.04)
- Update and upgrade:
sudo apt update && sudo apt upgrade
- Install git if it isn't already
- Install docker
- Install nvm / node / npm
- After installing nvm, install LTS version for node and npm:
nvm install --lts
- Check node version with
node --version
- Set the default node version (otherwise it won't persist between shells):
nvm alias default <node_version>
- Example:
nvm alias default 8.6.0
- Example:
- After installing nvm, install LTS version for node and npm:
- Install mysql-server
- Add dockerhost to the
/etc/hosts
filesudo emacs /etc/hosts
- Add the entry
127.0.0.1 dockerhost
- This way your production config file (discussed below) will work both on the host server and in the docker containers.
- Generate an ssh key and add to the project's deploy keys on Github
- Update and upgrade:
- Project Setup
- Navigate to where you want the project, then clone it:
git clone [email protected]:hammer-io/endor.git
- (This works via SSH only if you setup a deploy key.)
- Install dependencies:
cd endor && npm install
- Create production configuration file:
- From the endor directory, move to the config directory and copy the default config file:
cd config && cp default.json production.json
- Edit
production.json
and enter valid information (database credentials, etc) - Make sure to set the following:
- The database host should be set to "dockerhost"
- The database options should include the following:
"dialectOptions": { "socketPath": "/tmp/mysql.sock" },
- From the endor directory, move to the config directory and copy the default config file:
- Create and initialize the database:
- First, run
export NODE_ENV=production
to ensure it uses the production configs - Create the database:
npm run createDB
- Initialize:
npm run initDB
- First, run
- Navigate to where you want the project, then clone it:
- Setting up docker-gen and Nginx reverse proxy
docker pull jwilder/nginx-proxy
docker run -d -p 80:80 -v /var/run/docker.sock:/tmp/docker.sock jwilder/nginx-proxy
- If you visit the domain(s) without any services running, you should see the 503 page from nginx
- For more information, checkout this article by Thiago Marini.
- Build and run the
hammerio/endor
image
# Building the image (-t gives a tag name)
docker build -t hammerio/endor .
# Run the image on the defined virtual host with the host mysql socket mounted in the container
docker run --add-host=dockerhost:$(ip route | awk '/docker0/ { print $NF }') \
-v /var/run/mysqld/mysqld.sock:/tmp/mysql.sock \
-e NODE_ENV=production \
-e VIRTUAL_HOST=example.com \
-d hammerio/endor
# For easier debugging, run the following instead
# Instead of detaching, it keeps an interactive shell into the container open
docker run --add-host=dockerhost:$(ip route | awk '/docker0/ { print $NF }') \
-v /var/run/mysqld/mysqld.sock:/tmp/mysql.sock \
-e NODE_ENV=production \
-e VIRTUAL_HOST=example.com \
-it hammerio/endor
For the actual docker commands used in deployment, read above.
A docker image is built to run the application in
production. The following commands will help you deploy Endor in a docker
container on your local machine (for development, normally you don't need
to do this; just run npm start
):
# Building the image (-t gives a tag name)
docker build -t hammerio/endor .
# List docker images
docker images
# Runs the image, redirecting port 8888 on your machine to
# the exposed port in the image. The -d flag detaches the process.
docker run -p 8888:3000 -d hammerio/endor
# Get container ID
docker ps
# Print app output
docker logs <container_id>
# Enter the container, if necessary
docker exec -it <container_id> /bin/sh
# Stop the container
docker stop <container_id>
Most of this information was found in this guide from nodejs.org.