AWESOMIFY DEV
Increasing Velocity with
Vagrant and Docker
Agenda
- Cultural Movement
- Dev to Production
-
Dev Tooling
- vagrant
- docker
- Prod Tooling (Docker)
- Demo
DevOps
Say What?
DevOps
The New Buzz Word
Some seem to be putting DevOps into the same category as cloud, big data, and those other ambiguous terms that have no precise meaning, so can be spun however you want to help you sell stuff.
– Dale Vile, Feb 2016
DevOps
What does it really mean?
DevOps is the practice of operations and development engineers participating together in the entire service lifecycle, from design through the development process to production support.
– The Agile Admin Blog
DevOps
Breaking Down Silos
By having people from those silos all working together, it built a lot of empathy. And we were finally able to get moving.
– Rob Cummings, Director of Technical Operations at Nordstrom
DEV
QA
OPS
PM
Devops
Philosphy vs. Organization
"DevOps is a culture shift or a movement...." Instead, [companies] think that DevOps is a job or a role, so they create a new silo called DevOps
– Five Signs That Your DevOps Initiative is Failing by Mike Cavis
DevOps
What does DevOps do?
Activities: Code, Build, Test, Package, Release, Configure, Monitor
Methods: C.A.L.M.S. (Culture, Automation, Lean, Measurement, Sharing)
Testing Code
development to production
Testing Code
On Production
How close does is your laptop to production?
- Linux vs. OS X
- Built from Scratch?
- Consistency?
- Provisioning?
Testing Code
Chaos Reigns
How do services respond?
- Resilience
- Business Continuity
- Integration Points
- Respond to Failures
- Communicate Failures
- Data Integrity
Testing Code
Response
- ownership (everyone)
- participation
- debugging, testing
Testing Code
Fixing or Preventing
- troubleshooting
- monitoring
- reporting
- on call, escalation
Vagrant
virtual systems
Vagrant
Automates virtual machines
- port mapping
- file sync
- ssh keys
- control vm
- provision vm
- imaging
- access (ssh, winrm, rdp)
Vagrant
Provisioning
Apply configuration on your virtual machine(s)
- Shell Scripts
- Docker
- Ansible
- Others...
Vagrant
Virtualization Providers
- Virtualbox (default)
- AWS
- Docker
- others...
Vagrant
Throw Away virtual systems
Disposable Virtual Systems (Linux)
Development system (Mac OS X)
vs
Vagrant
Shared Dev
Environments
Segregated Dev
Environments
vs
Vagrant
Example
# Create Scripts
vi Vagrantfile
# Bootstrap
vagrant up
# Interaction / Start Service
vagrant ssh
# Stop Web Service
vagrant halt
# Test
curl -i localhost:8080
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.provision :shell, path: "install_app.sh"
config.vm.network :forwarded_port, guest: 80, host: 8080
end
Overview
Vagrantfile
Docker
images and containers
Docker
Virtual Machines vs. Containers
KVM
HVM
LXC
- segregation
- system
- application
- resources
- file, mem, cpu
- net, user, mount
Docker
Containers vs. Docker
Docker adds layered imaging and automation to containers
Docker
- docker client
- docker host
- docker registry
Automation
Docker
Provides host environment
- Virtualbox
- AWS
- Xhyve
- Generic
Docker Machine
# Bootstrap (VM)
docker-machine create
eval "$(docker-machine env default)"
Docker
build images, pull images, run container, push images
Workflow
Docker
Orchestration of Docker Machine
Docker Compose (Fig)
web:
build: ./app
volumes:
- "./app:/src/app"
ports:
- "80:3000"
links:
- redis
- db
environment:
- PGHOST=db
- PGDATABASE=postgres
- PGUSER=postgres
redis:
image: redis:latest
ports:
- "6379:6379"
db:
image: postgres
Docker
Example
# Create Scripts
vi Dockerfile
# Bootstrap (Container)
docker build -t mywebapp .
docker run -d -p 8080:8080 mywebapp
# Interaction
docker exec -it mywebapp bash
# Test Web Service
curl -i ${SERVER}:8080
# Stop Web Service
docker ps
docker kill ${CONTAINER_HASH}
Docker Engine
Docker
Example
# Create Scripts
vi Dockerfile
vi docker-compose.yml
# Bootstrap (Container)
docker-compose up -d
# Interaction
docker exec -it mywebapp bash
# Test Web Service
curl -i ${SERVER}:8080
# Stop Container
docker-compose stop
Docker Compose
Docker
Example
# Create Scripts
vi Dockerfile
# Bootstrap (Container)
docker build -t mywebapp .
docker run -d -p 8080:8080 mywebapp
# Interaction
docker exec -it mywebapp bash
# Test Web Service
curl -i ${SERVER}:8080
# Stop Web Service
docker ps
docker kill ${CONTAINER_HASH}
# Create Scripts
vi Dockerfile
vi docker-compose.yml
# Bootstrap (Container)
docker-compose up -d
# Interaction
docker exec -it mywebapp bash
# Test Web Service
curl -i ${SERVER}:8080
# Stop Container
docker-compose stop
Docker Engine
Docker Compose
Docker
On Production
Production
- base (ec2)
- pull code (git)
- build image (docker)
- push image (docker)
- pull image (docker)
- provision container (ansible)
- orchestrate (ansible)
- deploy
Workflow Example
Production
Pets
- have a name
- special attention
- hand crafted
Cattle
- have number
- managed as a group
- automated
vs
Production
Snowflake
- managing configurations
- configuration (snow) drift
- snowflakes are brittle
- each snowflake is unique
Configured
At
Deployment
Production
Tools for Snowflake
Production
Pheonix
- immutable
- disposable
- replaceable
- identical
Configured
At
Build Time
Production
Tools for Pheonix
Hello World
Awesome Demo
HelloWorld Demo
Dockerfile
FROM node:argon
# Create app directory
ENV APP_HOME /usr/src/app
RUN mkdir -p $APP_HOME
WORKDIR $APP_HOME
# Install app dependencies
COPY package.json $APP_HOME/package.json
RUN npm install
# Bundle app source
COPY . $APP_HOME
EXPOSE 8080
CMD [ "npm", "start" ]
HelloWorld Demo
docker-compose.yml
version: '2'
services:
web:
build: .
ports:
- "8080:8080"
HelloWorld Demo
Start VM
# Configure Environment
docker-machine create
# Configure Environment
eval "$(docker-machine env default)"
HelloWorld Demo
Start Container & Test
# Boostrap Container
docker-compose up -d
# Get VM's IP Address
WEBSERVER=$(docker-machine ip "${DOCKER_MACHINE_NAME}") # set to docker ip
WEBSERVER=${WEBSERVER:-localhost} # default to localhost if not set
# Run Test
curl -i "${WEBSERVER}":8080
The End
References
- What Is DevOps? http://theagileadmin.com/what-is-devops/
- David Vile. If you think DevOps is BS, you may be a victim of bandwagon marketing. http://www.freeformdynamics.com/fullarticle.asp?aid=1877
- History of DevOps: http://itrevolution.com/the-history-of-devops/
- Pets vs Cattle Infrstructure
References
- Snowflake Server Pattern
-
Pheonix Server Pattern (Immutable Production)
- http://martinfowler.com/bliki/PhoenixServer.html
- http://martinfowler.com/bliki/ImmutableServer.html
- https://www.thoughtworks.com/insights/blog/rethinking-building-cloud-part-4-immutable-servers
- http://techblog.netflix.com/2013/03/ami-creation-with-aminator.html
- http://theagileadmin.com/2015/11/24/immutable-delivery/
- http://electric-cloud.com/blog/2015/03/immutable-servers-ftw/
Deleted Scenes
Devops
C – Culture A – Automation L – Lean M – Measurement S – Sharing
DevOps
What does DevOps do?
- Code – Code Development and Review, continuous integration tools
- Build – Version control tools, code merging, Build status
- Test – Test and results determine performance
- Package – Artifact repository, Application pre-deployment staging
- Release – Change management, Release approvals, release automation
- Configure – Infrastructure configuration and management, Infrastructure as Code tools
- Monitor – Applications performance monitoring, End user experience
HelloWorld Demo
server.js
'use strict';
const express = require('express');
// Constants
const PORT = 8080;
// Application
const app = express();
var ip = 0
// Multiple Route Scenario
app.get('/', function (req, res) {
res.send('Hello world!\n');
});
app.listen(PORT);
var ip = require("ip");
console.log('Running on http://' + ip.address() + ':' + PORT);
HelloWorld Demo
package.json
{
"name": "express_hello_world",
"version": "1.0.0",
"description": "Express Hello World",
"author": "Joaquin Menchaca <jmenchaca@gobalto.com>",
"main": "server.js",
"scripts": {
"start": "node server.js"
},
"dependencies": {
"express": "^4.13.3",
"ip": "^1.1.2"
}
}
HelloWorld Demo
Vagrantfile
PRIVATE_IP="10.10.10.4"
Vagrant.configure(2) do |config|
# base system is Ubuntu
config.vm.box = "ubuntu/trusty64"
# private IP for Docker Machine
config.vm.network "private_network", ip: PRIVATE_IP
# Install Docker short-cut
config.vm.provision "shell", path: "install_docker.sh"
end
HelloWorld Demo
Start VM
# Start Virtual Machine
vagrant up
# Docker Machine uses Vagrant
PRIVATE_IP="10.10.10.4"
PRIVATE_KEY=".vagrant/machines/default/virtualbox/private_key"
docker-machine create --driver generic \
--generic-ssh-user vagrant \
--generic-ssh-key "${PWD}/${PRIVATE_KEY}" \
--generic-ip-address "${PRIVATE_IP}" \
hello_vm
# Configure Environment
eval "$(docker-machine env hello_vm)"
Awesomify Dev
By Joaquín Menchaca
Awesomify Dev
Using Docker and Vagrant to increase Velocity
- 1,878