Skip to content

Latest commit

 

History

History
579 lines (535 loc) · 15.3 KB

cookbook.md

File metadata and controls

579 lines (535 loc) · 15.3 KB

Continuous delivery environment cookbook

This cookbook has been written to start an environment with the main components needed for a continuous integration or continuous delivery deployment. The main components deployed using this cookbook are Jenkins, used for task automation and orchestration, GitLab, as a source code management system, and finally, docker registry, where are pushed the new releases' images.

A resource, named continuous_delivery_service, belonging at this cookbook, is responsible to create those elements needed for a service to be run.

Note: This environment has been thought for testing, learning or developing purposes, then is not recomended to use it on a productive environment.

Table of Contents

Preconditions

This cookbook has been developed and tested using:

  • Vagrant version 1.8.7, with plugin vagrant-berkshelf 5.1.1
  • Vagrant is forced to use chef version '12.20.3'
  • Vagrant box ubuntu/xenial64, version 20170730.0.0

Dependencies

Continuous delivery's cookbook depends to:

Resources

In the next section, will be described the continuous_delivery_service resource, which is responsible to create those elements needed for a service to be run.

continuous_delivery_service

Properties

Property Type Description
name String Name for the service to be created
image Hash It defines the image used by container's service.
The image's definition Hash properties are:
name(required), repo, tag, source or action, defined at docker_image resource.
Example:

{
  'name': 'registry',
  'tag': '2',
  'action': 'pull_if_missing'
}
      
container Hash It defines the container where the service runs in.
The container's definition Hash properties are:
name(required), repo(required), tag, port, volumes, env or action, defined at docker_container resource.
Example:

{
  'name': 'registry',
  'repo': 'registry',
  'tag': '2',
  'port': '5000:5000',
  'env': [
    "REGISTRY_HOST=10.0.0.2 
  ],
  'action': 'create'
}
      
files Array This property requires an array of hashes where are defined the files that must be copied from to host.
Each hash could have the properties file(required), source(required), mode or action, defined at cookbook_file resource.
Example:

[
  {
    'file': '/srv/docker/jenkins-master/config.xml',
    'source': 'jenkins/config.xml',
    'action': 'create'
  },
  {
    'file': '/srv/docker/jenkins-master/jenkins_master_setup.sh',
    'source': 'jenkins/jenkins_master_setup.sh',
    'mode': '0755',
    'action': 'create'
  },
  {
    'file': '/srv/docker/jenkins-master/Dockerfile',
    'source': 'jenkins/jenkins-master/Dockerfile',
    'action': 'create'
  }
]
      
systemd_service Hash Defines the systemd services based 'systemd_service.erb' template.
The properties required to fill the template are:
  • name: Container's name where the service runs in.
  • description: A description about the service.
  • requires: Dependencies to other services, like docker services.
  • after: Whether services must start after another services. Mainly docker service.

Example:

{
  'name': 'registry',
  'description': 'Service for private docker registry',
  'requires': 'docker',
  'after': 'docker'
}
      

Actions

Action Description
deploy Creates those elements needed for the service to be run.
clear Removes all elements created during the service deployment.

Recipes

In the next section, are presented the recipies defined on this cookbook.

continuous_delivery-default

Default recipe controls recipes execution, installing the required pieces to the host and then deploys the continuous delivery environment components.

There are some opcional components not deployed by default, like Portainer or Registry UI, but is possible to deploy them changing some attributes' values. These attributes are described below.

Attribute Description Type Default
['continuous_delivery']['service']['registry_ui'] Enables a web console to manage Registry service. Boolean false
['continuous_delivery']['service']['portainer'] Enables Portainer's service, to manage docker engine. Boolean false

continuous_delivery-registry

Registry recipe is responsible to deploy the docker registry where the new releases' images must be pushed to.

Attributes

Attribute Description Type Default
['registry']['deploy']['clear'] Enable clear component's deployment before deploy it. Boolean false
['registry']['service'] Name of the service. String -
['registry']['systemd'] Systemd service definition to be used on continuous_delivery_service resource. Hash
{
  'name': node['registry']['service'],
  'description': 'Service for private docker registry',
  'requires': node['docker']['service'],
  'after': node['docker']['service']
}
      
['registry']['config']['host'] Host where is deployed Registry service. String 0.0.0.0
['registry']['config']['port'] Port where listen to Registry. String 5000
['registry']['config']['protocol'] Protocol where is configured Registry [http|https]. String http
['registry']['config']['addr'] Registry address. String
#{node['registry']['config']['host']}:#{node['registry']['config']['port']}
      
['registry']['docker']['image'] Image definition to be used on continuous_delivery_service resource. Hash
{
  'name': 'registry',
  'tag': '2',
  'action': 'pull_if_missing'
}
      
