Skip to content
This repository has been archived by the owner on Nov 30, 2022. It is now read-only.

Commit

Permalink
Merge pull request #14 from codenamephp/resources
Browse files Browse the repository at this point in the history
Recreating recipes as resources
  • Loading branch information
bastianschwarz authored Jul 4, 2020
2 parents fb9cfd9 + 7819781 commit ca50633
Show file tree
Hide file tree
Showing 24 changed files with 304 additions and 178 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ install:
- eval "$(chef shell-init bash)"
- openssl aes-256-cbc -K $encrypted_f6ac716f1c72_key -iv $encrypted_f6ac716f1c72_iv -in codenamephp.pem.enc -out codenamephp.pem -d

script:
script:
- chef exec foodcritic .
- chef exec rubocop
- chef exec rspec
- travis_retry chef exec kitchen test
- chef exec kitchen test

before_deploy:
- chef exec knife cookbook metadata from file metadata.rb
Expand Down
59 changes: 59 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Rubocop",
"type": "shell",
"command": "rubocop -a",
"group": "test"
},
{
"label": "Foodcritic",
"type": "shell",
"command": "foodcritic .",
"group": "test"
},
{
"label": "RSpec",
"type": "shell",
"command": "rspec",
"group": "test"
},
{
"label": "Kitchen Test",
"type": "shell",
"command": "kitchen test"
},
{
"label": "Lint",
"dependsOn": [
"Rubocop",
"Foodcritic"
],
"problemMatcher": []
},
{
"label": "Unit",
"dependsOn": [
"RSpec"
]
},
{
"label": "Integration",
"dependsOn": [
"Kitchen Test"
]
},
{
"label": "All",
"dependsOn": [
"Lint",
"Unit",
"Integration"
],
"problemMatcher": []
}
]
}
2 changes: 1 addition & 1 deletion Berksfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ source 'https://supermarket.chef.io'

metadata

# cookbook 'test', path: './test/fixtures/cookbooks/test', group: :test
cookbook 'test', path: './test/fixtures/cookbooks/test', group: :test
5 changes: 5 additions & 0 deletions MIGRATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# 3.0

The recipes have been removed. Create a wrapper cookbook and use the resource there as needed. The service recipe was replaced by
the `codenamephp_docker_service` resource that does exactly the same as the recipe did. For docker-compose there is the
`codenamephp_docker_compose` resource
50 changes: 38 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,46 @@ This is just a wrapper cookbook for [docker][docker-github]
Add the cookbook to your Berksfile:

```ruby
cookbook 'codenamephp_docker', :github 'codenamephp/codenamephp_docker'
cookbook 'codenamephp_docker'
```

Add the cookbook to your runlist, e.g. in a role:

```json
{
"name": "default",
"chef_type": "role",
"json_class": "Chef::Role",
"run_list": [
"recipe[codenamephp_docker]"
]
}
Use the resources as needed in a wrapper cookbook. You can check out some examples either in this readme or in the test/fixtures/test cookbook.

## Resources
### Service
Uses the `docker_service` resource to install docker and create and start the service.

#### Actions
- `install`: Installs docker and creates and starts the service

#### Examples
With minimal properties:
```ruby
# Install
codenamephp_docker_service 'Install docker'
```

### Compose
Installs docker-compose as a docker image using the run script wrapper from docker-compose github. The bash completion is also installed.

#### Actions
- `install`: Installs docker-compose and bash completion

#### Properties
- `version`: The desired version as string, defaults to `'latest'`

#### Examples
With minimal properties:
```ruby
# Install
codenamephp_docker_service 'Install docker'
```

With custom version:
```ruby
codenamephp_docker_compose 'Install docker-compose' do
version '1.26.1'
end
```

[docker-github]: https://github.com/chef-cookbooks/docker
4 changes: 2 additions & 2 deletions kitchen.dokken.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ driver:
name: dokken
chef_version: current
privileged: true # because Docker and SystemD/Upstart

transport:
name: dokken

provisioner:
name: dokken
deprecations_as_errors: true
chef_license: accept

platforms:
- name: debian-10
driver:
Expand Down
4 changes: 2 additions & 2 deletions kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ platforms:
suites:
- name: default
run_list:
- recipe[codenamephp_docker::default]
- recipe[test]
verifier:
inspec_tests:
- test/smoke/default
- test/integration/default
attributes:
4 changes: 2 additions & 2 deletions metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
maintainer_email '[email protected]'
license 'Apache-2.0'
description 'Installs/Configures codenamephp_docker'
version '2.0.0'
chef_version '>= 13.0' if respond_to?(:chef_version)
version '3.0.0'
chef_version '>= 13.0'
issues_url 'https://github.com/codenamephp/chef.cookbook.docker/issues'
source_url 'https://github.com/codenamephp/chef.cookbook.docker'

Expand Down
27 changes: 0 additions & 27 deletions recipes/compose.rb

This file was deleted.

9 changes: 0 additions & 9 deletions recipes/default.rb

This file was deleted.

11 changes: 0 additions & 11 deletions recipes/service.rb

This file was deleted.

47 changes: 47 additions & 0 deletions resources/compose.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# frozen_string_literal: true

property :version, String, default: 'latest', description: 'The version of docker-compose to install, defaults to "latest"'

action :install do
remote_file 'download docker-compose' do
source compose_url
path '/usr/local/bin/docker-compose'
owner 'root'
group 'root'
mode '0755'
action :create
end

directory 'create bash completion directory' do
path '/etc/bash_completion.d'
owner 'root'
group 'root'
mode '0755'
recursive true
action :create
end

remote_file 'download bash completion' do
source lazy { compose_bash_completion_url }
path '/etc/bash_completion.d/docker-compose'
owner 'root'
group 'root'
mode '0755'
action :create
end
end

action_class do
def compose_url
distro = Mixlib::ShellOut.new('uname -s').run_command.stdout.strip
arch = Mixlib::ShellOut.new('uname -m').run_command.stdout.strip
file = "docker-compose-#{distro}-#{arch}"

new_resource.version == 'latest' ? "https://github.com/docker/compose/releases/latest/download/#{file}" : "https://github.com/docker/compose/releases/download/#{new_resource.version}/#{file}"
end

def compose_bash_completion_url
version = Mixlib::ShellOut.new("docker-compose -v | grep version | awk -F'[ ,]+' '{print $3}'").run_command.stdout.strip
"https://raw.githubusercontent.com/docker/compose/#{version}/contrib/completion/bash/docker-compose"
end
end
7 changes: 7 additions & 0 deletions resources/service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

action :install do
docker_service 'default' do
action %i[create start]
end
end
46 changes: 0 additions & 46 deletions spec/unit/recipes/compose_spec.rb

This file was deleted.

26 changes: 0 additions & 26 deletions spec/unit/recipes/default_spec.rb

This file was deleted.

Loading

0 comments on commit ca50633

Please sign in to comment.