Last active
August 23, 2016 19:41
-
-
Save anx21/6611a4a3bcbffc48b028dc70eef37105 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. Set up Project with Dockerfile and docker-compose.yml | |
(Steps 2, 3 & 4 should be performed with the help of a vagrant bootstrap script): | |
2. Set up vagrant with a port forwarding and private IP(will need to modify /etc/hosts on system hosting vagrant), | |
follow http://tech.osteel.me/posts/2015/01/25/how-to-use-vagrant-for-local-web-development.html | |
3. Set up docker on vagrant machine | |
4. Set up git hooks on vagrant machine | |
/*** FILES ***/ | |
/---Vagrantfile:---/ | |
# -*- mode: ruby -*- | |
# vi: set ft=ruby : | |
# All Vagrant configuration is done below. The "2" in Vagrant.configure | |
# configures the configuration version (we support older styles for | |
# backwards compatibility). Please don't change it unless you know what | |
# you're doing. | |
Vagrant.configure(2) do |config| | |
# The most common configuration options are documented and commented below. | |
# For a complete reference, please see the online documentation at | |
# https://docs.vagrantup.com. | |
# Every Vagrant development environment requires a box. You can search for | |
# boxes at https://atlas.hashicorp.com/search. | |
config.vm.box = "debian/jessie64" | |
config.vm.network :forwarded_port, guest: 80, host: 8080 | |
config.vm.network :private_network, ip: "192.168.68.8" | |
config.vm.provision :shell, :path => ".provision/bootstrap.sh" | |
# Disable automatic box update checking. If you disable this, then | |
# boxes will only be checked for updates when the user runs | |
# `vagrant box outdated`. This is not recommended. | |
# config.vm.box_check_update = false | |
# Create a forwarded port mapping which allows access to a specific port | |
# within the machine from a port on the host machine. In the example below, | |
# accessing "localhost:8080" will access port 80 on the guest machine. | |
# config.vm.network "forwarded_port", guest: 80, host: 8080 | |
# Create a private network, which allows host-only access to the machine | |
# using a specific IP. | |
# config.vm.network "private_network", ip: "192.168.33.10" | |
# Create a public network, which generally matched to bridged network. | |
# Bridged networks make the machine appear as another physical device on | |
# your network. | |
# config.vm.network "public_network" | |
# Share an additional folder to the guest VM. The first argument is | |
# the path on the host to the actual folder. The second argument is | |
# the path on the guest to mount the folder. And the optional third | |
# argument is a set of non-required options. | |
# config.vm.synced_folder "../data", "/vagrant_data" | |
# Provider-specific configuration so you can fine-tune various | |
# backing providers for Vagrant. These expose provider-specific options. | |
# Example for VirtualBox: | |
# | |
# config.vm.provider "virtualbox" do |vb| | |
# # Display the VirtualBox GUI when booting the machine | |
# vb.gui = true | |
# | |
# # Customize the amount of memory on the VM: | |
# vb.memory = "1024" | |
# end | |
# | |
# View the documentation for the provider you are using for more | |
# information on available options. | |
# Define a Vagrant Push strategy for pushing to Atlas. Other push strategies | |
# such as FTP and Heroku are also available. See the documentation at | |
# https://docs.vagrantup.com/v2/push/atlas.html for more information. | |
# config.push.define "atlas" do |push| | |
# push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME" | |
# end | |
# Enable provisioning with a shell script. Additional provisioners such as | |
# Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the | |
# documentation for more information about their specific syntax and use. | |
# config.vm.provision "shell", inline: <<-SHELL | |
# sh /vagrant/bootstrap.sh | |
# SHELL | |
end | |
/---Dockerfile:---/ | |
FROM ruby:2.3-slim | |
MAINTAINER Nick Janetakis <[email protected]> | |
# It is good practice to set a maintainer for all of your Docker | |
# images. It's not necessary but it's a good habit. | |
RUN apt-get update && apt-get install -qq -y --no-install-recommends \ | |
build-essential nodejs libpq-dev | |
# Ensure that our apt package list is updated and install a few | |
# packages to ensure that we can compile assets (nodejs) and | |
# communicate with PostgreSQL (libpq-dev). | |
ENV INSTALL_PATH /mobydock | |
# The name of the application is mobydock and while there | |
# is no standard on where your project should live inside of the Docker | |
# image, I like to put it in the root of the image and name it | |
# after the project. | |
# | |
# We don't even need to set the INSTALL_PATH variable, but I like | |
# to do it because we're going to be referencing it in a few spots | |
# later on in the Dockerfile. | |
# | |
# The variable could be named anything you want. | |
RUN mkdir -p $INSTALL_PATH | |
# This just creates the folder in the Docker image at the | |
# install path we defined above. | |
WORKDIR $INSTALL_PATH | |
# We're going to be executing a number of commands below, and | |
# having to CD into the /mobydock folder every time would be | |
# lame, so instead we can set the WORKDIR to be /mobydock. | |
# | |
# By doing this, Docker will be smart enough to execute all | |
# future commands from within this directory. | |
COPY Gemfile Gemfile.lock ./ | |
RUN bundle install --binstubs | |
# We want binstubs to be available so we can directly call sidekiq and | |
# potentially other binaries as command overrides without depending on | |
# bundle exec. | |
# This is mainly due for production compatibility assurance. | |
COPY . . | |
# This might look a bit alien but it's copying in everything from | |
# the current directory relative to the Dockerfile, over to the | |
# /mobydock folder inside of the Docker image. | |
# | |
# We can get away with using the . for the second argument because | |
# this is how the unix command cp (copy) works. It stands for the | |
# current directory. | |
RUN bundle exec rake RAILS_ENV=production DATABASE_URL=postgresql://user:[email protected]/dbname ACTION_CABLE_ALLOWED_REQUEST_ORIGINS=foo,bar SECRET_TOKEN=dummytoken assets:precompile | |
VOLUME ["$INSTALL_PATH/public"] | |
CMD puma -C config/puma.rb | |
# This is the command that's going to be ran by default if you run the | |
# Docker image without any arguments. | |
# | |
# In our case, it will start the Puma app server while passing in | |
# its config file. | |
/---post-receive git hook---/ | |
#!/usr/bin/env bash | |
REPO_NAME="mobydock" | |
export GIT_WORK_TREE="/var/git/${REPO_NAME}" | |
git checkout -f | |
TAG="$(git log --pretty=format:'%h' -n 1)" | |
FULL_COMMIT_TAG="${REPO_NAME}:${TAG}" | |
FULL_LATEST_TAG="${REPO_NAME}:latest" | |
docker build -t "${FULL_LATEST_TAG}" "${GIT_WORK_TREE}" | |
DOCKER_ID="$(docker images -q ${REPO_NAME} | head -1)" | |
echo "Restarting ${REPO_NAME}" | |
docker stop "${REPO_NAME}" | |
echo "Removing untagged Docker images(may take a while)" | |
docker rmi $(docker images --quiet --filter "dangling=true") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment