Skip to content

Instantly share code, notes, and snippets.

@naderio naderio/README.md
Last active Dec 21, 2017

Embed
What would you like to do?
Node.js Development Setup with Docker Compose and Vagrant

Node.js Development Setup

Requirements

Description

Usage

# clone and cleanup the gist
git clone https://gist.github.com/ab2dc58033087deb6685368c82d47ad5.git PROJECCT_NAME
cd PROJECCT_NAME
rm -fr .git README.md

# start dependencies
docker-compose up

# spawn VM
vagrant up

# ssh into VM
vagrant ssh

# tunnel to public URL (within vagrant ssh)
lt --port 5000
version: '2.1'
services:
mailcatcher:
image: schickling/mailcatcher:latest
container_name: bp-mailcatcher
hostname: mailcatcher
ports:
- "1080:1080"
- "1025:1025"
redis:
image: redis:3.2
container_name: bp-redis
hostname: redis
ports:
- "6379:6379"
volumes:
- "./data/redis:/data"
mongo:
image: mongo:3.4
container_name: bp-mongo
hostname: mongo
ports:
- "27017:27017"
volumes:
- "./data/mongo:/data/db"
# postgres:
# image: postgres:9.6
# container_name: bp-postgres
# hostname: postgres
# ports:
# - "5432:5432"
# volumes:
# - "./data/postgres:/var/lib/postgresql/data"
# environment:
# POSTGRES_PASSWORD: postgres
# couch:
# image: couchdb:1.6
# container_name: bp-couchdb
# hostname: couchdb
# ports:
# - "5984:5984"
# volumes:
# - "./data/couchdb:/usr/local/var/lib/couchdb"
# orient:
# image: orientdb:latest
# container_name: bp-orient
# hostname: orient
# ports:
# - "0.0.0.0:2424:2424"
# - "0.0.0.0:2480:2480"
# volumes:
# # - "./data/orient/databases:/orientdb/config"
# - "./data/orient/databases:/orientdb/databases"
# - "./data/orient/backup:/orientdb/backup"
# environment:
# - ORIENTDB_ROOT_PASSWORD=root
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANT_COMMAND = ARGV[0]
VAGRANT_HOSTNAME = ENV['VAGRANT_HOSTNAME'] || "bp-dev";
VAGRANT_USERNAME = ENV['VAGRANT_USERNAME'] || "deploy";
# VAGRANT_INTERFACE = ENV['VAGRANT_INTERFACE'] || "wlan0";
# VAGRANT_IP = ENV['VAGRANT_IP'] || "192.168.1.100";
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/xenial64"
# config.vm.network "public_network", bridge: VAGRANT_INTERFACE, ip: VAGRANT_IP
config.vm.network "forwarded_port", guest: 5858, host: 5858 # Node.js Legacy Debugger
config.vm.network "forwarded_port", guest: 9229, host: 9229 # Node.js Inspector (Chrome DevTools)
config.vm.network "forwarded_port", guest: 5000, host: 5000 # Application
config.vm.hostname = VAGRANT_HOSTNAME
config.vm.provider "virtualbox" do |v|
v.name = VAGRANT_HOSTNAME
end
if VAGRANT_COMMAND == "ssh" || VAGRANT_COMMAND == "ssh-config"
# config.ssh.host = VAGRANT_IP
# config.ssh.port = 22
config.ssh.username = VAGRANT_USERNAME
end
config.vm.synced_folder ".", "/data"
config.vm.provision "shell", inline: <<-SHELL
set -x
adduser #{VAGRANT_USERNAME} <<-EOM
#{VAGRANT_USERNAME}
#{VAGRANT_USERNAME}
#{VAGRANT_USERNAME}
Y
EOM
echo '%sudo ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/01-sudo
usermod -aG ubuntu,adm,sudo #{VAGRANT_USERNAME}
cp -R /home/ubuntu/.ssh /home/#{VAGRANT_USERNAME}/
chown -R #{VAGRANT_USERNAME}:#{VAGRANT_USERNAME} /home/#{VAGRANT_USERNAME}/.ssh
apt-get install -y build-essential python
curl -sL https://deb.nodesource.com/setup_8.x | bash
apt-get install -y nodejs
npm install -g npm@latest
npm install -g localtunnel
chown -R #{VAGRANT_USERNAME}:#{VAGRANT_USERNAME} /usr/lib/node_modules
SHELL
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.