Fotis Alexandrou

Hacking your workflow

 

How to achieve more efficient web development sessions

Who am I to speak

  • Full stack Web Developer
  • Automation Enthusiast
  • Wannabe musician
  • Nervous by default

The Problem

Inconsistency & lack of proper automation cost

working hours = $$$

Sources:

Hello, Vagrant

Vagrant is free and open-source software for creating and configuring virtual development environments. It can be seen as a wrapper around virtualization software such as VirtualBox, KVM, VMware and around configuration management software such as Chef, Salt or Puppet

Really easy to start

$ vagrant init hashicorp/precise32
$ vagrant up # provision
$ vagrant ssh
$ vagrant halt
$ vagrant destroy

Vagrant in the cloud

Requirements

  • An operating system
  • A browser & an internet connection
  • A terminal

https://www.vagrantup.com

Vagrantfile

# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

  # Every Vagrant virtual environment requires a box to build off of.
  config.vm.box = "ubuntu/trusty64"

  # forwarded ports
  config.vm.network "forwarded_port", guest: 80, host: 8080

  # IP configuration
  config.vm.network "private_network", ip: "192.168.6.66"

  # Shared folders
  config.vm.synced_folder "../blog", "/var/www/blog"
  config.vm.synced_folder "./", "/opt/puppet-repo"

  # Provider-specific configuration
  # VirtualBox:
  config.vm.provider "virtualbox" do |vb|
    # Give the box 1GB RAM
    vb.customize ["modifyvm", :id, "--memory", "1024"]
    # 2 CPUs
    vb.customize ["modifyvm", :id, "--cpus", "2"]
    # Enable following symlinks
    vb.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/v-root", "1"]
  end
end

Benefits

  • Consistency between local development & production server

  • Ability to use the same provisioning recipes on production

  • Prevents from bloating the host OS with many services

  • Production server changes can be tested locally before being destroying production

Gotchas

  • Apache / Nginx sendfile bug
    • http://bit.ly/12fn4Qp
  • Memory + CPU increase
    • http://bit.ly/12fnxSD
  • Symlinks handling
    • http://bit.ly/1G5uyT6
  • Mac filesystem
  • Sharing options & NFS

Provisioning

  • Provisioning tools such as Puppet or Chef
  • Reusable, testable
  • Infrastructure as code (ie. the Dream)

Puppet

Provisioner with a simple scripting language

class system-update {

  exec { 'apt-get update':
    command => 'apt-get update',
  }

  package { 'git':
    ensure => "installed",
    require => Exec['apt-get update'],
  }
}

Standalone or with agent

Benefits

... speaking of GitHub

  • OMG it's good
  • Facebook for developers
    • stalking other people's code
  • Git is what makes the difference

Git

Source Control Management tool

http://git-scm.com/

Core concepts

  • Everything is local
  • Freedom

So you're using SVN...

I'm happy you're enjoying your simple workflow but...

  • Branching is a nightmare
  • Always committing to remote repo
  • Always in need of internet connection
  • Huge repo? Your CPU hates you

Ready for git?

Getting started
Exhibit A: Building the new facebook

$ git init
$ git remote add origin [email protected]:falexandrou/new-facebook-soon-to-be-billionaire
$ git add --all .
$ git commit -m "Initial commit - New facebook done, waiting to become a legend"
$ git push origin master
$ git clone [email protected]:employee-one/new-facebook-soon-to-be-billionaire worst-idea-ever
$ git remote add upstream [email protected]:falexandrou/new-facebook-soon-to-be-billionaire
$ git checkout upstream/master -b my-branch
$ git fetch upstream
$ vim NewFacebook.js
$ git commit -am "I still think this is a terrible idea"
$ git push origin master

Employee joins, nobody knows why

"Killer" features

Branching

$ git checkout origin/master -b my-feature-branch
$ git br -m my-awesome-branch
$ git br -D my-older-branch
$ git checkout ab32bcff2da -b my-branch-from-commit

"Killer" features

Submodules

$ git submodule add [email protected]:falexandrou/my-git-submodule
$ git update --init --recursive

"Killer" features

Stash

$ git status
    modified:   src/less/some-file.less

$ git stash
Saved working directory and index state WIP on master: abc12345 fixes

$ git status
nothing to commit, working directory clean

$ git stash pop
    modified:   src/less/some-file.less
Dropped refs/[email protected]{0} (64ffabe91f396d6deafa777c8cbbecf7059c26c6b)

Common workflow

$ git status
$ git diff
$ git add --all .
$ git commit -m "Some commit message"
$ git push origin branch-name

...then probably open a "Pull Request"

Pull Requests

  • Tool by popular git tools (eg. GitHub, BitBucket, Gitorious, Gitlab)
  • Diff between current commit and the branch we're comparing against
  • Can be used as code review tool

Resources

Other features - Cheatsheet

  • Changing commit message
    • git commit --amend
  • Reseting to previous commit
    • git log --raw
    • git reset abc12345abcdef
  • Deleting a branch
    • git branch -D my-branch
  • Show all commits (even if squashed)
    • git log -g

Uses / Abuses

  • GitHub pages (git push to post)
  • Docker workflow

Docker

  • The container concept (not new)
  • Containers & images
  • Git-like set of commands

Docker Hub

  • Stores your Docker images
  • Browse public Docker images
  • Offers private images

Dockerfile

  • Plain bash-like syntax
  • Can add files in the context of the Dockerfile
  • $ docker build .
FROM ubuntu
MAINTAINER Fotis Alexandrou <[email protected]>

# Update aptitude
RUN apt-get update

# Install assuming "yes" to prompts
RUN apt-get install -y nodejs

# Create our document root file
RUN mkdir /var/www

# Add the node.js app file
ADD app.js /var/www/app.js

# Run the server
CMD ["/usr/bin/node", "/var/www/app.js"] 

Docker is not a VM

  • A Docker container runs by sharing the same linux kernel
    • Doesn't work in Windows & Mac (vagrant now looks handy, huh?
  • A Docker container is a process
  • A container is up whilst the process is running
  • The state of the docker can be committed to an image
  • A Docker container is reusable and disposable

Tools, tools, tools...

  • Easy to get carried away
  • Always something newer & sexier is available
  • Focus on whatever gets the job right

Thank You

Twitter: @falexandrou

GitHub: @falexandrou

https://www.falexandrou.com