Skip to content

Instantly share code, notes, and snippets.

@jorgeavaldez
Last active June 27, 2017 03:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jorgeavaldez/951d926d473c694345db13cbd734689d to your computer and use it in GitHub Desktop.
Save jorgeavaldez/951d926d473c694345db13cbd734689d to your computer and use it in GitHub Desktop.
Node JS Docker Workflow Templates
FROM ubuntu
# Create the app source dir
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
RUN apt-get -y update
# Time to install Node.JS version 7
RUN curl -sL https://deb.nodesource.com/setup_7.x | bash
RUN apt-get install -y nodejs
RUN apt-get install -y npm
# Install the app dependencies
COPY package.json /usr/src/app/
RUN npm install
# Bundle app src
COPY . /usr/src/app
# Let the docker daemon bind to port 4205
# This may change based on how we write the app, don't forget to change it
EXPOSE 4205
# The command to run the app itself
CMD ["npm", "start"]
.SILENT:
help:
echo
echo "Docker Workflow Makefile"
echo "Prebuilt Makefile to run Node JS services in Docker"
echo "Inspired by the files from https://github.com/retrohacker/presentation and the"
echo "presentation they come from"
echo
echo "By Jorge Valdez"
echo
echo "Make commands"
echo
echo " Commands: "
echo
echo " help - show this message"
echo " run - Start this service, and all of its deps, locally (docker)"
echo " test - Run the unit tests"
echo " deps - Check for all dependencies"
echo
build: clean
docker-compose -f ./run.yml build
run: build
docker-compose -f ./run.yml up -d
clean:
docker-compose -f ./run.yml rm -f
deps:
echo " Dependencies: "
echo
echo " * docker $(shell which docker > /dev/null || echo '- \033[31mNOT INSTALLED\033[37m')"
echo " * nodejs $(shell which nodejs > /dev/null || echo '- \033[31mNOT INSTALLED\033[37m')"
echo " * docker-compose $(shell which docker-compose > /dev/null || echo '- \033[31mNOT INSTALLED\033[37m')"
echo
.PHONY: build run clean deps
version: "2"
services:
mongo:
image: mongo
ports:
- "27017:27017"
zerg:
build: .
image: your_namespace/ayye:lmao
links:
- mongo
ports:
- "4205:4205"
# -*- mode: ruby -*-
# vi: set ft=ruby :
require 'fileutils'
require 'ipaddr'
VAGRANTFILE_API_VERSION = "2"
ENV['VAGRANT_DEFAULT_PROVIDER'] = 'virtualbox'
$instance_name = 'instance_name'
$share_home = false
$vm_gui = false
$vm_memory = 512
$vm_cpus = 1
$vm_ip = "172.69.4.20"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "ubuntu/trusty64"
config.ssh.insert_key = true
if Vagrant.has_plugin?("vagrant-cachier")
config.cache.scope = :box
end
config.vm.define $instance_name do |config|
config.vm.hostname = $instance_name
# zerg service
config.vm.network "forwarded_port", guest: 4205, host: 4205
# load api service
config.vm.network "forwarded_port", guest: 4206, host: 4206
# mongo
config.vm.network "forwarded_port", guest: 27017, host: 27017
ip = IPAddr.new($vm_ip)
$vm_ip = ip.succ.to_s
config.vm.network "private_network", ip: $vm_ip
# add the load service and the store service as synced folders
config.vm.synced_folder ".", "/vagrant/service"
end
config.vm.provider :virtualbox do |vb|
vb.gui = $vm_gui
vb.memory = $vm_memory
vb.cpus = $vm_cpus
end
config.vm.provision "docker", images: [
"ubuntu"
]
config.vm.provision "shell", privileged: true, inline: <<-SHELL
sudo apt-get -y update
sudo apt-get install -y build-essentials
sudo apt-get install -y python-pip
sudo pip install docker-compose
SHELL
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment