stuff #1

Merged
wmantly merged 1 commits from setup into master 2019-05-14 17:33:30 +00:00
39 changed files with 727 additions and 0 deletions
Showing only changes of commit 6e69a84284 - Show all commits

5
cookbooks/hosting.json Normal file
View File

@ -0,0 +1,5 @@
{
run_list: [
recipe[first_cookbook:user]
]
}

View File

@ -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'
product_name: chefdk
platforms:
- name: ubuntu-16.04
- name: centos-7
suites:
- name: default
run_list:
- recipe[test]
attributes:

View File

@ -0,0 +1,7 @@
source 'https://supermarket.chef.io'
metadata
group :delivery do
cookbook 'test', path: './test/fixtures/cookbooks/test'
end

View File

@ -0,0 +1,3 @@
Copyright 2019 The Authors
All rights reserved, do not redistribute.

View File

@ -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
<SNIP>
-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 Ubuntu 16.04' do
let(:chef_run) do
runner = ChefSpec::ServerRunner.new(platform: 'ubuntu', version: '16.04')
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 <default-centos-71> (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.

View File

@ -0,0 +1,104 @@
# 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*
kitchen.yml*
.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
# Bundler #
###########
vendor/*
# Policyfile #
##############
Policyfile.rb
Policyfile.lock.json
# Cookbooks #
#############
CONTRIBUTING*
CHANGELOG*
TESTING*
# Vagrant #
###########
.vagrant
Vagrantfile

View File

@ -0,0 +1 @@
{"id": "delivery_builder_keys"}

View File

@ -0,0 +1,8 @@
name 'build_cookbook'
maintainer 'The Authors'
maintainer_email 'you@example.com'
license 'all_rights'
version '0.1.0'
chef_version '>= 13.0'
depends 'delivery-truck'

View File

@ -0,0 +1,6 @@
#
# Cookbook:: build_cookbook
# Recipe:: default
#
# Copyright:: 2019, The Authors, All Rights Reserved.
include_recipe 'delivery-truck::default'

View File

@ -0,0 +1,6 @@
#
# Cookbook:: build_cookbook
# Recipe:: deploy
#
# Copyright:: 2019, The Authors, All Rights Reserved.
include_recipe 'delivery-truck::deploy'

View File

@ -0,0 +1,6 @@
#
# Cookbook:: build_cookbook
# Recipe:: functional
#
# Copyright:: 2019, The Authors, All Rights Reserved.
include_recipe 'delivery-truck::functional'

View File

@ -0,0 +1,6 @@
#
# Cookbook:: build_cookbook
# Recipe:: lint
#
# Copyright:: 2019, The Authors, All Rights Reserved.
include_recipe 'delivery-truck::lint'

View File

@ -0,0 +1,6 @@
#
# Cookbook:: build_cookbook
# Recipe:: provision
#
# Copyright:: 2019, The Authors, All Rights Reserved.
include_recipe 'delivery-truck::provision'

View File

@ -0,0 +1,6 @@
#
# Cookbook:: build_cookbook
# Recipe:: publish
#
# Copyright:: 2019, The Authors, All Rights Reserved.
include_recipe 'delivery-truck::publish'

View File

@ -0,0 +1,6 @@
#
# Cookbook:: build_cookbook
# Recipe:: quality
#
# Copyright:: 2019, The Authors, All Rights Reserved.
include_recipe 'delivery-truck::quality'

View File

@ -0,0 +1,6 @@
#
# Cookbook:: build_cookbook
# Recipe:: security
#
# Copyright:: 2019, The Authors, All Rights Reserved.
include_recipe 'delivery-truck::security'

View File

@ -0,0 +1,6 @@
#
# Cookbook:: build_cookbook
# Recipe:: smoke
#
# Copyright:: 2019, The Authors, All Rights Reserved.
include_recipe 'delivery-truck::smoke'

View File

@ -0,0 +1,6 @@
#
# Cookbook:: build_cookbook
# Recipe:: syntax
#
# Copyright:: 2019, The Authors, All Rights Reserved.
include_recipe 'delivery-truck::syntax'

View File

@ -0,0 +1,6 @@
#
# Cookbook:: build_cookbook
# Recipe:: unit
#
# Copyright:: 2019, The Authors, All Rights Reserved.
include_recipe 'delivery-truck::unit'

View File

@ -0,0 +1,2 @@
name 'test'
version '0.1.0'

View File

@ -0,0 +1,9 @@
# frozen_string_literal: true
%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'
environment('GIT_DISCOVERY_ACROSS_FILESYSTEM' => '1')
end
end

View File

@ -0,0 +1,17 @@
{
"version": "2",
"build_cookbook": {
"name": "build_cookbook",
"path": ".delivery/build_cookbook"
},
"delivery-truck": {
"lint": {
"enable_cookstyle": true
}
},
"skip_phases": [],
"job_dispatch": {
"version": "v2"
},
"dependencies": []
}

View File

@ -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 . -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"

22
cookbooks/hosting/.gitignore vendored Normal file
View File

@ -0,0 +1,22 @@
.vagrant
*~
*#
.#*
\#*#
.*.sw[a-z]
*.un~
# Bundler
Gemfile.lock
gems.locked
bin/*
.bundle/*
# test kitchen
.kitchen/
.kitchen.local.yml
# Chef
Berksfile.lock
.zero-knife.rb
Policyfile.lock.json

View File

@ -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
suites:
- name: default
run_list:
- recipe[hosting::default]
verifier:
inspec_tests:
- test/integration/default
attributes:

View File

@ -0,0 +1,6 @@
# frozen_string_literal: true
source 'https://supermarket.chef.io'
cookbook 'postgresql', '~> 7.1.4'
metadata

View File

@ -0,0 +1,11 @@
# hosting CHANGELOG
This file is used to list changes made in each version of the hosting cookbook.
# 0.1.0
Initial release.
- change 0
- change 1

View File

@ -0,0 +1,3 @@
Copyright 2019 The Authors
All rights reserved, do not redistribute.

View File

@ -0,0 +1,4 @@
# hosting
TODO: Enter the cookbook description here.

View File

@ -0,0 +1,104 @@
# 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*
kitchen.yml*
.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
# Bundler #
###########
vendor/*
# Policyfile #
##############
Policyfile.rb
Policyfile.lock.json
# Cookbooks #
#############
CONTRIBUTING*
CHANGELOG*
TESTING*
# Vagrant #
###########
.vagrant
Vagrantfile

View File

@ -0,0 +1,20 @@
name 'hosting'
maintainer 'The Authors'
maintainer_email 'you@example.com'
license 'All Rights Reserved'
description 'Installs/Configures hosting'
long_description 'Installs/Configures hosting'
version '0.1.0'
chef_version '>= 13.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/<insert_org_here>/hosting/issues'
# The `source_url` points to the development repository 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/<insert_org_here>/hosting'

View File

@ -0,0 +1,5 @@
#
# Cookbook:: hosting
# Recipe:: default
#
# Copyright:: 2019, The Authors, All Rights Reserved.

View File

@ -0,0 +1,20 @@
directory '/opt/theta42' do
owner 'root'
group 'root'
mode '0755'
action :create
end
directory '/opt/theta42/bin' do
owner 'root'
group 'root'
mode '0755'
action :create
end
directory '/opt/theta42/gitea' do
owner 'gitea'
group 'gitea'
mode '0755'
action :create
end

View File

@ -0,0 +1,17 @@
postgresql_server_install 'My PostgreSQL Server install' do
action :install
end
postgresql_access 'local_postgres_superuser' do
comment 'Local postgres superuser access'
access_type 'local'
access_db 'all'
access_user 'postgres'
access_addr nil
access_method 'ident'
end
postgresql_user 'gitea' do
password 'UserP4ssword'
createdb true
end

View File

@ -0,0 +1,10 @@
user 'gitea system user' do
comment 'gitea system user'
username 'gitea'
system true
shell '/bin/false'
end
group 'gitea' do
members 'gitea'
end

View File

@ -0,0 +1,3 @@
# frozen_string_literal: true
require 'chefspec'
require 'chefspec/berkshelf'

View File

@ -0,0 +1,35 @@
#
# Cookbook:: hosting
# Spec:: default
#
# Copyright:: 2019, The Authors, All Rights Reserved.
require 'spec_helper'
describe 'hosting::default' do
context 'When all attributes are default, on Ubuntu 16.04' do
let(:chef_run) do
# for a complete list of available platforms and versions see:
# https://github.com/customink/fauxhai/blob/master/PLATFORMS.md
runner = ChefSpec::ServerRunner.new(platform: 'ubuntu', version: '16.04')
runner.converge(described_recipe)
end
it 'converges successfully' do
expect { chef_run }.to_not raise_error
end
end
context 'When all attributes are default, on CentOS 7.4.1708' do
let(:chef_run) do
# for a complete list of available platforms and versions see:
# https://github.com/customink/fauxhai/blob/master/PLATFORMS.md
runner = ChefSpec::ServerRunner.new(platform: 'centos', version: '7.4.1708')
runner.converge(described_recipe)
end
it 'converges successfully' do
expect { chef_run }.to_not raise_error
end
end
end

View File

@ -0,0 +1,16 @@
# InSpec test for recipe hosting::default
# The InSpec reference, with examples and extensive documentation, can be
# found at http://inspec.io/docs/reference/resources/
unless os.windows?
# This is an example test, replace with your own test.
describe user('root'), :skip do
it { should exist }
end
end
# This is an example test, replace it with your own test.
describe port(80), :skip do
it { should_not be_listening }
end