['registry']['docker']['container'] Container definition to be used on continuous_delivery_service resource. Hash
{
  'name': "#{node['registry']['service']}",
  'repo': "#{node['registry']['docker']['image'].name}",
  'tag': "#{node['registry']['docker']['image'].tag}",
  'port': "5000:#{node['registry']['config']['port']}",
  'env': [
    "REGISTRY_HOST=#{node['registry']['config']['host']}",
    "REGISTRY_STORAGE_DELETE_ENABLED=true"
  ],
  'action': 'create'
}
      

continuous_delivery-gitlab

Gitlab recipe is responsible to deploy the Gitlab component used as source code management system.

Attributes

Attribute Description Type Default
['gitlab']['deploy']['clear'] Enable clear component's deployment before deploy it. Boolean false
['gitlab']['config']['external_url'] External URL to login to GitLab. String http://localhost
['gitlab']['config']['listen_port'] Port configured to access into GitLab web portal. Integer 80
['gitlab']['config']['ssh_port'] Port configured to access into GitLab using ssh. Integer 2222
['gitlab']['config']['listen_https'] Enable https access. Boolean false
['gitlab']['directory'] List of directories to be created on host. Hash
{
  '/srv/gitlab/data' => {},
  '/srv/gitlab/logs' => {},
  '/srv/gitlab/config' => {}
}
['gitlab']['files'] List of files to be used on continuous_delivery_service resource. Array
[
  {
    'file': '/srv/gitlab/config/gitlab.rb',
    'source': '#is a template and will not be created be continuous_delivery_services resource',
    'action': 'create'
  }
]
['gitlab']['service'] Name of the service. String -
['gitlab']['systemd'] Systemd service definition to be used on continuous_delivery_service resource. Hash
{
  'name': node['gitlab']['service'],
  'description': 'gitlab service',
  'requires': node['docker']['service'],
  'after': node['docker']['service']
}
      
['gitlab']['docker']['image'] Image definition to be used on continuous_delivery_service resource. Hash
{
  'name': 'gitlab/gitlab-ce',
  'tag': 'latest',
  'action': 'pull_if_missing'
}
      
['gitlab']['docker']['container'] Container definition to be used on continuous_delivery_service resource. Hash
{
  'name': 'gitlab',
  'repo': "#{node['gitlab']['docker']['image'].name}",
  'volumes': [
    "/srv/gitlab/data:/var/opt/gitlab",
    "/srv/gitlab/logs:/var/log/gitlab",
    "/srv/gitlab/config:/etc/gitlab"
  ],
  'port': [
    "80:80",
    "443:443",
    "#{node['gitlab']['config']['ssh_port']}:22"
  ],
  'action': 'create'
}
      

continuous_delivery-jenkins

Jenkins recipe is responsible to deploy the Jenkins component, which lets to automate the delivery process and to release our application frequently.

Attributes

Attribute Description Type Default
['jenkins']['deploy']['clear'] Enable clear component's deployment before deploy it. Boolean false
['continuous_delivery']['service']['registry_ui'] Enable a web console for to manage Registry service. Boolean false
['continuous_delivery']['service']['portainer'] Enable Portainer's service, to manage docker engine. Boolean false

continuous_delivery-registry_ui

Registry UI recipe is responsible to deploy the component which will let to control the environment's docker registry status.

Attributes

Attribute Description Type Default
['registry_ui']['deploy']['clear'] Enable clear component's deployment before deploy it. Boolean false
['continuous_delivery']['service']['registry_ui'] Enable a web console for to manage Registry service. Boolean false
['continuous_delivery']['service']['portainer'] Enable Portainer's service, to manage docker engine. Boolean false

continuous_delivery-portainer

Portainer recipe is responsible to deploy the component which will let to control the host's docker engine.

Attributes

Attribute Description Type Default
['portainer']['deploy']['clear'] Enable clear component's deployment before deploy it. Boolean false
['continuous_delivery']['service']['registry_ui'] Enable a web console for to manage Registry service. Boolean false
['continuous_delivery']['service']['portainer'] Enable Portainer's service, to manage docker engine. Boolean false

Usage

Include continuous_delivery in your node's run_list:

env.vm.provision "chef_solo" do |chef|
  chef.add_recipe "continuous_delivery"
end

Examples

Some examples of how to modify your deployment changing the attributes' default values, into Vagrantfile.

  • Enable Portainer service:
env.vm.provision "chef_solo" do |chef|
  chef.add_recipe "continuous_delivery"
  chef.json = {
    :continuous_delivery => {
      :service => {
        :portainer => true,
        :registry_ui => false
      }
    }
  }
end
  • Clear old Registry before its new deployment:
env.vm.provision "chef_solo" do |chef|
  chef.add_recipe "continuous_delivery"
  chef.json = {
  :registry => {
    :deploy => {
      :clear => true
    }
  }  
}
end

Author

Author:: Aleix Penella (aleix.penella [at] gmail.com)