better directory struct
This commit is contained in:
21
ops/cookbooks/hosting/.delivery/build_cookbook/.kitchen.yml
Normal file
21
ops/cookbooks/hosting/.delivery/build_cookbook/.kitchen.yml
Normal 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:
|
7
ops/cookbooks/hosting/.delivery/build_cookbook/Berksfile
Normal file
7
ops/cookbooks/hosting/.delivery/build_cookbook/Berksfile
Normal file
@ -0,0 +1,7 @@
|
||||
source 'https://supermarket.chef.io'
|
||||
|
||||
metadata
|
||||
|
||||
group :delivery do
|
||||
cookbook 'test', path: './test/fixtures/cookbooks/test'
|
||||
end
|
3
ops/cookbooks/hosting/.delivery/build_cookbook/LICENSE
Normal file
3
ops/cookbooks/hosting/.delivery/build_cookbook/LICENSE
Normal file
@ -0,0 +1,3 @@
|
||||
Copyright 2019 The Authors
|
||||
|
||||
All rights reserved, do not redistribute.
|
146
ops/cookbooks/hosting/.delivery/build_cookbook/README.md
Normal file
146
ops/cookbooks/hosting/.delivery/build_cookbook/README.md
Normal 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.
|
104
ops/cookbooks/hosting/.delivery/build_cookbook/chefignore
Normal file
104
ops/cookbooks/hosting/.delivery/build_cookbook/chefignore
Normal 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
|
@ -0,0 +1 @@
|
||||
{"id": "delivery_builder_keys"}
|
@ -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'
|
@ -0,0 +1,6 @@
|
||||
#
|
||||
# Cookbook:: build_cookbook
|
||||
# Recipe:: default
|
||||
#
|
||||
# Copyright:: 2019, The Authors, All Rights Reserved.
|
||||
include_recipe 'delivery-truck::default'
|
@ -0,0 +1,6 @@
|
||||
#
|
||||
# Cookbook:: build_cookbook
|
||||
# Recipe:: deploy
|
||||
#
|
||||
# Copyright:: 2019, The Authors, All Rights Reserved.
|
||||
include_recipe 'delivery-truck::deploy'
|
@ -0,0 +1,6 @@
|
||||
#
|
||||
# Cookbook:: build_cookbook
|
||||
# Recipe:: functional
|
||||
#
|
||||
# Copyright:: 2019, The Authors, All Rights Reserved.
|
||||
include_recipe 'delivery-truck::functional'
|
@ -0,0 +1,6 @@
|
||||
#
|
||||
# Cookbook:: build_cookbook
|
||||
# Recipe:: lint
|
||||
#
|
||||
# Copyright:: 2019, The Authors, All Rights Reserved.
|
||||
include_recipe 'delivery-truck::lint'
|
@ -0,0 +1,6 @@
|
||||
#
|
||||
# Cookbook:: build_cookbook
|
||||
# Recipe:: provision
|
||||
#
|
||||
# Copyright:: 2019, The Authors, All Rights Reserved.
|
||||
include_recipe 'delivery-truck::provision'
|
@ -0,0 +1,6 @@
|
||||
#
|
||||
# Cookbook:: build_cookbook
|
||||
# Recipe:: publish
|
||||
#
|
||||
# Copyright:: 2019, The Authors, All Rights Reserved.
|
||||
include_recipe 'delivery-truck::publish'
|
@ -0,0 +1,6 @@
|
||||
#
|
||||
# Cookbook:: build_cookbook
|
||||
# Recipe:: quality
|
||||
#
|
||||
# Copyright:: 2019, The Authors, All Rights Reserved.
|
||||
include_recipe 'delivery-truck::quality'
|
@ -0,0 +1,6 @@
|
||||
#
|
||||
# Cookbook:: build_cookbook
|
||||
# Recipe:: security
|
||||
#
|
||||
# Copyright:: 2019, The Authors, All Rights Reserved.
|
||||
include_recipe 'delivery-truck::security'
|
@ -0,0 +1,6 @@
|
||||
#
|
||||
# Cookbook:: build_cookbook
|
||||
# Recipe:: smoke
|
||||
#
|
||||
# Copyright:: 2019, The Authors, All Rights Reserved.
|
||||
include_recipe 'delivery-truck::smoke'
|
@ -0,0 +1,6 @@
|
||||
#
|
||||
# Cookbook:: build_cookbook
|
||||
# Recipe:: syntax
|
||||
#
|
||||
# Copyright:: 2019, The Authors, All Rights Reserved.
|
||||
include_recipe 'delivery-truck::syntax'
|
@ -0,0 +1,6 @@
|
||||
#
|
||||
# Cookbook:: build_cookbook
|
||||
# Recipe:: unit
|
||||
#
|
||||
# Copyright:: 2019, The Authors, All Rights Reserved.
|
||||
include_recipe 'delivery-truck::unit'
|
2
ops/cookbooks/hosting/.delivery/build_cookbook/test/fixtures/cookbooks/test/metadata.rb
vendored
Normal file
2
ops/cookbooks/hosting/.delivery/build_cookbook/test/fixtures/cookbooks/test/metadata.rb
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
name 'test'
|
||||
version '0.1.0'
|
@ -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
|
17
ops/cookbooks/hosting/.delivery/config.json
Normal file
17
ops/cookbooks/hosting/.delivery/config.json
Normal 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": []
|
||||
}
|
36
ops/cookbooks/hosting/.delivery/project.toml
Normal file
36
ops/cookbooks/hosting/.delivery/project.toml
Normal 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
ops/cookbooks/hosting/.gitignore
vendored
Normal file
22
ops/cookbooks/hosting/.gitignore
vendored
Normal 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
|
26
ops/cookbooks/hosting/.kitchen.yml
Normal file
26
ops/cookbooks/hosting/.kitchen.yml
Normal 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:
|
6
ops/cookbooks/hosting/Berksfile
Normal file
6
ops/cookbooks/hosting/Berksfile
Normal file
@ -0,0 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
source 'https://supermarket.chef.io'
|
||||
|
||||
cookbook 'postgresql', '~> 7.1.4'
|
||||
|
||||
metadata
|
11
ops/cookbooks/hosting/CHANGELOG.md
Normal file
11
ops/cookbooks/hosting/CHANGELOG.md
Normal 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
|
||||
|
3
ops/cookbooks/hosting/LICENSE
Normal file
3
ops/cookbooks/hosting/LICENSE
Normal file
@ -0,0 +1,3 @@
|
||||
Copyright 2019 The Authors
|
||||
|
||||
All rights reserved, do not redistribute.
|
4
ops/cookbooks/hosting/README.md
Normal file
4
ops/cookbooks/hosting/README.md
Normal file
@ -0,0 +1,4 @@
|
||||
# hosting
|
||||
|
||||
TODO: Enter the cookbook description here.
|
||||
|
104
ops/cookbooks/hosting/chefignore
Normal file
104
ops/cookbooks/hosting/chefignore
Normal 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
|
22
ops/cookbooks/hosting/metadata.rb
Normal file
22
ops/cookbooks/hosting/metadata.rb
Normal file
@ -0,0 +1,22 @@
|
||||
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'
|
||||
|
||||
depends 'postgresql'
|
||||
|
||||
# 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'
|
5
ops/cookbooks/hosting/recipes/default.rb
Normal file
5
ops/cookbooks/hosting/recipes/default.rb
Normal file
@ -0,0 +1,5 @@
|
||||
#
|
||||
# Cookbook:: hosting
|
||||
# Recipe:: default
|
||||
#
|
||||
# Copyright:: 2019, The Authors, All Rights Reserved.
|
46
ops/cookbooks/hosting/recipes/gitea.rb
Normal file
46
ops/cookbooks/hosting/recipes/gitea.rb
Normal file
@ -0,0 +1,46 @@
|
||||
remote_file '/opt/theta42/bin/gitea' do
|
||||
source 'https://github.com/go-gitea/gitea/releases/download/v1.8.1/gitea-1.8.1-linux-amd64'
|
||||
mode '0755'
|
||||
action :create
|
||||
end
|
||||
|
||||
template '/opt/theta42/gitea/conf/app.ini' do
|
||||
source 'app.ini.erb'
|
||||
owner 'gitea'
|
||||
group 'gitea'
|
||||
mode '0755'
|
||||
end
|
||||
|
||||
systemd_unit 'gitea.service' do
|
||||
content <<-EOU.gsub(/^\s+/, '')
|
||||
[Unit]
|
||||
Description=Gitea (Git with a cup of tea)
|
||||
After=syslog.target
|
||||
After=network.target
|
||||
After=postgresql.service
|
||||
|
||||
|
||||
[Service]
|
||||
# Modify these two values and uncomment them if you have
|
||||
# repos with lots of files and get an HTTP error 500 because
|
||||
# of that
|
||||
###
|
||||
#LimitMEMLOCK=infinity
|
||||
#LimitNOFILE=65535
|
||||
RestartSec=10s
|
||||
Type=simple
|
||||
User=gitea
|
||||
Group=gitea
|
||||
WorkingDirectory=/opt/theta42/gitea
|
||||
ExecStart=/opt/theta42/bin/gitea web --config /opt/theta42/gitea/conf/app.ini
|
||||
Restart=always
|
||||
Environment=USER=gitea HOME=/home/gitea GITEA_WORK_DIR=/opt/theta42/gitea GITEA_CUSTOM=/opt/theta42/gitea/custom
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
||||
|
||||
EOU
|
||||
|
||||
action [:create, :enable, :start]
|
||||
end
|
48
ops/cookbooks/hosting/recipes/mkdir.rb
Normal file
48
ops/cookbooks/hosting/recipes/mkdir.rb
Normal file
@ -0,0 +1,48 @@
|
||||
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 '/home/gitea' do
|
||||
owner 'gitea'
|
||||
group 'gitea'
|
||||
mode '0755'
|
||||
action :create
|
||||
end
|
||||
|
||||
directory '/opt/theta42/gitea' do
|
||||
owner 'gitea'
|
||||
group 'gitea'
|
||||
mode '0755'
|
||||
action :create
|
||||
end
|
||||
|
||||
directory '/opt/theta42/gitea/conf' do
|
||||
owner 'gitea'
|
||||
group 'gitea'
|
||||
mode '0755'
|
||||
action :create
|
||||
end
|
||||
|
||||
directory '/opt/theta42/gitea/data' do
|
||||
owner 'gitea'
|
||||
group 'gitea'
|
||||
mode '0755'
|
||||
action :create
|
||||
end
|
||||
|
||||
directory '/opt/theta42/gitea/custom' do
|
||||
owner 'gitea'
|
||||
group 'gitea'
|
||||
mode '0755'
|
||||
action :create
|
||||
end
|
62
ops/cookbooks/hosting/recipes/nginx.rb
Normal file
62
ops/cookbooks/hosting/recipes/nginx.rb
Normal file
@ -0,0 +1,62 @@
|
||||
# apt_repository 'open resty repo' do
|
||||
# uri 'http://openresty.org/package/ubuntu'
|
||||
# key 'https://openresty.org/package/pubkey.gpg'
|
||||
# components ['main']
|
||||
# end
|
||||
|
||||
apt_package 'software-properties-common'
|
||||
|
||||
execute 'add key' do
|
||||
command 'wget -qO - https://openresty.org/package/pubkey.gpg | sudo apt-key add -'
|
||||
end
|
||||
|
||||
execute 'add repo' do
|
||||
command 'add-apt-repository -y "deb http://openresty.org/package/ubuntu $(lsb_release -sc) main"; apt update'
|
||||
end
|
||||
|
||||
apt_package 'openresty'
|
||||
|
||||
apt_package 'luarocks'
|
||||
|
||||
execute 'install lua-resty-auto-ssl' do
|
||||
command 'luarocks install lua-resty-auto-ssl'
|
||||
end
|
||||
|
||||
directory '/etc/ssl' do
|
||||
mode '0755'
|
||||
action :create
|
||||
end
|
||||
|
||||
execute 'defualt ssl' do
|
||||
command "openssl req -new -newkey rsa:2048 -days 3650 -nodes -x509 -subj '/CN=sni-support-required-for-valid-ssl' -keyout /etc/ssl/resty-auto-ssl-fallback.key -out /etc/ssl/resty-auto-ssl-fallback.crt"
|
||||
end
|
||||
|
||||
execute 'defualt ssl' do
|
||||
command "openssl req -new -newkey rsa:2048 -days 3650 -nodes -x509 -subj '/CN=sni-support-required-for-valid-ssl' -keyout /etc/ssl/resty-auto-ssl-fallback.key -out /etc/ssl/resty-auto-ssl-fallback.crt"
|
||||
end
|
||||
|
||||
template '/etc/openresty/nginx.conf' do
|
||||
source 'nginx.conf.erb'
|
||||
end
|
||||
|
||||
template '/etc/openresty/autossl.conf' do
|
||||
source 'autossl.conf.erb'
|
||||
end
|
||||
|
||||
directory '/etc/openresty/sites-enabled' do
|
||||
mode '0755'
|
||||
action :create
|
||||
end
|
||||
|
||||
directory '/var/log/nginx/' do
|
||||
mode '0775'
|
||||
action :create
|
||||
end
|
||||
|
||||
template '/etc/openresty/sites-enabled/host.conf' do
|
||||
source 'host.conf.erb'
|
||||
end
|
||||
|
||||
systemd_unit 'openresty' do
|
||||
action :reload
|
||||
end
|
53
ops/cookbooks/hosting/recipes/postgress.rb
Normal file
53
ops/cookbooks/hosting/recipes/postgress.rb
Normal file
@ -0,0 +1,53 @@
|
||||
postgresql_server_install 'My PostgreSQL Server install' do
|
||||
initdb_locale 'en_US.utf8'
|
||||
action :install
|
||||
end
|
||||
|
||||
postgresql_server_install 'Setup my PostgreSQL 9.6 server' do
|
||||
initdb_locale 'en_US.utf8'
|
||||
action :create
|
||||
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 node['db-password']
|
||||
# createrole true
|
||||
end
|
||||
|
||||
# Hack for creating a database, this cook book is broken with debian...
|
||||
|
||||
execute 'add database' do
|
||||
command 'createdb gitea'
|
||||
user 'postgres'
|
||||
not_if 'psql -lqt | cut -d \| -f 1 | grep -qw gitea', :user => 'postgres'
|
||||
end
|
||||
|
||||
execute 'Grant gitea user' do
|
||||
command 'echo "grant all privileges on database gitea to gitea ;" | psql'
|
||||
user 'postgres'
|
||||
end
|
||||
|
||||
template '/home/gitea/dump.sql' do
|
||||
source 'gitea_postgres.sql.erb'
|
||||
owner 'gitea'
|
||||
group 'gitea'
|
||||
mode '0755'
|
||||
end
|
||||
|
||||
execute 'base DB' do
|
||||
command 'psql gitea < /home/gitea/dump.sql'
|
||||
user 'postgres'
|
||||
end
|
||||
|
||||
# postgresql_database 'gitea' do
|
||||
# locale 'en_US.utf8'
|
||||
# owner 'gitea'
|
||||
# end
|
10
ops/cookbooks/hosting/recipes/user.rb
Normal file
10
ops/cookbooks/hosting/recipes/user.rb
Normal file
@ -0,0 +1,10 @@
|
||||
user 'gitea system user' do
|
||||
comment 'gitea system user'
|
||||
username 'gitea'
|
||||
home '/home/gitea'
|
||||
shell '/bin/bash'
|
||||
end
|
||||
|
||||
group 'gitea' do
|
||||
members 'gitea'
|
||||
end
|
3
ops/cookbooks/hosting/spec/spec_helper.rb
Normal file
3
ops/cookbooks/hosting/spec/spec_helper.rb
Normal file
@ -0,0 +1,3 @@
|
||||
# frozen_string_literal: true
|
||||
require 'chefspec'
|
||||
require 'chefspec/berkshelf'
|
35
ops/cookbooks/hosting/spec/unit/recipes/default_spec.rb
Normal file
35
ops/cookbooks/hosting/spec/unit/recipes/default_spec.rb
Normal 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
|
67
ops/cookbooks/hosting/templates/app.ini.erb
Normal file
67
ops/cookbooks/hosting/templates/app.ini.erb
Normal file
@ -0,0 +1,67 @@
|
||||
APP_NAME = <%= node['custom-title'] %>
|
||||
RUN_USER = gitea
|
||||
RUN_MODE = prod
|
||||
|
||||
[oauth2]
|
||||
JWT_SECRET = QywECk5l8_8GDE7wMZpAJHOAO74eIpg1ny_-zm3AKSY
|
||||
|
||||
[security]
|
||||
INTERNAL_TOKEN = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE1NTc4ODAwNjJ9.k3PPY_Dh0s04j8aQOx7R8N56bqLEGmBKOF3SnsHTtBw
|
||||
INSTALL_LOCK = true
|
||||
SECRET_KEY = x95ZGsKkk3PEQxsyGiIERM1DRX4vMosnTVqOwULjbpK70X4pSQ7keBMU1QPr5ExH
|
||||
|
||||
[database]
|
||||
DB_TYPE = postgres
|
||||
HOST = 127.0.0.1:5432
|
||||
NAME = gitea
|
||||
USER = gitea
|
||||
PASSWD = <%= node['db-password'] %>
|
||||
SSL_MODE = disable
|
||||
PATH = /opt/theta42/data/gitea.db
|
||||
|
||||
[repository]
|
||||
ROOT = /root/gitea-repositories
|
||||
|
||||
[server]
|
||||
SSH_DOMAIN = <%= node['custom-domain'] %>
|
||||
DOMAIN = <%= node['custom-domain'] %>
|
||||
HTTP_PORT = 3000
|
||||
ROOT_URL = http://<%= node['custom-domain'] %>/
|
||||
DISABLE_SSH = false
|
||||
SSH_PORT = 22
|
||||
LFS_START_SERVER = true
|
||||
LFS_CONTENT_PATH = /opt/theta42/gitea/data/lfs
|
||||
LFS_JWT_SECRET = tvg4SFUSNduclix3Lye9_UD1IYaX46lUDUpenQovSbY
|
||||
OFFLINE_MODE = false
|
||||
|
||||
[mailer]
|
||||
ENABLED = false
|
||||
|
||||
[service]
|
||||
REGISTER_EMAIL_CONFIRM = false
|
||||
ENABLE_NOTIFY_MAIL = false
|
||||
DISABLE_REGISTRATION = false
|
||||
ALLOW_ONLY_EXTERNAL_REGISTRATION = false
|
||||
ENABLE_CAPTCHA = false
|
||||
REQUIRE_SIGNIN_VIEW = false
|
||||
DEFAULT_KEEP_EMAIL_PRIVATE = false
|
||||
DEFAULT_ALLOW_CREATE_ORGANIZATION = true
|
||||
DEFAULT_ENABLE_TIMETRACKING = true
|
||||
NO_REPLY_ADDRESS = noreply.example.org
|
||||
|
||||
[picture]
|
||||
DISABLE_GRAVATAR = false
|
||||
ENABLE_FEDERATED_AVATAR = true
|
||||
|
||||
[openid]
|
||||
ENABLE_OPENID_SIGNIN = true
|
||||
ENABLE_OPENID_SIGNUP = true
|
||||
|
||||
[session]
|
||||
PROVIDER = file
|
||||
|
||||
[log]
|
||||
MODE = file
|
||||
LEVEL = Info
|
||||
ROOT_PATH = /opt/theta42/gitea/log
|
||||
|
16
ops/cookbooks/hosting/templates/autossl.conf.erb
Normal file
16
ops/cookbooks/hosting/templates/autossl.conf.erb
Normal file
@ -0,0 +1,16 @@
|
||||
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
|
||||
ssl_prefer_server_ciphers on;
|
||||
ssl_ciphers EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
|
||||
|
||||
ssl_certificate_by_lua_block {
|
||||
auto_ssl:ssl_certificate()
|
||||
}
|
||||
|
||||
location /.well-known/acme-challenge/ {
|
||||
content_by_lua_block {
|
||||
auto_ssl:challenge_server()
|
||||
}
|
||||
}
|
||||
|
||||
ssl_certificate /etc/ssl/resty-auto-ssl-fallback.crt;
|
||||
ssl_certificate_key /etc/ssl/resty-auto-ssl-fallback.key;
|
5281
ops/cookbooks/hosting/templates/gitea_postgres.sql.erb
Normal file
5281
ops/cookbooks/hosting/templates/gitea_postgres.sql.erb
Normal file
File diff suppressed because it is too large
Load Diff
24
ops/cookbooks/hosting/templates/host.conf.erb
Normal file
24
ops/cookbooks/hosting/templates/host.conf.erb
Normal file
@ -0,0 +1,24 @@
|
||||
server {
|
||||
listen 80;
|
||||
listen 443 ssl;
|
||||
server_name <%= node['custom-domain'];
|
||||
|
||||
include autossl.conf;
|
||||
|
||||
proxy_set_header X-Forwarded-For $remote_addr;
|
||||
|
||||
location / {
|
||||
proxy_pass http://localhost:3000;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Host $server_name;
|
||||
proxy_read_timeout 1200s;
|
||||
|
||||
# used for view/edit office file via Office Online Server
|
||||
client_max_body_size 0;
|
||||
|
||||
access_log /var/log/nginx/gitea.access.log;
|
||||
error_log /var/log/nginx/gitea.error.log;
|
||||
}
|
||||
}
|
75
ops/cookbooks/hosting/templates/nginx.conf.erb
Normal file
75
ops/cookbooks/hosting/templates/nginx.conf.erb
Normal file
@ -0,0 +1,75 @@
|
||||
#user nobody;
|
||||
worker_processes 4;
|
||||
|
||||
#error_log logs/error.log;
|
||||
#error_log logs/error.log notice;
|
||||
#error_log logs/error.log info;
|
||||
|
||||
#pid logs/nginx.pid;
|
||||
|
||||
|
||||
events {
|
||||
worker_connections 1024;
|
||||
}
|
||||
|
||||
|
||||
http {
|
||||
client_max_body_size 4g;
|
||||
|
||||
|
||||
lua_shared_dict auto_ssl 100m;
|
||||
lua_shared_dict auto_ssl_settings 64k;
|
||||
|
||||
resolver 8.8.4.4 8.8.8.8;
|
||||
|
||||
init_by_lua_block {
|
||||
auto_ssl = (require "resty.auto-ssl").new()
|
||||
auto_ssl:set("storage_adapter", "resty.auto-ssl.storage_adapters.redis")
|
||||
auto_ssl:set("allow_domain", function(domain)
|
||||
return true
|
||||
end)
|
||||
auto_ssl:init()
|
||||
}
|
||||
|
||||
init_worker_by_lua_block {
|
||||
auto_ssl:init_worker()
|
||||
}
|
||||
|
||||
ssl_session_cache shared:SSL:10m;
|
||||
ssl_session_timeout 10m;
|
||||
|
||||
server {
|
||||
listen 127.0.0.1:8999;
|
||||
|
||||
# Increase the body buffer size, to ensure the internal POSTs can always
|
||||
# parse the full POST contents into memory.
|
||||
client_body_buffer_size 128k;
|
||||
client_max_body_size 128k;
|
||||
|
||||
location / {
|
||||
content_by_lua_block {
|
||||
auto_ssl:hook_server()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
include mime.types;
|
||||
default_type application/octet-stream;
|
||||
|
||||
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
||||
# '$status $body_bytes_sent "$http_referer" '
|
||||
# '"$http_user_agent" "$http_x_forwarded_for"';
|
||||
|
||||
access_log /var/log/nginx/access.log;
|
||||
error_log /var/log/nginx/error.log;
|
||||
|
||||
sendfile on;
|
||||
#tcp_nopush on;
|
||||
|
||||
#keepalive_timeout 0;
|
||||
keepalive_timeout 65;
|
||||
|
||||
#gzip on;
|
||||
include sites-enabled/*;
|
||||
|
||||
}
|
@ -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
|
Reference in New Issue
Block a user