DevOps,
Dev Environments and Docker

- Chris Henry (@chrishenry)

A bit about me

DevOps

A culture that emphasizes collaboration and communication between teams while automating the process of software delivery and infrastructure changes.

Culture

The summation of what everyone says and does.

Communication & Empathy

More important than loops and queries

Team Productivity

Not your productivity.

Empathy & Communication Codified

  • Help others to understand and build your project
  • Reduce friction from development to production

12 Factor App

A methodology for building apps to be deployed on modern cloud platforms

Let's talk through some of the more important factors.

Codebase

One codebase tracked in revision control

Dependencies

Explicitly declare and isolate dependencies

Config

  • Data that determines how the app runs
  • Store config in the environment

The Environment

Environment variables are a set of dynamic named values that can affect the way running processes will behave on a computer. They are part of the environment in which a process runs.

- Wikipedia

The Environment


$ export NYCDA=nifty

$ echo $NYCDA
nifty

$ env | grep -i nyc
NYCDA=nifty

$ unset NYCDA

$ echo $NYCDA

$
            

Access in Ruby


$ cat env.rb
#!/usr/bin/env ruby

puts ENV['NYCDA']

$ ruby env.rb
nifty
            

Docker containers wrap up a piece of software in a complete filesystem that contains everything it needs to run.

Repeatability

For you, your teammates, stage and production

Isolation

You're gonna be working on more than one project at a time, what happens if they require different versions of Ruby, MySQL, Postgres, Python, etc?

A little bit of code

Dockerfile


FROM ruby:2.3.3

RUN apt-get update -qq && \
    apt-get install -y build-essential libpq-dev nodejs && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

RUN mkdir /rails-app
WORKDIR /rails-app

ADD Gemfile /rails-app/Gemfile
ADD Gemfile.lock /rails-app/Gemfile.lock

RUN bundle install
ADD . /rails-app
            

Docker Compose


version: '2'
services:
  db:
    image: mysql:latest
    env_file: .env
    volumes:
      - ./mysql-data/:/var/lib/mysql/
  web:
    build:
      context: ./rails-app/
    command: bundle exec rails s -p 3000 -b '0.0.0.0'
    env_file: .env
    environment:
      MYSQL_HOST: db
    volumes:
      - ./rails-app/:/rails-app/
    ports:
      - "3000:3000"
    depends_on:
      - db
              

Environment File (.env)


RAILS_ENV=docker-dev
MYSQL_PORT=3306
MYSQL_USER=your_user
MYSQL_PASSWORD=password
MYSQL_ROOT_PASSWORD=password
MYSQL_DATABASE=your_database
              

Database Yaml


docker-dev:
  <<: *default
  database: <%= ENV['MYSQL_DATABASE'] %>
  username: <%= ENV['MYSQL_USER'] %>
  password: <%= ENV['MYSQL_PASSWORD'] %>
  host: <%= ENV['MYSQL_HOST'] %>
  port: <%= ENV['MYSQL_PORT'] %>
              

Questions?

Thanks!!!1!