Skip to content

Instantly share code, notes, and snippets.

@christian-fei
Forked from joebew42/devops-workshop.md
Created March 29, 2016 12:39

Revisions

  1. @joebew42 joebew42 revised this gist Mar 29, 2016. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion devops-workshop.md
    Original file line number Diff line number Diff line change
    @@ -768,7 +768,11 @@ Run `vagrant provision test`

    # Monitoring

    With Sensu [on-site]
    You'll find the *monitoring* cookbook [**here**](https://github.com/joebew42/dropwizard-sample-app/tree/devops-workshop/cookbooks)

    **Exercise**

    Try to integrate the cookbook in your infrastructure. See the previous section.

    # Cloud infrastructure

  2. @joebew42 joebew42 revised this gist Mar 29, 2016. 1 changed file with 8 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions devops-workshop.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,11 @@
    * [Creating a cookbook for our CI server](#creating-a-cookbook-for-our-ci-server)
    * [Adding a Test Machine](#adding-a-test-machine)
    * [Automates the application deployment](#automates-the-application-deployment)
    * [Deployment automation in Jenkins](#deployment-automation-in-jenkins)
    * [Logging](#logging)
    * [Monitoring](#monitoring)
    * [Cloud infrastructure](#cloud-infrastructure)

    # Creating a cookbook for our CI server

    ## Requirements
  3. @joebew42 joebew42 revised this gist Mar 29, 2016. 1 changed file with 35 additions and 2 deletions.
    37 changes: 35 additions & 2 deletions devops-workshop.md
    Original file line number Diff line number Diff line change
    @@ -723,11 +723,44 @@ Can you add the same "code coverage" for the **ci** cookbook ?

    ### Send logs from test/production environment

    TODO
    root Vagrantfile

    ```
    ...
    ['test', 'production'].each_with_index do |environment, index|
    config.vm.define "#{environment}" do |machine|
    machine.vm.hostname = "#{environment}"
    machine.vm.network :private_network, ip: "192.168.33.#{102 + index}"
    machine.vm.provider 'virtualbox' do |vb|
    vb.memory = 1024
    end
    machine.vm.provision :chef_zero, install: true do |chef|
    chef.verbose_logging
    chef.nodes_path = 'cookbooks'
    chef.file_cache_path = '/var/chef/cache'
    chef.add_recipe 'sample-app::default'
    chef.add_recipe 'sample-app::nginx'
    chef.add_recipe 'sample-app::application_deployment'
    chef.add_recipe 'logging::client'
    chef.json = {
    "databases": ["db_notes"],
    "logging": {
    "host": "192.168.33.110"
    }
    }
    end
    end
    end
    ...
    ```

    Run `vagrant provision test`

    # Monitoring

    TODO
    With Sensu [on-site]

    # Cloud infrastructure

  4. @joebew42 joebew42 revised this gist Mar 25, 2016. 1 changed file with 3 additions and 10 deletions.
    13 changes: 3 additions & 10 deletions devops-workshop.md
    Original file line number Diff line number Diff line change
    @@ -14,9 +14,10 @@ cd dropwizard-sample-app/cookbooks/
    ## Create the ci cookbook

    ```
    knife cookbook create ci -o .
    chef generate cookbook ci
    ```
    This creates a `scaffold` of the cookbook. The `-o .` option tells knife to create the cookbook in the current directory (default is /home/user/.chef/cookbooks/xxx).

    This will create a `scaffold` of the cookbook.

    ### Our first recipe

    @@ -118,14 +119,6 @@ Adding [`java`](https://supermarket.chef.io/cookbooks/java) as cookbook dependec
    depends 'java', '~> 1.39.0'
    ```

    Then, we have to use `Berkshelf` to tells kitchen how to resolve external cookbook dependencies (such as `java`). Create the file `Berksfile` with these lines:

    ```
    source "https://api.berkshelf.com"
    metadata
    ```

    Put some java's specific attributes in `attributes/java.rb`

    ```
  5. @joebew42 joebew42 revised this gist Mar 25, 2016. 1 changed file with 12 additions and 0 deletions.
    12 changes: 12 additions & 0 deletions devops-workshop.md
    Original file line number Diff line number Diff line change
    @@ -841,6 +841,18 @@ resource "aws_security_group" "sample-app" {
    protocol = "tcp"
    cidr_blocks = ["0.0.0.0/0"]
    }
    ingress {
    from_port = 22
    to_port = 22
    protocol = "tcp"
    cidr_blocks = ["0.0.0.0/0"]
    }
    egress {
    from_port = 0
    to_port = 0
    protocol = "-1"
    cidr_blocks = ["0.0.0.0/0"]
    }
    }
    resource "aws_instance" "sample-app" {
  6. @joebew42 joebew42 revised this gist Mar 25, 2016. 1 changed file with 94 additions and 4 deletions.
    98 changes: 94 additions & 4 deletions devops-workshop.md
    Original file line number Diff line number Diff line change
    @@ -755,7 +755,7 @@ Define packer template in `packer/sample-app.json`
    "aws_secret_key": "",
    "name": "default",
    "region": "eu-central-1",
    "source_ami": "ami-60baaa0c",
    "source_ami": "ami-7e9b7c11",
    "vpc_id": "",
    "subnet_id": ""
    },
    @@ -799,7 +799,7 @@ Create a Packer a `packer/private.json` file to customize Packer variables:
    {
    "aws_access_key": "{your access key}",
    "aws_secret_key": "{your secret key}",
    "name": "{your name}",
    "name": "{your name}"
    }
    ```

    @@ -813,6 +813,96 @@ Run Packer passing your custom configuration file and the template as arguments:

    Take note of generated **AMI id**.

    ## Terraform
    ## Create AWS stack with Terraform

    TODO
    Create terraform directory:

    ```
    mkdir terraform
    cd terraform
    ```

    Define terraform template in `terraform/sample-app.tf`

    ```
    provider "aws" {
    access_key = "${var.access_key}"
    secret_key = "${var.secret_key}"
    region = "eu-central-1"
    }
    resource "aws_security_group" "sample-app" {
    name = "${var.name}-devops-jumpstart-sample-app"
    description = "Security group for web that allows web traffic from internet"
    ingress {
    from_port = 80
    to_port = 80
    protocol = "tcp"
    cidr_blocks = ["0.0.0.0/0"]
    }
    }
    resource "aws_instance" "sample-app" {
    instance_type = "t2.small"
    ami = "${var.ami}"
    key_name = "devops-jumpstart"
    security_groups = ["${aws_security_group.sample-app.name}"]
    tags {
    Name = "${var.name} devops-jumpstart sample-app"
    }
    }
    output "ip" {
    value = "${aws_instance.sample-app.public_ip}"
    }
    ```

    Define terraform variables in `terraform/variables.tf`

    ```
    variable "access_key" {}
    variable "secret_key" {}
    variable "name" {
    default = "user"
    }
    variable "ami" {}
    ```

    Define terraform variables values in `terraform/terraform.tfvars`

    ```
    access_key = "{your access key}"
    secret_key = "{your secret key}"
    ami = "{packer generated AMI id}"
    name = "{your name}"
    ```

    Check terraform build plan

    ```
    terraform plan
    ```

    Create stack

    ```
    terraform apply
    ```

    Show stack state

    ```
    terraform show
    ```

    Take note of generated instance IP address.
    Visit instance IP address in a browser.

    Get AWS instance details using aws client

    ```
    aws configure
    aws ec2 describe-instances --filters "Name=tag:Name,Values={user} devops-jumpstart blog"
    ```
  7. @joebew42 joebew42 revised this gist Mar 25, 2016. 1 changed file with 73 additions and 2 deletions.
    75 changes: 73 additions & 2 deletions devops-workshop.md
    Original file line number Diff line number Diff line change
    @@ -738,9 +738,80 @@ TODO

    # Cloud infrastructure

    ## Packer
    ## Create AWS AMI with Packer

    Go back to project root and create `packer` directory

    ```
    mkdir packer
    ```

    Define packer template in `packer/sample-app.json`

    ```
    {
    "variables": {
    "aws_access_key": "",
    "aws_secret_key": "",
    "name": "default",
    "region": "eu-central-1",
    "source_ami": "ami-60baaa0c",
    "vpc_id": "",
    "subnet_id": ""
    },
    "builders": [
    {
    "access_key": "{{user `aws_access_key`}}",
    "secret_key": "{{user `aws_secret_key`}}",
    "type": "amazon-ebs",
    "region": "{{user `region`}}",
    "source_ami": "{{user `source_ami`}}",
    "ami_virtualization_type": "hvm",
    "vpc_id": "{{user `vpc_id`}}",
    "subnet_id": "{{user `subnet_id`}}",
    "instance_type": "t2.small",
    "ssh_username": "ubuntu",
    "ami_name": "{{user `name`}}-sample-app-{{isotime \"20060102-150405\"}}",
    "tags": {
    "Name": "{{user `name`}}-sample-app-{{isotime \"20060102-150405\"}}"
    }
    }
    ],
    "provisioners": [
    {
    "type": "chef-solo",
    "cookbook_paths": ["berks-cookbooks"],
    "run_list": [
    "sample-app::default",
    "sample-app::nginx",
    "sample-app::application_deployment"
    ]
    }
    ]
    }
    ```

    TODO
    Create a Packer a `packer/private.json` file to customize Packer variables:

    ```
    {
    "aws_access_key": "{your access key}",
    "aws_secret_key": "{your secret key}",
    "name": "{your name}",
    }
    ```

    Vendorize all needed cookbooks making them availabe to Packer:

    `berks vendor`

    Run Packer passing your custom configuration file and the template as arguments:

    `packer build -var-file=packer/private.json packer/sample-app.json`

    Take note of generated **AMI id**.

    ## Terraform

  8. @joebew42 joebew42 revised this gist Mar 25, 2016. 1 changed file with 19 additions and 1 deletion.
    20 changes: 19 additions & 1 deletion devops-workshop.md
    Original file line number Diff line number Diff line change
    @@ -726,4 +726,22 @@ Visits `http://192.168.33.110:5601` for Kibana Dashboard

    Take a look at *unit* and *integration* tests!

    Can you add the same "code coverage" for the **ci** cookbook ?
    Can you add the same "code coverage" for the **ci** cookbook ?

    ### Send logs from test/production environment

    TODO

    # Monitoring

    TODO

    # Cloud infrastructure

    ## Packer

    TODO

    ## Terraform

    TODO
  9. @joebew42 joebew42 revised this gist Mar 25, 2016. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions devops-workshop.md
    Original file line number Diff line number Diff line change
    @@ -720,6 +720,8 @@ Run `berks update`

    Run `vagrant up management`

    Visits `http://192.168.33.110:5601` for Kibana Dashboard

    **Exercise**

    Take a look at *unit* and *integration* tests!
  10. @joebew42 joebew42 revised this gist Mar 25, 2016. 1 changed file with 56 additions and 1 deletion.
    57 changes: 56 additions & 1 deletion devops-workshop.md
    Original file line number Diff line number Diff line change
    @@ -669,4 +669,59 @@ We have already create the `test` machine that is a production-like machine. We
    ...
    ```

    Run `vagrant up production`
    Run `vagrant up production`

    # Logging

    We are going to provision an ELK stack (elasticsearch, logstash and kibana)

    For practicality (time!) reason a simple logging cookbook can be found [**here**](https://github.com/joebew42/dropwizard-sample-app/tree/devops-workshop/cookbooks)

    The complete guide for the logging cookbook can be found [**here**](https://github.com/xpeppers/devops-jumpstart/wiki/4.-Centralized-logging)

    ## Add a new machine for logging purpose

    Adds the cookbook `logging` as berks dependency

    *Berksfile*

    ```
    source 'https://supermarket.chef.io'
    cookbook 'sample-app', path: './cookbooks/sample-app'
    cookbook 'ci', path: './cookbooks/ci'
    cookbook 'logging', path: './cookbooks/logging'
    ```

    Run `berks update`

    *Vagrantfile*

    ```
    ...
    config.vm.define "management" do |management|
    management.vm.hostname = "management"
    management.vm.network :private_network, ip: '192.168.33.110'
    management.vm.provider 'virtualbox' do |vb|
    vb.memory = 1024
    end
    management.vm.provision :chef_zero, install: true do |chef|
    chef.verbose_logging
    chef.nodes_path = 'cookbooks'
    chef.file_cache_path = '/var/chef/cache'
    chef.add_recipe 'logging::default'
    chef.json = {}
    end
    end
    ...
    ```

    Run `vagrant up management`

    **Exercise**

    Take a look at *unit* and *integration* tests!

    Can you add the same "code coverage" for the **ci** cookbook ?
  11. @joebew42 joebew42 revised this gist Mar 24, 2016. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion devops-workshop.md
    Original file line number Diff line number Diff line change
    @@ -667,4 +667,6 @@ We have already create the `test` machine that is a production-like machine. We
    end
    end
    ...
    ```
    ```

    Run `vagrant up production`
  12. @joebew42 joebew42 revised this gist Mar 24, 2016. 1 changed file with 46 additions and 1 deletion.
    47 changes: 46 additions & 1 deletion devops-workshop.md
    Original file line number Diff line number Diff line change
    @@ -420,7 +420,50 @@ run `vagrant up test` in order to boot the test machine.

    ## We'd like to add a reverse proxy in production

    TODO: nginx recipe
    *recipes/nginx.rb*

    ```
    package 'nginx'
    cookbook_file '/etc/nginx/sites-available/default' do
    source 'nginx-default-site'
    notifies :restart, 'service[nginx]', :delayed
    end
    service 'nginx'
    ```

    *files/nginx-default-site*

    ```
    upstream backend {
    server localhost:8080;
    }
    server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;
    server_name localhost;
    location / {
    proxy_pass http://backend;
    }
    }
    ```

    Now we can add the recipe in the root Vagrantfile

    *Vagrantfile*

    ```
    ...
    chef.add_recipe 'sample-app::default'
    chef.add_recipe 'sample-app::nginx'
    ...
    ```

    run `vagrant provision test`

    # Automates the application deployment

    @@ -515,6 +558,7 @@ Update the root Vagrantfile in order to execute this recipe:
    chef.nodes_path = 'cookbooks'
    chef.file_cache_path = '/var/chef/cache'
    chef.add_recipe 'sample-app::default'
    chef.add_recipe 'sample-app::nginx'
    chef.add_recipe 'sample-app::application_deployment'
    chef.json = {
    "databases": ["db_notes"]
    @@ -614,6 +658,7 @@ We have already create the `test` machine that is a production-like machine. We
    chef.nodes_path = 'cookbooks'
    chef.file_cache_path = '/var/chef/cache'
    chef.add_recipe 'sample-app::default'
    chef.add_recipe 'sample-app::nginx'
    chef.add_recipe 'sample-app::application_deployment'
    chef.json = {
    "databases": ["db_notes"]
  13. @joebew42 joebew42 revised this gist Mar 24, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion devops-workshop.md
    Original file line number Diff line number Diff line change
    @@ -603,7 +603,7 @@ We have already create the `test` machine that is a production-like machine. We
    ['test', 'production'].each_with_index do |environment, index|
    config.vm.define "#{environment}" do |machine|
    machine.vm.hostname = "#{environment}"
    machine.vm.network :private_network, ip: "192.168.33.#{101 + index}"
    machine.vm.network :private_network, ip: "192.168.33.#{102 + index}"
    machine.vm.provider 'virtualbox' do |vb|
    vb.memory = 1024
  14. @joebew42 joebew42 revised this gist Mar 24, 2016. 1 changed file with 29 additions and 1 deletion.
    30 changes: 29 additions & 1 deletion devops-workshop.md
    Original file line number Diff line number Diff line change
    @@ -594,4 +594,32 @@ Now we can create the job on jenkins to automates the deploy on test machine. We

    ## Deploy in production ? Simple now !

    TODO
    We have already create the `test` machine that is a production-like machine. We have only to add a new machine in the root Vagrantfile:

    *Vagrantfile*

    ```
    ...
    ['test', 'production'].each_with_index do |environment, index|
    config.vm.define "#{environment}" do |machine|
    machine.vm.hostname = "#{environment}"
    machine.vm.network :private_network, ip: "192.168.33.#{101 + index}"
    machine.vm.provider 'virtualbox' do |vb|
    vb.memory = 1024
    end
    machine.vm.provision :chef_zero, install: true do |chef|
    chef.verbose_logging
    chef.nodes_path = 'cookbooks'
    chef.file_cache_path = '/var/chef/cache'
    chef.add_recipe 'sample-app::default'
    chef.add_recipe 'sample-app::application_deployment'
    chef.json = {
    "databases": ["db_notes"]
    }
    end
    end
    end
    ...
    ```
  15. @joebew42 joebew42 revised this gist Mar 24, 2016. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions devops-workshop.md
    Original file line number Diff line number Diff line change
    @@ -418,6 +418,10 @@ We are telling the cookbook to use the new attribute `databases` with only a dat

    run `vagrant up test` in order to boot the test machine.

    ## We'd like to add a reverse proxy in production

    TODO: nginx recipe

    # Automates the application deployment

    In order to demostrate how is possible to automates an application deployment we are going to build from scratch a deployment workflow for our application. To do this we use [`fabric`](http://docs.fabfile.org/en/1.10/)
  16. @joebew42 joebew42 revised this gist Mar 24, 2016. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion devops-workshop.md
    Original file line number Diff line number Diff line change
    @@ -586,4 +586,8 @@ end

    Run the provision of the `ci` machine: `vagrant provision ci`

    Now we can crete the job on jenkins for deploy purpose.
    Now we can create the job on jenkins to automates the deploy on test machine. We'll adds a simple acceptance test with a `curl` command.

    ## Deploy in production ? Simple now !

    TODO
  17. @joebew42 joebew42 revised this gist Mar 24, 2016. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions devops-workshop.md
    Original file line number Diff line number Diff line change
    @@ -548,6 +548,7 @@ end
    package 'git'
    package 'python-virtualenv'
    package 'python-dev'
    mysql_service 'test' do
    port '3306'
  18. @joebew42 joebew42 revised this gist Mar 24, 2016. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions devops-workshop.md
    Original file line number Diff line number Diff line change
    @@ -583,4 +583,6 @@ remote_file "#{node['jenkins']['master']['home']}/.ssh/deployer" do
    end
    ```

    Run the provision of the `ci` machine: `vagrant provision ci`

    Now we can crete the job on jenkins for deploy purpose.
  19. @joebew42 joebew42 revised this gist Mar 24, 2016. 1 changed file with 62 additions and 0 deletions.
    62 changes: 62 additions & 0 deletions devops-workshop.md
    Original file line number Diff line number Diff line change
    @@ -522,3 +522,65 @@ Run the provision of the test machine: `vagrant provision test`

    ## Authorize Jenkins to perform deploy on Test machine

    In order to authorize jenkins to perform deploy on test machine we have to change the default recipe:

    * Install the virtualenv
    * Install the *deployer* private key
    * Add a jenkins plugin to run python code in a virtualenv

    `cd cookbooks/ci`

    *recipes/default.rb*

    ```
    include_recipe 'java'
    include_recipe 'maven'
    include_recipe 'jenkins::master'
    jenkins_plugin 'git'
    jenkins_plugin 'greenballs'
    jenkins_plugin 'junit'
    jenkins_plugin 'jobConfigHistory'
    jenkins_plugin 'delivery-pipeline-plugin'
    jenkins_plugin 'shiningpanda' do
    notifies :restart, 'service[jenkins]', :delayed
    end
    package 'git'
    package 'python-virtualenv'
    mysql_service 'test' do
    port '3306'
    version '5.5'
    initial_root_password 'root'
    action [:create, :start]
    end
    mysql2_chef_gem 'default' do
    action [:install]
    end
    mysql_database 'db_notes_test' do
    connection(
    :host => '127.0.0.1',
    :username => 'root',
    :password => 'root'
    )
    action :create
    end
    directory "#{node['jenkins']['master']['home']}/.ssh" do
    owner node['jenkins']['master']['user']
    group node['jenkins']['master']['group']
    mode '0700'
    end
    remote_file "#{node['jenkins']['master']['home']}/.ssh/deployer" do
    source 'https://gist.githubusercontent.com/joebew42/440c14b70ee305af31f6/raw/2ccd359966d523a026123a434dba262ca9a90e79/deployer'
    owner node['jenkins']['master']['user']
    group node['jenkins']['master']['group']
    mode '0600'
    end
    ```

    Now we can crete the job on jenkins for deploy purpose.
  20. @joebew42 joebew42 revised this gist Mar 24, 2016. 1 changed file with 5 additions and 3 deletions.
    8 changes: 5 additions & 3 deletions devops-workshop.md
    Original file line number Diff line number Diff line change
    @@ -244,8 +244,7 @@ jenkins_plugin 'git'
    jenkins_plugin 'greenballs'
    jenkins_plugin 'junit'
    jenkins_plugin 'jobConfigHistory'
    jenkins_plugin 'delivery-pipeline-plugin'
    jenkins_plugin 'build-pipeline-plugin' do
    jenkins_plugin 'delivery-pipeline-plugin' do
    notifies :restart, 'service[jenkins]', :delayed
    end
    @@ -519,4 +518,7 @@ Update the root Vagrantfile in order to execute this recipe:
    end
    ...
    ```
    Run the provision of the test machine: `vagrant provision test`
    Run the provision of the test machine: `vagrant provision test`

    ## Authorize Jenkins to perform deploy on Test machine

  21. @joebew42 joebew42 revised this gist Mar 24, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion devops-workshop.md
    Original file line number Diff line number Diff line change
    @@ -474,7 +474,7 @@ We want to extend our basic pipeline with a specific task for the deploy. There
    cd cookbooks/sample-app
    ```

    ## An home and a user used application deployment
    ## An home and a user used for application deployment

    *recipes/application_deployment.rb*

  22. @joebew42 joebew42 revised this gist Mar 24, 2016. 1 changed file with 41 additions and 2 deletions.
    43 changes: 41 additions & 2 deletions devops-workshop.md
    Original file line number Diff line number Diff line change
    @@ -479,5 +479,44 @@ cd cookbooks/sample-app
    *recipes/application_deployment.rb*

    ```
    TODO
    ```
    user 'deployer' do
    shell '/bin/bash'
    home '/home/deployer'
    manage_home true
    action :create
    end
    directory '/home/deployer/.ssh' do
    owner 'deployer'
    group 'deployer'
    mode '0700'
    end
    remote_file '/home/deployer/.ssh/authorized_keys' do
    source 'https://gist.githubusercontent.com/joebew42/cfb85d25199b94461c27/raw/ebf41312424286b302d4b7b8f645931d12e0c4b8/deployer.pub'
    owner 'deployer'
    group 'deployer'
    mode '0600'
    action :create
    end
    ```

    Update the root Vagrantfile in order to execute this recipe:

    *Vagrantfile*

    ```
    ...
    test.vm.provision :chef_zero, install: true do |chef|
    chef.verbose_logging
    chef.nodes_path = 'cookbooks'
    chef.file_cache_path = '/var/chef/cache'
    chef.add_recipe 'sample-app::default'
    chef.add_recipe 'sample-app::application_deployment'
    chef.json = {
    "databases": ["db_notes"]
    }
    end
    ...
    ```
    Run the provision of the test machine: `vagrant provision test`
  23. @joebew42 joebew42 revised this gist Mar 24, 2016. 1 changed file with 9 additions and 3 deletions.
    12 changes: 9 additions & 3 deletions devops-workshop.md
    Original file line number Diff line number Diff line change
    @@ -468,10 +468,16 @@ Let's try to deploy the application on the `test` machine

    # Deployment automation in Jenkins

    We want to extend our basic pipeline with a specific task for the deploy. There are some changes we have to introduce to the cookbook `jenkins`:
    We want to extend our basic pipeline with a specific task for the deploy. There are some changes we have to introduce in the cookbook `sample-app`:

    ```
    cd cookbooks/jenkins
    cd cookbooks/sample-app
    ```

    TODO
    ## An home and a user used application deployment

    *recipes/application_deployment.rb*

    ```
    TODO
    ```
  24. @joebew42 joebew42 revised this gist Mar 24, 2016. 1 changed file with 10 additions and 0 deletions.
    10 changes: 10 additions & 0 deletions devops-workshop.md
    Original file line number Diff line number Diff line change
    @@ -465,3 +465,13 @@ def migrate():
    Let's try to deploy the application on the `test` machine

    `fab -u vagrant -H 192.168.33.102 deploy`

    # Deployment automation in Jenkins

    We want to extend our basic pipeline with a specific task for the deploy. There are some changes we have to introduce to the cookbook `jenkins`:

    ```
    cd cookbooks/jenkins
    ```

    TODO
  25. @joebew42 joebew42 revised this gist Mar 24, 2016. 1 changed file with 44 additions and 1 deletion.
    45 changes: 44 additions & 1 deletion devops-workshop.md
    Original file line number Diff line number Diff line change
    @@ -421,4 +421,47 @@ run `vagrant up test` in order to boot the test machine.

    # Automates the application deployment

    TODO
    In order to demostrate how is possible to automates an application deployment we are going to build from scratch a deployment workflow for our application. To do this we use [`fabric`](http://docs.fabfile.org/en/1.10/)

    **requirements**

    * Python 2.7
    * virtualenv

    install fabric by `pip install -r requirements.txt`

    then create our first and very simple deploy workflow:

    *fabfile.py*

    ```
    from fabric.api import *
    env.warn_only = True
    def deploy():
    stop()
    copy_artefact()
    copy_configuration()
    migrate()
    start()
    def copy_artefact():
    put("target/sample-app-1.0-SNAPSHOT.jar", "/home/vagrant/")
    def copy_configuration():
    put("configuration.yml", "/home/vagrant/")
    def start():
    run("screen -S sample-app -d -m java -jar /home/vagrant/sample-app-1.0-SNAPSHOT.jar server configuration.yml", pty=False)
    def stop():
    run("screen -S sample-app -X quit", pty=False)
    def migrate():
    run("java -jar /home/vagrant/sample-app-1.0-SNAPSHOT.jar db migrate configuration.yml")
    ```

    Let's try to deploy the application on the `test` machine

    `fab -u vagrant -H 192.168.33.102 deploy`
  26. @joebew42 joebew42 renamed this gist Mar 24, 2016. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  27. @joebew42 joebew42 revised this gist Mar 24, 2016. 1 changed file with 7 additions and 1 deletion.
    8 changes: 7 additions & 1 deletion devops-ci-chef.md
    Original file line number Diff line number Diff line change
    @@ -415,4 +415,10 @@ Now we can add a new `test` machine in our root Vagrantfile
    end
    ...
    ```
    We are telling the cookbook to use the new attribute `databases` with only a database. Cool!
    We are telling the cookbook to use the new attribute `databases` with only a database. Cool!

    run `vagrant up test` in order to boot the test machine.

    # Automates the application deployment

    TODO
  28. @joebew42 joebew42 revised this gist Mar 24, 2016. 1 changed file with 85 additions and 1 deletion.
    86 changes: 85 additions & 1 deletion devops-ci-chef.md
    Original file line number Diff line number Diff line change
    @@ -331,4 +331,88 @@ cookbook 'sample-app', path: './cookbooks/sample-app'
    cookbook 'ci', path: './cookbooks/ci'
    ```

    run `berks update`
    run `berks update`

    # Adding a Test machine

    The `test` machine is used to simulate a production like environment. We can use to test deploy task or as a `staging` phase.

    The cookbook used to proviion the test machine is the same used for `dev` environment, with small changes.

    ```
    cd cookbooks/sample-app
    ```

    We have to modify the `default` recipe:

    *recipes/default.rb*

    ```
    ...
    ['db_notes', 'db_notes_test'].each do |database_name|
    mysql_database database_name do
    connection(
    :host => '127.0.0.1',
    :username => 'root',
    :password => 'root'
    )
    action :create
    end
    end
    ...
    ```

    In a `test` environment we don't need a database used for integration, so we can continue by extracting the list `['db_notes', 'db_notes_test']` as attribute of the cookbook, in order to assign new values programmatically during the provision.

    *atributes/default.rb*

    ```
    default['java']['jdk_version'] = '7'
    default['databases'] = ['db_notes', 'db_notes_test']
    ```

    *recipes/default.rb*

    ```
    ...
    node['databases'].each do |database_name|
    mysql_database database_name do
    connection(
    :host => '127.0.0.1',
    :username => 'root',
    :password => 'root'
    )
    action :create
    end
    end
    ...
    ```

    Now we can add a new `test` machine in our root Vagrantfile

    *Vagrantfile*

    ```
    ...
    config.vm.define "test" do |test|
    test.vm.hostname = "test"
    test.vm.network :private_network, ip: '192.168.33.102'
    test.vm.provider 'virtualbox' do |vb|
    vb.memory = 1024
    end
    test.vm.provision :chef_zero, install: true do |chef|
    chef.verbose_logging
    chef.nodes_path = 'cookbooks'
    chef.file_cache_path = '/var/chef/cache'
    chef.add_recipe 'sample-app::default'
    chef.json = {
    "databases": ["db_notes"]
    }
    end
    end
    ...
    ```
    We are telling the cookbook to use the new attribute `databases` with only a database. Cool!
  29. @joebew42 joebew42 revised this gist Mar 23, 2016. 1 changed file with 38 additions and 0 deletions.
    38 changes: 38 additions & 0 deletions devops-ci-chef.md
    Original file line number Diff line number Diff line change
    @@ -294,3 +294,41 @@ describe 'ci::default' do
    end
    end
    ```

    ## Adding the CI machine in the root Vagrantfile

    *Vagrantfile*

    ```
    ...
    config.vm.define "ci" do |ci|
    ci.vm.hostname = "ci"
    ci.vm.network :private_network, ip: '192.168.33.101'
    ci.vm.provider 'virtualbox' do |vb|
    vb.memory = 1024
    end
    ci.vm.provision :chef_zero, install: true do |chef|
    chef.verbose_logging
    chef.nodes_path = 'cookbooks'
    chef.file_cache_path = '/var/chef/cache'
    chef.add_recipe 'ci::default'
    chef.json = {}
    end
    end
    ...
    ```

    And then adds the cookbook `ci` as dependecy

    *Berksfile*

    ```
    source 'https://supermarket.chef.io'
    cookbook 'sample-app', path: './cookbooks/sample-app'
    cookbook 'ci', path: './cookbooks/ci'
    ```

    run `berks update`
  30. @joebew42 joebew42 revised this gist Mar 23, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion devops-ci-chef.md
    Original file line number Diff line number Diff line change
    @@ -192,7 +192,7 @@ include_recipe 'jenkins::master'

    run the converge with `kitchen converge`

    Visits: `http://192.168.33.101:8080` :D
    Visits: `http://192.168.33.33:8080` :D

    #### Just one simple integration test