From 2d2e806f8462fd55684391952d9dcb7b94691630 Mon Sep 17 00:00:00 2001 From: Yogesh Date: Wed, 19 Apr 2017 06:03:42 -0400 Subject: [PATCH] adding postgresql cookbook --- cookbooks/apache/metadata.rb | 2 +- cookbooks/apache/recipes/default.rb | 1 + .../.delivery/build_cookbook/.kitchen.yml | 21 +++ .../.delivery/build_cookbook/Berksfile | 9 ++ .../.delivery/build_cookbook/LICENSE | 3 + .../.delivery/build_cookbook/README.md | 146 ++++++++++++++++++ .../.delivery/build_cookbook/chefignore | 107 +++++++++++++ .../data_bags/keys/delivery_builder_keys.json | 1 + .../.delivery/build_cookbook/metadata.rb | 7 + .../build_cookbook/recipes/default.rb | 6 + .../build_cookbook/recipes/deploy.rb | 6 + .../build_cookbook/recipes/functional.rb | 6 + .../.delivery/build_cookbook/recipes/lint.rb | 6 + .../build_cookbook/recipes/provision.rb | 6 + .../build_cookbook/recipes/publish.rb | 6 + .../build_cookbook/recipes/quality.rb | 6 + .../build_cookbook/recipes/security.rb | 6 + .../.delivery/build_cookbook/recipes/smoke.rb | 6 + .../build_cookbook/recipes/syntax.rb | 6 + .../.delivery/build_cookbook/recipes/unit.rb | 6 + .../build_cookbook/secrets/fakey-mcfakerton | 0 .../test/fixtures/cookbooks/test/metadata.rb | 2 + .../cookbooks/test/recipes/default.rb | 7 + cookbooks/postgresql/.delivery/config.json | 12 ++ cookbooks/postgresql/.delivery/project.toml | 36 +++++ cookbooks/postgresql/.gitignore | 21 +++ cookbooks/postgresql/.kitchen.yml | 26 ++++ cookbooks/postgresql/Berksfile | 3 + cookbooks/postgresql/README.md | 4 + cookbooks/postgresql/chefignore | 107 +++++++++++++ cookbooks/postgresql/metadata.rb | 19 +++ cookbooks/postgresql/recipes/default.rb | 20 +++ cookbooks/postgresql/spec/spec_helper.rb | 2 + .../spec/unit/recipes/default_spec.rb | 20 +++ .../test/smoke/default/default_test.rb | 18 +++ 35 files changed, 659 insertions(+), 1 deletion(-) create mode 100644 cookbooks/postgresql/.delivery/build_cookbook/.kitchen.yml create mode 100644 cookbooks/postgresql/.delivery/build_cookbook/Berksfile create mode 100644 cookbooks/postgresql/.delivery/build_cookbook/LICENSE create mode 100644 cookbooks/postgresql/.delivery/build_cookbook/README.md create mode 100644 cookbooks/postgresql/.delivery/build_cookbook/chefignore create mode 100644 cookbooks/postgresql/.delivery/build_cookbook/data_bags/keys/delivery_builder_keys.json create mode 100644 cookbooks/postgresql/.delivery/build_cookbook/metadata.rb create mode 100644 cookbooks/postgresql/.delivery/build_cookbook/recipes/default.rb create mode 100644 cookbooks/postgresql/.delivery/build_cookbook/recipes/deploy.rb create mode 100644 cookbooks/postgresql/.delivery/build_cookbook/recipes/functional.rb create mode 100644 cookbooks/postgresql/.delivery/build_cookbook/recipes/lint.rb create mode 100644 cookbooks/postgresql/.delivery/build_cookbook/recipes/provision.rb create mode 100644 cookbooks/postgresql/.delivery/build_cookbook/recipes/publish.rb create mode 100644 cookbooks/postgresql/.delivery/build_cookbook/recipes/quality.rb create mode 100644 cookbooks/postgresql/.delivery/build_cookbook/recipes/security.rb create mode 100644 cookbooks/postgresql/.delivery/build_cookbook/recipes/smoke.rb create mode 100644 cookbooks/postgresql/.delivery/build_cookbook/recipes/syntax.rb create mode 100644 cookbooks/postgresql/.delivery/build_cookbook/recipes/unit.rb create mode 100644 cookbooks/postgresql/.delivery/build_cookbook/secrets/fakey-mcfakerton create mode 100644 cookbooks/postgresql/.delivery/build_cookbook/test/fixtures/cookbooks/test/metadata.rb create mode 100644 cookbooks/postgresql/.delivery/build_cookbook/test/fixtures/cookbooks/test/recipes/default.rb create mode 100644 cookbooks/postgresql/.delivery/config.json create mode 100644 cookbooks/postgresql/.delivery/project.toml create mode 100644 cookbooks/postgresql/.gitignore create mode 100644 cookbooks/postgresql/.kitchen.yml create mode 100644 cookbooks/postgresql/Berksfile create mode 100644 cookbooks/postgresql/README.md create mode 100644 cookbooks/postgresql/chefignore create mode 100644 cookbooks/postgresql/metadata.rb create mode 100644 cookbooks/postgresql/recipes/default.rb create mode 100644 cookbooks/postgresql/spec/spec_helper.rb create mode 100644 cookbooks/postgresql/spec/unit/recipes/default_spec.rb create mode 100644 cookbooks/postgresql/test/smoke/default/default_test.rb diff --git a/cookbooks/apache/metadata.rb b/cookbooks/apache/metadata.rb index 159234f..bdf557b 100644 --- a/cookbooks/apache/metadata.rb +++ b/cookbooks/apache/metadata.rb @@ -4,7 +4,7 @@ license 'all_rights' description 'Installs/Configures apache' long_description 'Installs/Configures apache' -version '0.1.0' +version '0.1.1' # The `issues_url` points to the location where issues for this cookbook are # tracked. A `View Issues` link will be displayed on this cookbook's page when diff --git a/cookbooks/apache/recipes/default.rb b/cookbooks/apache/recipes/default.rb index e0bf6bf..4a2d0e8 100644 --- a/cookbooks/apache/recipes/default.rb +++ b/cookbooks/apache/recipes/default.rb @@ -14,3 +14,4 @@ action [:start, :enable] end +include_recipe 'apache::websites' diff --git a/cookbooks/postgresql/.delivery/build_cookbook/.kitchen.yml b/cookbooks/postgresql/.delivery/build_cookbook/.kitchen.yml new file mode 100644 index 0000000..2d3fce6 --- /dev/null +++ b/cookbooks/postgresql/.delivery/build_cookbook/.kitchen.yml @@ -0,0 +1,21 @@ +--- +driver: + name: vagrant + synced_folders: + - [<%= File.join(ENV['PWD'], '..', '..')%>, '/tmp/repo-data'] + +provisioner: + name: chef_zero + encrypted_data_bag_secret_key_path: 'secrets/fakey-mcfakerton' + data_bags_path: './data_bags' + +platforms: + - name: ubuntu-16.04 + - name: centos-7.2 + +suites: + - name: default + run_list: + - recipe[delivery_build::default] + - recipe[test] + attributes: diff --git a/cookbooks/postgresql/.delivery/build_cookbook/Berksfile b/cookbooks/postgresql/.delivery/build_cookbook/Berksfile new file mode 100644 index 0000000..fe9c94f --- /dev/null +++ b/cookbooks/postgresql/.delivery/build_cookbook/Berksfile @@ -0,0 +1,9 @@ +source 'https://supermarket.chef.io' + +metadata + +group :delivery do + cookbook 'delivery_build', git: 'https://github.com/chef-cookbooks/delivery_build' + cookbook 'delivery-base', git: 'https://github.com/chef-cookbooks/delivery-base' + cookbook 'test', path: './test/fixtures/cookbooks/test' +end diff --git a/cookbooks/postgresql/.delivery/build_cookbook/LICENSE b/cookbooks/postgresql/.delivery/build_cookbook/LICENSE new file mode 100644 index 0000000..d31c097 --- /dev/null +++ b/cookbooks/postgresql/.delivery/build_cookbook/LICENSE @@ -0,0 +1,3 @@ +Copyright 2017 The Authors + +All rights reserved, do not redistribute. diff --git a/cookbooks/postgresql/.delivery/build_cookbook/README.md b/cookbooks/postgresql/.delivery/build_cookbook/README.md new file mode 100644 index 0000000..1ecf0b7 --- /dev/null +++ b/cookbooks/postgresql/.delivery/build_cookbook/README.md @@ -0,0 +1,146 @@ +# build_cookbook + +A build cookbook for running the parent project through Chef Delivery + +This build cookbook should be customized to suit the needs of the parent project. Using this cookbook can be done outside of Chef Delivery, too. If the parent project is a Chef cookbook, we've detected that and "wrapped" [delivery-truck](https://github.com/chef-cookbooks/delivery-truck). That means it is a dependency, and each of its pipeline phase recipes is included in the appropriate phase recipes in this cookbook. If the parent project is not a cookbook, it's left as an exercise to the reader to customize the recipes as needed for each phase in the pipeline. + +## .delivery/config.json + +In the parent directory to this build_cookbook, the `config.json` can be modified as necessary. For example, phases can be skipped, publishing information can be added, and so on. Refer to customer support or the Chef Delivery documentation for assistance on what options are available for this configuration. + +## Test Kitchen - Local Verify Testing + +This cookbook also has a `.kitchen.yml` which can be used to create local build nodes with Test Kitchen to perform the verification phases, `unit`, `syntax`, and `lint`. When running `kitchen converge`, the instances will be set up like Chef Delivery "build nodes" with the [delivery_build cookbook](https://github.com/chef-cookbooks/delivery_build). The reason for this is to make sure that the same exact kind of nodes are used by this build cookbook are run on the local workstation as would run Delivery. It will run `delivery job verify PHASE` for the parent project. + +Modify the `.kitchen.yml` if necessary to change the platforms or other configuration to run the verify phases. After making changes in the parent project, `cd` into this directory (`.delivery/build_cookbook`), and run: + +``` +kitchen test +``` + +## Recipes + +Each of the recipes in this build_cookbook are run in the named phase during the Chef Delivery pipeline. The `unit`, `syntax`, and `lint` recipes are additionally run when using Test Kitchen for local testing as noted in the above section. + +## Making Changes - Cookbook Example + +When making changes in the parent project (that which lives in `../..` from this directory), or in the recipes in this build cookbook, there is a bespoke workflow for Chef Delivery. As an example, we'll discuss a Chef Cookbook as the parent. + +First, create a new branch for the changes. + +``` +git checkout -b testing-build-cookbook +``` + +Next, increment the version in the metadata.rb. This should be in the _parent_, not in this, the build_cookbook. If this is not done, the verify phase will fail. + +``` +% git diff + +-version '0.1.0' ++version '0.1.1' +``` + +The change we'll use for an example is to install the `zsh` package. Write a failing ChefSpec in the cookbook project's `spec/unit/recipes/default_spec.rb`. + +```ruby +require 'spec_helper' + +describe 'godzilla::default' do + context 'When all attributes are default, on an unspecified platform' do + let(:chef_run) do + runner = ChefSpec::ServerRunner.new + runner.converge(described_recipe) + end + + it 'installs zsh' do + expect(chef_run).to install_package('zsh') + end + end +end +``` + +Commit the local changes as work in progress. The `delivery job` expects to use a clean git repository. + +``` +git add ../.. +git commit -m 'WIP: Testing changes' +``` + +From _this_ directory (`.delivery/build_cookbook`, relative to the parent cookbook project), run + +``` +cd .delivery/build_cookbook +kitchen converge +``` + +This will take some time at first, because the VMs need to be created, Chef installed, the Delivery CLI installed, etc. Later runs will be faster until they are destroyed. It will also fail on the first VM, as expected, because we wrote the test first. Now edit the parent cookbook project's default recipe to install `zsh`. + +``` +cd ../../ +$EDITOR/recipes/default.rb +``` + +It should look like this: + +``` +package 'zsh' +``` + +Create another commit. + +``` +git add . +git commit -m 'WIP: Install zsh in default recipe' +``` + +Now rerun kitchen from the build_cookbook. + +``` +cd .delivery/build_cookbook +kitchen converge +``` + +This will take awhile because it will now pass on the first VM, and then create the second VM. We should have warned you this was a good time for a coffee break. + +``` +Recipe: test::default + +- execute HOME=/home/vagrant delivery job verify unit --server localhost --ent test --org kitchen + * execute[HOME=/home/vagrant delivery job verify lint --server localhost --ent test --org kitchen] action run + - execute HOME=/home/vagrant delivery job verify lint --server localhost --ent test --org kitchen + + - execute HOME=/home/vagrant delivery job verify syntax --server localhost --ent test --org kitchen + +Running handlers: +Running handlers complete +Chef Client finished, 3/32 resources updated in 54.665445968 seconds +Finished converging (1m26.83s). +``` + +Victory is ours! Our verify phase passed on the build nodes. + +We are ready to run this through our Delivery pipeline. Simply run `delivery review` on the local system from the parent project, and it will open a browser window up to the change we just added. + +``` +cd ../.. +delivery review +``` + +## FAQ + +### Why don't I just run rspec and foodcritic/rubocop on my local system? + +An objection to the Test Kitchen approach is that it is much faster to run the unit, lint, and syntax commands for the project on the local system. That is totally true, and also totally valid. Do that for the really fast feedback loop. However, the dance we do with Test Kitchen brings a much higher degree of confidence in the changes we're making, that everything will run on the build nodes in Chef Delivery. We strongly encourage this approach before actually pushing the changes to Delivery. + +### Why do I have to make a commit every time? + +When running `delivery job`, it expects to merge the commit for the changeset against the clean master branch. If we don't save our progress by making a commit, our local changes aren't run through `delivery job` in the Test Kitchen build instances. We can always perform an interactive rebase, and modify the original changeset message in Delivery with `delivery review --edit`. The latter won't modify the git commits, only the changeset in Delivery. + +### What do I do next? + +Make changes in the cookbook project as required for organizational goals and needs. Modify the `build_cookbook` as necessary for the pipeline phases that the cookbook should go through. + +### What if I get stuck? + +Contact Chef Support, or your Chef Customer Success team and they will help you get unstuck. diff --git a/cookbooks/postgresql/.delivery/build_cookbook/chefignore b/cookbooks/postgresql/.delivery/build_cookbook/chefignore new file mode 100644 index 0000000..38e7379 --- /dev/null +++ b/cookbooks/postgresql/.delivery/build_cookbook/chefignore @@ -0,0 +1,107 @@ +# Put files/directories that should be ignored in this file when uploading +# to a chef-server or supermarket. +# Lines that start with '# ' are comments. + +# OS generated files # +###################### +.DS_Store +Icon? +nohup.out +ehthumbs.db +Thumbs.db + +# SASS # +######## +.sass-cache + +# EDITORS # +########### +\#* +.#* +*~ +*.sw[a-z] +*.bak +REVISION +TAGS* +tmtags +*_flymake.* +*_flymake +*.tmproj +.project +.settings +mkmf.log + +## COMPILED ## +############## +a.out +*.o +*.pyc +*.so +*.com +*.class +*.dll +*.exe +*/rdoc/ + +# Testing # +########### +.watchr +.rspec +spec/* +spec/fixtures/* +test/* +features/* +examples/* +Guardfile +Procfile +.kitchen* +.rubocop.yml +spec/* +Rakefile +.travis.yml +.foodcritic +.codeclimate.yml + +# SCM # +####### +.git +*/.git +.gitignore +.gitmodules +.gitconfig +.gitattributes +.svn +*/.bzr/* +*/.hg/* +*/.svn/* + +# Berkshelf # +############# +Berksfile +Berksfile.lock +cookbooks/* +tmp + +# Policyfile # +############## +Policyfile.rb +Policyfile.lock.json + +# Cookbooks # +############# +CONTRIBUTING* +CHANGELOG* +TESTING* +MAINTAINERS.toml + +# Strainer # +############ +Colanderfile +Strainerfile +.colander +.strainer + +# Vagrant # +########### +.vagrant +Vagrantfile diff --git a/cookbooks/postgresql/.delivery/build_cookbook/data_bags/keys/delivery_builder_keys.json b/cookbooks/postgresql/.delivery/build_cookbook/data_bags/keys/delivery_builder_keys.json new file mode 100644 index 0000000..af375ea --- /dev/null +++ b/cookbooks/postgresql/.delivery/build_cookbook/data_bags/keys/delivery_builder_keys.json @@ -0,0 +1 @@ +{"id": "delivery_builder_keys"} \ No newline at end of file diff --git a/cookbooks/postgresql/.delivery/build_cookbook/metadata.rb b/cookbooks/postgresql/.delivery/build_cookbook/metadata.rb new file mode 100644 index 0000000..10330e7 --- /dev/null +++ b/cookbooks/postgresql/.delivery/build_cookbook/metadata.rb @@ -0,0 +1,7 @@ +name 'build_cookbook' +maintainer 'The Authors' +maintainer_email 'you@example.com' +license 'all_rights' +version '0.1.0' + +depends 'delivery-truck' diff --git a/cookbooks/postgresql/.delivery/build_cookbook/recipes/default.rb b/cookbooks/postgresql/.delivery/build_cookbook/recipes/default.rb new file mode 100644 index 0000000..b2746b5 --- /dev/null +++ b/cookbooks/postgresql/.delivery/build_cookbook/recipes/default.rb @@ -0,0 +1,6 @@ +# +# Cookbook:: build_cookbook +# Recipe:: default +# +# Copyright:: 2017, The Authors, All Rights Reserved. +include_recipe 'delivery-truck::default' diff --git a/cookbooks/postgresql/.delivery/build_cookbook/recipes/deploy.rb b/cookbooks/postgresql/.delivery/build_cookbook/recipes/deploy.rb new file mode 100644 index 0000000..9a61010 --- /dev/null +++ b/cookbooks/postgresql/.delivery/build_cookbook/recipes/deploy.rb @@ -0,0 +1,6 @@ +# +# Cookbook:: build_cookbook +# Recipe:: deploy +# +# Copyright:: 2017, The Authors, All Rights Reserved. +include_recipe 'delivery-truck::deploy' diff --git a/cookbooks/postgresql/.delivery/build_cookbook/recipes/functional.rb b/cookbooks/postgresql/.delivery/build_cookbook/recipes/functional.rb new file mode 100644 index 0000000..cae646d --- /dev/null +++ b/cookbooks/postgresql/.delivery/build_cookbook/recipes/functional.rb @@ -0,0 +1,6 @@ +# +# Cookbook:: build_cookbook +# Recipe:: functional +# +# Copyright:: 2017, The Authors, All Rights Reserved. +include_recipe 'delivery-truck::functional' diff --git a/cookbooks/postgresql/.delivery/build_cookbook/recipes/lint.rb b/cookbooks/postgresql/.delivery/build_cookbook/recipes/lint.rb new file mode 100644 index 0000000..40aee0c --- /dev/null +++ b/cookbooks/postgresql/.delivery/build_cookbook/recipes/lint.rb @@ -0,0 +1,6 @@ +# +# Cookbook:: build_cookbook +# Recipe:: lint +# +# Copyright:: 2017, The Authors, All Rights Reserved. +include_recipe 'delivery-truck::lint' diff --git a/cookbooks/postgresql/.delivery/build_cookbook/recipes/provision.rb b/cookbooks/postgresql/.delivery/build_cookbook/recipes/provision.rb new file mode 100644 index 0000000..57d0a78 --- /dev/null +++ b/cookbooks/postgresql/.delivery/build_cookbook/recipes/provision.rb @@ -0,0 +1,6 @@ +# +# Cookbook:: build_cookbook +# Recipe:: provision +# +# Copyright:: 2017, The Authors, All Rights Reserved. +include_recipe 'delivery-truck::provision' diff --git a/cookbooks/postgresql/.delivery/build_cookbook/recipes/publish.rb b/cookbooks/postgresql/.delivery/build_cookbook/recipes/publish.rb new file mode 100644 index 0000000..ad890fd --- /dev/null +++ b/cookbooks/postgresql/.delivery/build_cookbook/recipes/publish.rb @@ -0,0 +1,6 @@ +# +# Cookbook:: build_cookbook +# Recipe:: publish +# +# Copyright:: 2017, The Authors, All Rights Reserved. +include_recipe 'delivery-truck::publish' diff --git a/cookbooks/postgresql/.delivery/build_cookbook/recipes/quality.rb b/cookbooks/postgresql/.delivery/build_cookbook/recipes/quality.rb new file mode 100644 index 0000000..f5d4d74 --- /dev/null +++ b/cookbooks/postgresql/.delivery/build_cookbook/recipes/quality.rb @@ -0,0 +1,6 @@ +# +# Cookbook:: build_cookbook +# Recipe:: quality +# +# Copyright:: 2017, The Authors, All Rights Reserved. +include_recipe 'delivery-truck::quality' diff --git a/cookbooks/postgresql/.delivery/build_cookbook/recipes/security.rb b/cookbooks/postgresql/.delivery/build_cookbook/recipes/security.rb new file mode 100644 index 0000000..7d47af1 --- /dev/null +++ b/cookbooks/postgresql/.delivery/build_cookbook/recipes/security.rb @@ -0,0 +1,6 @@ +# +# Cookbook:: build_cookbook +# Recipe:: security +# +# Copyright:: 2017, The Authors, All Rights Reserved. +include_recipe 'delivery-truck::security' diff --git a/cookbooks/postgresql/.delivery/build_cookbook/recipes/smoke.rb b/cookbooks/postgresql/.delivery/build_cookbook/recipes/smoke.rb new file mode 100644 index 0000000..2203cbd --- /dev/null +++ b/cookbooks/postgresql/.delivery/build_cookbook/recipes/smoke.rb @@ -0,0 +1,6 @@ +# +# Cookbook:: build_cookbook +# Recipe:: smoke +# +# Copyright:: 2017, The Authors, All Rights Reserved. +include_recipe 'delivery-truck::smoke' diff --git a/cookbooks/postgresql/.delivery/build_cookbook/recipes/syntax.rb b/cookbooks/postgresql/.delivery/build_cookbook/recipes/syntax.rb new file mode 100644 index 0000000..7147f96 --- /dev/null +++ b/cookbooks/postgresql/.delivery/build_cookbook/recipes/syntax.rb @@ -0,0 +1,6 @@ +# +# Cookbook:: build_cookbook +# Recipe:: syntax +# +# Copyright:: 2017, The Authors, All Rights Reserved. +include_recipe 'delivery-truck::syntax' diff --git a/cookbooks/postgresql/.delivery/build_cookbook/recipes/unit.rb b/cookbooks/postgresql/.delivery/build_cookbook/recipes/unit.rb new file mode 100644 index 0000000..fa6d9ba --- /dev/null +++ b/cookbooks/postgresql/.delivery/build_cookbook/recipes/unit.rb @@ -0,0 +1,6 @@ +# +# Cookbook:: build_cookbook +# Recipe:: unit +# +# Copyright:: 2017, The Authors, All Rights Reserved. +include_recipe 'delivery-truck::unit' diff --git a/cookbooks/postgresql/.delivery/build_cookbook/secrets/fakey-mcfakerton b/cookbooks/postgresql/.delivery/build_cookbook/secrets/fakey-mcfakerton new file mode 100644 index 0000000..e69de29 diff --git a/cookbooks/postgresql/.delivery/build_cookbook/test/fixtures/cookbooks/test/metadata.rb b/cookbooks/postgresql/.delivery/build_cookbook/test/fixtures/cookbooks/test/metadata.rb new file mode 100644 index 0000000..1725039 --- /dev/null +++ b/cookbooks/postgresql/.delivery/build_cookbook/test/fixtures/cookbooks/test/metadata.rb @@ -0,0 +1,2 @@ +name 'test' +version '0.1.0' \ No newline at end of file diff --git a/cookbooks/postgresql/.delivery/build_cookbook/test/fixtures/cookbooks/test/recipes/default.rb b/cookbooks/postgresql/.delivery/build_cookbook/test/fixtures/cookbooks/test/recipes/default.rb new file mode 100644 index 0000000..c26a70a --- /dev/null +++ b/cookbooks/postgresql/.delivery/build_cookbook/test/fixtures/cookbooks/test/recipes/default.rb @@ -0,0 +1,7 @@ +%w(unit lint syntax).each do |phase| + # TODO: This works on Linux/Unix. Not Windows. + execute "HOME=/home/vagrant delivery job verify #{phase} --server localhost --ent test --org kitchen" do + cwd '/tmp/repo-data' + user 'vagrant' + end +end diff --git a/cookbooks/postgresql/.delivery/config.json b/cookbooks/postgresql/.delivery/config.json new file mode 100644 index 0000000..6c0e69f --- /dev/null +++ b/cookbooks/postgresql/.delivery/config.json @@ -0,0 +1,12 @@ +{ + "version": "2", + "build_cookbook": { + "name": "build_cookbook", + "path": ".delivery/build_cookbook" + }, + "skip_phases": [], + "job_dispatch": { + "version": "v2" + }, + "dependencies": [] +} diff --git a/cookbooks/postgresql/.delivery/project.toml b/cookbooks/postgresql/.delivery/project.toml new file mode 100644 index 0000000..c453234 --- /dev/null +++ b/cookbooks/postgresql/.delivery/project.toml @@ -0,0 +1,36 @@ +# Delivery Prototype for Local Phases Execution +# +# The purpose of this file is to prototype a new way to execute +# phases locally on your workstation. The delivery-cli will read +# this file and execute the command(s) that are configured for +# each phase. You can customize them by just modifying the phase +# key on this file. +# +# By default these phases are configured for Cookbook Workflow only +# +# As this is still a prototype we are not modifying the current +# config.json file and it will continue working as usual. + +[local_phases] +unit = "chef exec rspec spec/" +lint = "chef exec cookstyle" +# Foodcritic includes rules only appropriate for community cookbooks +# uploaded to Supermarket. We turn off any rules tagged "supermarket" +# by default. If you plan to share this cookbook you should remove +# '-t ~supermarket' below to enable supermarket rules. +syntax = "chef exec foodcritic . --exclude spec -f any -t ~supermarket" +provision = "chef exec kitchen create" +deploy = "chef exec kitchen converge" +smoke = "chef exec kitchen verify" +# The functional phase is optional, you can define it by uncommenting +# the line below and running the command: `delivery local functional` +# functional = "" +cleanup = "chef exec kitchen destroy" + +# Remote project.toml file +# +# Specify a remote URI location for the `project.toml` file. +# This is useful for teams that wish to centrally manage the behavior +# of the `delivery local` command across many different projects. +# +# remote_file = "https://url/project.toml" diff --git a/cookbooks/postgresql/.gitignore b/cookbooks/postgresql/.gitignore new file mode 100644 index 0000000..febee30 --- /dev/null +++ b/cookbooks/postgresql/.gitignore @@ -0,0 +1,21 @@ +.vagrant +*~ +*# +.#* +\#*# +.*.sw[a-z] +*.un~ + +# Bundler +Gemfile.lock +bin/* +.bundle/* + +# test kitchen +.kitchen/ +.kitchen.local.yml + +# Chef +Berksfile.lock +.zero-knife.rb +Policyfile.lock.json diff --git a/cookbooks/postgresql/.kitchen.yml b/cookbooks/postgresql/.kitchen.yml new file mode 100644 index 0000000..449b272 --- /dev/null +++ b/cookbooks/postgresql/.kitchen.yml @@ -0,0 +1,26 @@ +--- +driver: + name: vagrant + +provisioner: + name: chef_zero + # You may wish to disable always updating cookbooks in CI or other testing environments. + # For example: + # always_update_cookbooks: <%= !ENV['CI'] %> + always_update_cookbooks: true + +verifier: + name: inspec + +platforms: + - name: ubuntu-16.04 + - name: centos-7.2 + +suites: + - name: default + run_list: + - recipe[postgresql::default] + verifier: + inspec_tests: + - test/smoke/default + attributes: diff --git a/cookbooks/postgresql/Berksfile b/cookbooks/postgresql/Berksfile new file mode 100644 index 0000000..34fea21 --- /dev/null +++ b/cookbooks/postgresql/Berksfile @@ -0,0 +1,3 @@ +source 'https://supermarket.chef.io' + +metadata diff --git a/cookbooks/postgresql/README.md b/cookbooks/postgresql/README.md new file mode 100644 index 0000000..45aa548 --- /dev/null +++ b/cookbooks/postgresql/README.md @@ -0,0 +1,4 @@ +# postgresql + +TODO: Enter the cookbook description here. + diff --git a/cookbooks/postgresql/chefignore b/cookbooks/postgresql/chefignore new file mode 100644 index 0000000..38e7379 --- /dev/null +++ b/cookbooks/postgresql/chefignore @@ -0,0 +1,107 @@ +# Put files/directories that should be ignored in this file when uploading +# to a chef-server or supermarket. +# Lines that start with '# ' are comments. + +# OS generated files # +###################### +.DS_Store +Icon? +nohup.out +ehthumbs.db +Thumbs.db + +# SASS # +######## +.sass-cache + +# EDITORS # +########### +\#* +.#* +*~ +*.sw[a-z] +*.bak +REVISION +TAGS* +tmtags +*_flymake.* +*_flymake +*.tmproj +.project +.settings +mkmf.log + +## COMPILED ## +############## +a.out +*.o +*.pyc +*.so +*.com +*.class +*.dll +*.exe +*/rdoc/ + +# Testing # +########### +.watchr +.rspec +spec/* +spec/fixtures/* +test/* +features/* +examples/* +Guardfile +Procfile +.kitchen* +.rubocop.yml +spec/* +Rakefile +.travis.yml +.foodcritic +.codeclimate.yml + +# SCM # +####### +.git +*/.git +.gitignore +.gitmodules +.gitconfig +.gitattributes +.svn +*/.bzr/* +*/.hg/* +*/.svn/* + +# Berkshelf # +############# +Berksfile +Berksfile.lock +cookbooks/* +tmp + +# Policyfile # +############## +Policyfile.rb +Policyfile.lock.json + +# Cookbooks # +############# +CONTRIBUTING* +CHANGELOG* +TESTING* +MAINTAINERS.toml + +# Strainer # +############ +Colanderfile +Strainerfile +.colander +.strainer + +# Vagrant # +########### +.vagrant +Vagrantfile diff --git a/cookbooks/postgresql/metadata.rb b/cookbooks/postgresql/metadata.rb new file mode 100644 index 0000000..f866738 --- /dev/null +++ b/cookbooks/postgresql/metadata.rb @@ -0,0 +1,19 @@ +name 'postgresql' +maintainer 'The Authors' +maintainer_email 'you@example.com' +license 'all_rights' +description 'Installs/Configures postgresql' +long_description 'Installs/Configures postgresql' +version '0.1.0' + +# The `issues_url` points to the location where issues for this cookbook are +# tracked. A `View Issues` link will be displayed on this cookbook's page when +# uploaded to a Supermarket. +# +# issues_url 'https://github.com//postgresql/issues' if respond_to?(:issues_url) + +# The `source_url` points to the development reposiory for this cookbook. A +# `View Source` link will be displayed on this cookbook's page when uploaded to +# a Supermarket. +# +# source_url 'https://github.com//postgresql' if respond_to?(:source_url) diff --git a/cookbooks/postgresql/recipes/default.rb b/cookbooks/postgresql/recipes/default.rb new file mode 100644 index 0000000..6c8f383 --- /dev/null +++ b/cookbooks/postgresql/recipes/default.rb @@ -0,0 +1,20 @@ +# +# Cookbook:: postgresql +# Recipe:: default +# +# Copyright:: 2017, The Authors, All Rights Reserved. +# + +package 'postgresql-server' do + notifies :run, 'execute[init-postgres]' +end + +execute 'init-postgres' do + command 'postgresql-setup initdb' + action :nothing +end + + +service 'postgresql' do + action [:enable, :start] +end diff --git a/cookbooks/postgresql/spec/spec_helper.rb b/cookbooks/postgresql/spec/spec_helper.rb new file mode 100644 index 0000000..1dd5126 --- /dev/null +++ b/cookbooks/postgresql/spec/spec_helper.rb @@ -0,0 +1,2 @@ +require 'chefspec' +require 'chefspec/berkshelf' diff --git a/cookbooks/postgresql/spec/unit/recipes/default_spec.rb b/cookbooks/postgresql/spec/unit/recipes/default_spec.rb new file mode 100644 index 0000000..59a2737 --- /dev/null +++ b/cookbooks/postgresql/spec/unit/recipes/default_spec.rb @@ -0,0 +1,20 @@ +# +# Cookbook:: postgresql +# Spec:: default +# +# Copyright:: 2017, The Authors, All Rights Reserved. + +require 'spec_helper' + +describe 'postgresql::default' do + context 'When all attributes are default, on an unspecified platform' do + let(:chef_run) do + runner = ChefSpec::ServerRunner.new + runner.converge(described_recipe) + end + + it 'converges successfully' do + expect { chef_run }.to_not raise_error + end + end +end diff --git a/cookbooks/postgresql/test/smoke/default/default_test.rb b/cookbooks/postgresql/test/smoke/default/default_test.rb new file mode 100644 index 0000000..178e0b0 --- /dev/null +++ b/cookbooks/postgresql/test/smoke/default/default_test.rb @@ -0,0 +1,18 @@ +# # encoding: utf-8 + +# Inspec test for recipe postgresql::default + +# The Inspec reference, with examples and extensive documentation, can be +# found at http://inspec.io/docs/reference/resources/ + +unless os.windows? + describe user('root') do + it { should exist } + skip 'This is an example test, replace with your own test.' + end +end + +describe port(80) do + it { should_not be_listening } + skip 'This is an example test, replace with your own test.' +end