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.
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
Continuous delivery's cookbook depends to:
- docker cookbook, version '~> 2.0'
- ssh_keygen cookbook, version '~> 1.1.0'
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.
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:
|
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:
|
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:
|
systemd_service | Hash |
Defines the systemd services based 'systemd_service.erb' template. The properties required to fill the template are:
Example:
|
Action | Description |
---|---|
deploy | Creates those elements needed for the service to be run. |
clear | Removes all elements created during the service deployment. |
In the next section, are presented the recipies defined on this cookbook.
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 |
Registry recipe is responsible to deploy the docker registry where the new releases' images must be pushed to.
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' } |
Gitlab recipe is responsible to deploy the Gitlab component used as source code management system.
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' } |
Jenkins recipe is responsible to deploy the Jenkins component, which lets to automate the delivery process and to release our application frequently.
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 |
Registry UI recipe is responsible to deploy the component which will let to control the environment's docker registry status.
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 |
Portainer recipe is responsible to deploy the component which will let to control the host's docker engine.
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 |
Include continuous_delivery
in your node's run_list
:
env.vm.provision "chef_solo" do |chef|
chef.add_recipe "continuous_delivery"
end
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:: Aleix Penella (aleix.penella [at] gmail.com)