Set up an instance of Mastodon for Kosmos

Refs #19

Use new application cookbook, update our cookbooks
This commit is contained in:
Greg 2017-04-06 21:20:51 +02:00
parent a3f5c5f646
commit de11c0d691
345 changed files with 22591 additions and 3473 deletions

2
.gitignore vendored
View File

@ -1,2 +1,4 @@
/.chef/encrypted_data_bag_secret
/.bundle/
/.vagrant/
/nodes/vagrant-node.json

9
Batali
View File

@ -14,10 +14,10 @@ Batali.define do
ref: 'relax_dependencies'
cookbook 'postfix'
cookbook 'unattended-upgrades'
cookbook 'application_nodejs',
git: 'https://github.com/67p/application_nodejs.git',
ref: 'master'
cookbook 'application', '4.1.6'
cookbook 'application'
cookbook 'application_javascript'
cookbook 'application_ruby'
cookbook 'application_git'
cookbook 'users'
cookbook 'sudo'
cookbook 'hostname'
@ -29,6 +29,7 @@ Batali.define do
cookbook 'nginx'
cookbook 'build-essential'
cookbook 'mysql'
cookbook 'postgresql', '~> 6.1'
cookbook 'database'
cookbook 'mysql2_chef_gem'
cookbook 'omnibus_updater'

95
Vagrantfile vendored Normal file
View File

@ -0,0 +1,95 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure(2) do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
# https://docs.vagrantup.com.
# Every Vagrant development environment requires a box. You can search for
# boxes at https://atlas.hashicorp.com/search.
config.vm.box = "bento/ubuntu-15.04"
config.vm.provider "virtualbox" do |vb|
# Customize the amount of memory on the VM:
vb.memory = "1024"
end
# Disable automatic box update checking. If you disable this, then
# boxes will only be checked for updates when the user runs
# `vagrant box outdated`. This is not recommended.
# config.vm.box_check_update = false
# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing "localhost:8080" will access port 80 on the guest machine.
# config.vm.network "forwarded_port", guest: 80, host: 8080
# Create a private network, which allows host-only access to the machine
# using a specific IP.
# config.vm.network "private_network", ip: "192.168.33.10"
# Create a public network, which generally matched to bridged network.
# Bridged networks make the machine appear as another physical device on
# your network.
# config.vm.network "public_network"
# Share an additional folder to the guest VM. The first argument is
# the path on the host to the actual folder. The second argument is
# the path on the guest to mount the folder. And the optional third
# argument is a set of non-required options.
# config.vm.synced_folder "../data", "/vagrant_data"
# Provider-specific configuration so you can fine-tune various
# backing providers for Vagrant. These expose provider-specific options.
# Example for VirtualBox:
#
# config.vm.provider "virtualbox" do |vb|
# # Display the VirtualBox GUI when booting the machine
# vb.gui = true
#
# # Customize the amount of memory on the VM:
# vb.memory = "1024"
# end
#
# View the documentation for the provider you are using for more
# information on available options.
# Define a Vagrant Push strategy for pushing to Atlas. Other push strategies
# such as FTP and Heroku are also available. See the documentation at
# https://docs.vagrantup.com/v2/push/atlas.html for more information.
# config.push.define "atlas" do |push|
# push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME"
# end
# Enable provisioning with a shell script. Additional provisioners such as
# Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
# documentation for more information about their specific syntax and use.
# config.vm.provision "shell", inline: <<-SHELL
# sudo apt-get update
# sudo apt-get install -y apache2
# SHELL
config.vm.provision :chef_zero do |chef|
chef.cookbooks_path = ['./cookbooks', './site-cookbooks']
chef.data_bags_path = './data_bags'
chef.roles_path = './roles'
chef.node_name = "vagrant-node"
chef.nodes_path = './nodes'
chef.environments_path = './environments'
chef.encrypted_data_bag_secret_key_path = '.chef/encrypted_data_bag_secret'
chef.environment = 'development'
# chef.add_recipe 'kosmos-wordpress'
# chef.add_recipe 'sockethub'
chef.add_recipe 'kosmos-mastodon'
# chef.add_recipe 'kosmos-mastodon::nginx'
# chef.add_recipe '5apps-hubot::xmpp_botka'
# chef.add_recipe 'kosmos-hubot'
end
end

View File

@ -36,7 +36,7 @@
"version": "0.2.0",
"source": {
"url": "https://github.com/67P/mediawiki-cookbook.git",
"ref": "b76104ab975ed95e238c10ae49722f0dacd7c0b2",
"ref": "41d3c5129b5a6cd9c473e99339885bc1feac5d57",
"type": "Batali::Source::Git",
"subdirectory": null
}
@ -325,29 +325,6 @@
"version": "4.0.9"
}
},
{
"name": "postgresql",
"dependencies": [
[
"apt",
">= 1.9.0"
],
[
"build-essential",
">= 0.0.0"
],
[
"openssl",
"~> 4.0"
]
],
"version": "4.0.0",
"source": {
"type": "Batali::Source::Site",
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/postgresql/versions/4.0.0/download",
"version": "4.0.0"
}
},
{
"name": "apt",
"dependencies": [
@ -612,7 +589,7 @@
],
[
"mysql2_chef_gem",
"~> 1.0.1"
">= 1.0.1"
],
[
"build-essential",
@ -642,7 +619,7 @@
"version": "3.0.0",
"source": {
"url": "https://github.com/67P/wordpress-cookbook.git",
"ref": "bc6a108fcfb05c3fafd903bcf81ac33617e6cef9",
"ref": "d6401db517476e6f3ab36aa92dfc0f5ed6a8a264",
"type": "Batali::Source::Git",
"subdirectory": null
}
@ -698,105 +675,234 @@
"version": "0.1.2"
}
},
{
"name": "application_nodejs",
"dependencies": [
[
"nodejs",
"> 0"
],
[
"application",
"> 0"
]
],
"version": "2.0.1",
"source": {
"url": "https://github.com/67p/application_nodejs.git",
"ref": "0c3494b0cae87bd1e9cbf360e91f1a290b517a66",
"type": "Batali::Source::Git",
"subdirectory": null
}
},
{
"name": "nodejs",
"dependencies": [
[
"yum-epel",
">= 0.0.0"
],
[
"build-essential",
">= 0.0.0"
],
[
"ark",
">= 0.0.0"
],
[
"apt",
">= 2.9.1"
],
[
"homebrew",
">= 0.0.0"
]
],
"version": "3.0.0",
"source": {
"type": "Batali::Source::Site",
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/nodejs/versions/3.0.0/download",
"version": "3.0.0"
}
},
{
"name": "ark",
"dependencies": [
[
"build-essential",
">= 0.0.0"
],
[
"windows",
">= 0.0.0"
],
[
"seven_zip",
">= 0.0.0"
]
],
"version": "2.2.1",
"source": {
"type": "Batali::Source::Site",
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/ark/versions/2.2.1/download",
"version": "2.2.1"
}
},
{
"name": "homebrew",
"dependencies": [
[
"build-essential",
">= 2.1.2"
]
],
"version": "2.0.5",
"source": {
"type": "Batali::Source::Site",
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/homebrew/versions/2.0.5/download",
"version": "2.0.5"
}
},
{
"name": "application",
"dependencies": [
[
"poise",
"~> 2.4"
],
[
"poise-service",
"~> 1.0"
]
],
"version": "5.1.0",
"source": {
"type": "Batali::Source::Site",
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/application/versions/5.1.0/download",
"version": "5.1.0"
}
},
{
"name": "poise",
"dependencies": [
],
"version": "4.1.6",
"version": "2.7.2",
"source": {
"type": "Batali::Source::Site",
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/application/versions/4.1.6/download",
"version": "4.1.6"
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/poise/versions/2.7.2/download",
"version": "2.7.2"
}
},
{
"name": "poise-service",
"dependencies": [
[
"poise",
"~> 2.0"
]
],
"version": "1.4.2",
"source": {
"type": "Batali::Source::Site",
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/poise-service/versions/1.4.2/download",
"version": "1.4.2"
}
},
{
"name": "application_javascript",
"dependencies": [
[
"poise",
"~> 2.0"
],
[
"application",
"~> 5.0"
],
[
"poise-javascript",
"~> 1.0"
],
[
"poise-service",
"~> 1.0"
]
],
"version": "1.0.0",
"source": {
"type": "Batali::Source::Site",
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/application_javascript/versions/1.0.0/download",
"version": "1.0.0"
}
},
{
"name": "poise-javascript",
"dependencies": [
[
"poise",
"~> 2.0"
],
[
"poise-languages",
"~> 2.0"
]
],
"version": "1.1.0",
"source": {
"type": "Batali::Source::Site",
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/poise-javascript/versions/1.1.0/download",
"version": "1.1.0"
}
},
{
"name": "poise-languages",
"dependencies": [
[
"poise",
"~> 2.5"
],
[
"poise-archive",
"~> 1.0"
]
],
"version": "2.1.0",
"source": {
"type": "Batali::Source::Site",
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/poise-languages/versions/2.1.0/download",
"version": "2.1.0"
}
},
{
"name": "poise-archive",
"dependencies": [
[
"poise",
"~> 2.6"
]
],
"version": "1.4.0",
"source": {
"type": "Batali::Source::Site",
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/poise-archive/versions/1.4.0/download",
"version": "1.4.0"
}
},
{
"name": "application_ruby",
"dependencies": [
[
"poise-service",
"~> 1.0"
],
[
"poise",
"~> 2.0"
],
[
"application",
"~> 5.0"
],
[
"poise-ruby",
"~> 2.1"
]
],
"version": "4.0.1",
"source": {
"type": "Batali::Source::Site",
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/application_ruby/versions/4.0.1/download",
"version": "4.0.1"
}
},
{
"name": "poise-ruby",
"dependencies": [
[
"poise",
"~> 2.0"
],
[
"poise-languages",
"~> 2.0"
]
],
"version": "2.2.0",
"source": {
"type": "Batali::Source::Site",
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/poise-ruby/versions/2.2.0/download",
"version": "2.2.0"
}
},
{
"name": "application_git",
"dependencies": [
[
"git",
">= 0.0.0"
],
[
"poise",
"~> 2.0"
],
[
"application",
"~> 5.0"
]
],
"version": "1.1.0",
"source": {
"type": "Batali::Source::Site",
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/application_git/versions/1.1.0/download",
"version": "1.1.0"
}
},
{
"name": "git",
"dependencies": [
[
"build-essential",
">= 0.0.0"
],
[
"dmg",
">= 0.0.0"
],
[
"yum-epel",
">= 0.0.0"
]
],
"version": "6.0.0",
"source": {
"type": "Batali::Source::Site",
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/git/versions/6.0.0/download",
"version": "6.0.0"
}
},
{
"name": "dmg",
"dependencies": [
],
"version": "3.1.0",
"source": {
"type": "Batali::Source::Site",
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/dmg/versions/3.1.0/download",
"version": "3.1.0"
}
},
{
@ -896,6 +1002,29 @@
"version": "2.5.4"
}
},
{
"name": "postgresql",
"dependencies": [
[
"compat_resource",
">= 12.16.3"
],
[
"build-essential",
">= 2.0.0"
],
[
"openssl",
">= 4.0"
]
],
"version": "6.1.1",
"source": {
"type": "Batali::Source::Site",
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/postgresql/versions/6.1.1/download",
"version": "6.1.1"
}
},
{
"name": "omnibus_updater",
"dependencies": [
@ -920,6 +1049,75 @@
"version": "0.2.0"
}
},
{
"name": "nodejs",
"dependencies": [
[
"yum-epel",
">= 0.0.0"
],
[
"build-essential",
">= 0.0.0"
],
[
"ark",
">= 0.0.0"
],
[
"apt",
">= 2.9.1"
],
[
"homebrew",
">= 0.0.0"
]
],
"version": "3.0.0",
"source": {
"type": "Batali::Source::Site",
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/nodejs/versions/3.0.0/download",
"version": "3.0.0"
}
},
{
"name": "ark",
"dependencies": [
[
"build-essential",
">= 0.0.0"
],
[
"windows",
">= 0.0.0"
],
[
"seven_zip",
">= 0.0.0"
]
],
"version": "2.2.1",
"source": {
"type": "Batali::Source::Site",
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/ark/versions/2.2.1/download",
"version": "2.2.1"
}
},
{
"name": "homebrew",
"dependencies": [
[
"build-essential",
">= 2.1.2"
]
],
"version": "2.0.5",
"source": {
"type": "Batali::Source::Site",
"url": "https://supermarket.chef.io:443/api/v1/cookbooks/homebrew/versions/2.0.5/download",
"version": "2.0.5"
}
},
{
"name": "logrotate",
"dependencies": [

View File

@ -1,103 +1,96 @@
application Cookbook CHANGELOG
=======================
This file is used to list changes made in each version of the application cookbook.
# Application Changelog
## v5.1.0
v4.1.6
------
- Support for Chef 12.
- Add `strict_ssh` option to enable host key checking.
- Add `keep_releases` option to control number of releases to keep.
- Allow passing a path to a file for `deploy_key`.
* Add `application_cookbook_file`, `application_file`, and `application_template resources.
v4.1.4
------
### Bug
- **[COOK-3343](https://tickets.opscode.com/browse/COOK-3343)** - Can't parse release candidate version number
## v5.0.0
* Massive rewrite on top of newer Chef patterns. See the 5.0 README for details.
v4.1.2
------
### Bug
- **[COOK-3343](https://tickets.opscode.com/browse/COOK-3343)** - Can't parse release candidate version number
## v4.1.6
* Support for Chef 12.
* Add `strict_ssh` option to enable host key checking.
* Add `keep_releases` option to control number of releases to keep.
* Allow passing a path to a file for `deploy_key`.
v4.1.0
------
### Bug
- [COOK-3343] - Can't parse release candidate version number
## v4.1.4
* [COOK-3343](https://tickets.opscode.com/browse/COOK-3343) - Can't parse release candidate version number.
v4.0.0
------
### Breaking
- Removes compatability with Chef 10
## v4.1.2
* [COOK-3343](https://tickets.opscode.com/browse/COOK-3343) - Can't parse release candidate version number.
## v4.1.0
* [COOK-3343] - Can't parse release candidate version number.
## v4.0.0
* Removes compatability with Chef 10.
* [COOK-3564](https://tickets.opscode.com/browse/COOK-3564) - Replace calls to `Chef::Mixin::RecipeDefinitionDSLCore`.
## v3.0.0
* [COOK-3306]: Multiple Memory Leaks in Application Cookbook.
## v2.0.4
* [COOK-2812]: application cookbook doesn't allow to specify a block as `restart_command`.
## v2.0.2
* [COOK-2537]: Provide proper `respond_to` behavior when using `method_missing`.
* [COOK-2713]: application resource should Allow sub-resource attributes to propogate up.
### Improvement
- **[COOK-3564](https://tickets.opscode.com/browse/COOK-3564)** - Replace calls to `Chef::Mixin::RecipeDefinitionDSLCore`
* [COOK-2597]: Allow customization for `shallow_clone` when doing a git deploy.
v3.0.0
------
### Bug
- [COOK-3306]: Multiple Memory Leaks in Application Cookbook
## v2.0.0
v2.0.4
------
### Bug
- [COOK-2812]: application cookbook doesn't allow to specify a block as `restart_command`
v2.0.2
------
### Bug
- [COOK-2537]: Provide proper `respond_to` behavior when using `method_missing`
- [COOK-2713]: application resource should Allow sub-resource attributes to propogate up
### Improvement
- [COOK-2597]: Allow customization for `shallow_clone` when doing a git deploy
v2.0.0
------
This release is incompatible with previous releases (hence major version change). The recipes used in older versions are deprecated and completely removed. See README.md for further detail.
- [COOK-1673] - `deploy_revision` in the application cookbook gives an argument error
- [COOK-1820] - Application cookbook: remove deprecated recipes
* [COOK-1673] - `deploy_revision` in the application cookbook gives an argument error.
* [COOK-1820] - Application cookbook: remove deprecated recipes.
v1.0.4
------
- [COOK-1567] - Add git submodules to application cookbook
## v1.0.4
v1.0.2
------
- [COOK-1312] - string callbacks fail with method not found (really included this time)
- [COOK-1332] - add `release_path` and `shared_path` methods
- [COOK-1333] - add example for running migrations
- [COOK-1360] - fix minor typos in README
- [COOK-1374] - use runit attributes in unicorn run script
* [COOK-1567] - Add git submodules to application cookbook.
## v1.0.2
* [COOK-1312] - string callbacks fail with method not found (really included this time).
* [COOK-1332] - add `release_path` and `shared_path` methods.
* [COOK-1333] - add example for running migrations.
* [COOK-1360] - fix minor typos in README.
* [COOK-1374] - use runit attributes in unicorn run script.
## v1.0.0
v1.0.0
------
This release introduces the LWRP for application deployment, as well as other improvements. The recipes will be deprecated in August 2012 as indicated by their warning messages and in the README.md.
- [COOK-634] - Implement LWRP for application deployment
- [COOK-1116] - use other SCMs than git
- [COOK-1252] - add `:force_deploy` that maps to corresponding action of deploy resource
- [COOK-1253] - fix rollback error
- [COOK-1312] - string callbacks fail with method not found
- [COOK-1313] - implicit file based hooks aren't invoked
- [COOK-1318] - Create `to_ary` method to resolve issue in resources() lookup on "application[foo]" resources
* [COOK-634] - Implement LWRP for application deployment.
* [COOK-1116] - use other SCMs than git.
* [COOK-1252] - add `:force_deploy` that maps to corresponding action of deploy resource.
* [COOK-1253] - fix rollback error.
* [COOK-1312] - string callbacks fail with method not found.
* [COOK-1313] - implicit file based hooks aren't invoked.
* [COOK-1318] - Create `to_ary` method to resolve issue in resources() lookup on "application[foo]" resources.
v0.99.14
--------
- [COOK-1065] - use pip in virtualenv during deploy
## v0.99.14
v0.99.12
--------
- [COOK-606] application cookbook deployment recipes should use ipaddress instead of fqdn
* [COOK-1065] - use pip in virtualenv during deploy.
v0.99.11
--------
- make the `_default` `chef_environment` look like production rails env
## v0.99.12
v0.99.10
--------
- Use Chef 0.10's `node.chef_environment` instead of `node['app_environment']`.
* [COOK-606] application cookbook deployment recipes should use ipaddress instead of fqdn.
## v0.99.11
* make the `_default` `chef_environment` look like production rails env.
## v0.99.10
* Use Chef 0.10's `node.chef_environment` instead of `node['app_environment']`.

View File

@ -1,206 +1,259 @@
Application cookbook
====================
This cookbook is designed to be able to describe and deploy web applications. It provides the basic infrastructure; other cookbooks are required to support specific combinations of frameworks and application servers. The following cookbooks are available at this time:
# Application cookbook
- [application_java](https://github.com/opscode-cookbooks/application_java) (Java and Tomcat)
- [application_nginx](https://github.com/opscode-cookbooks/application_nginx) (nginx reverse proxy)
- [application_php](https://github.com/opscode-cookbooks/application_php) (PHP with `mod_php_apache2`)
- [application_python](https://github.com/opscode-cookbooks/application_python) (Django with Gunicorn)
- [application_ruby](https://github.com/opscode-cookbooks/application_ruby) (Rails with Passenger or Unicorn)
[![Build Status](https://img.shields.io/travis/poise/application.svg)](https://travis-ci.org/poise/application)
[![Gem Version](https://img.shields.io/gem/v/poise-application.svg)](https://rubygems.org/gems/poise-application)
[![Cookbook Version](https://img.shields.io/cookbook/v/application.svg)](https://supermarket.chef.io/cookbooks/application)
[![Coverage](https://img.shields.io/codeclimate/coverage/github/poise/application.svg)](https://codeclimate.com/github/poise/application)
[![Gemnasium](https://img.shields.io/gemnasium/poise/application.svg)](https://gemnasium.com/poise/application)
[![License](https://img.shields.io/badge/license-Apache_2-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0)
A [Chef](https://www.chef.io/) cookbook to deploy applications.
Backwards Compatibility
-----------------------
- Version 4.0.0 dropped support for Chef 10
- Version 2.0.0 dropped support for the `apps` data bag.
## Getting Started
Requirements
------------
The previous dependencies have been moved out to the application-stack-specific cookbooks, and this cookbook has no external dependencies.
Resources/Providers
-------------------
The `application` LWRP configures the basic properties of most applications, regardless of the framework or application server they use. These include:
- SCM information for the deployment, such as the repository URL and branch name;
- deployment destination, including the filesystem path to deploy to;
- any OS packages to install as dependencies;
- optional callback to control the deployment.
This LWRP uses the `deploy_revision` LWRP to perform the bulk of its tasks, and many concepts and parameters map directly to it. Check the documentation for `deploy_revision` for more information.
Configuration of framework-specific aspects of the application are performed by invoking a sub-resource; see the appropriate cookbook for more documentation.
### Actions
- `:deploy`: deploy an application, including any necessary configuration, restarting the associated service if necessary
- `:force_deploy`: same as `:deploy`, but it will send a `:force_deploy` action to the deploy resource, directing it to deploy the application even if the same revision is already deployed
### Attribute Parameters
- `name`: name attribute. The name of the application you are setting up. This will be used to derive the default value for other attribute
- `packages`: an Array or Hash of packages to be installed before starting the deployment
- `path`: target path of the deployment; it will be created if it does not exist
- `owner`: the user that shall own the target path
- `group`: the group that shall own the target path
- `keep_releases`: count of keep releases
- `strategy`: the underlying LWRP that will be used to perform the deployment. The default is `:deploy_revision`, and it should never be necessary to change it
- `scm_provider`: the provider class to use for the deployment. It defaults to `Chef::Provider::Git`, you can set it to `Chef::Provider::Subversion` to deploy from an SVN repository
- `repository`: the URL of the repository the application should be checked out from
- `revision`: an identifier pointing to the revision that should be checked out
- `deploy_key`: the private key to use to access the repository via SSH, or path to a file containing the key
- `rollback_on_error`: if true, exceptions during a deployment will be caught and a clean rollback to the previous version will be attempted; the exception will then be re-raised. Defaults to true; change it only if you know what you are doing
- `environment`: a Hash of environment variables to set while running migrations
- `purge_before_symlink`: an Array of paths (relative to the checkout) to remove before creating symlinks
- `create_dirs_before_symlink`: an Array of paths (relative to the checkout) pointing to directories to create before creating symlinks
- `symlinks`: a Hash of shared/dir/path => release/dir/path. It determines which files and dirs in the shared directory get symlinked to the current release directory
- `symlink_before_migrate`: similar to symlinks, except that they will be linked before any migration is run
- `migrate`: if `true` then migrations will be run; defaults to false
- `migration_command`: a command to run to migrate the application from the previous to the current state
- `restart_command`: a command to run when restarting the application
- `environment_name`: the name of a framework-specific "environment" (for example the Rails environment). By default it is the same as the Chef environment, unless it is `_default`, in which case it is set to `production`
- `enable_submodules`: whether to enable git submodules in the deploy, passed into the deploy resource.
### Callback Attributes
You can also set a few attributes on this LWRP that are interpreted as callback to be called at specific points during a deployment. If you pass a block, it will be evaluated within a new context. If you pass a string, it will be interpreted as a path (relative to the release directory) to a file; if it exists, it will be loaded and evaluated as though it were a Chef recipe.
The following callback attributes are available:
- `before_deploy`: invoked immediately after initial setup and before the deployment proper is started. This callback will be invoked on every Chef run
- `before_migrate`
- `before_symlink`
- `before_restart`
- `after_restart`
### Sub-resources
Anything that is not a known attribute will be interpreted as the name of a sub-resource; the resource will be looked up, and any nested attribute will be passed to it. More than one sub-resource can be added to an application; the order is significant, with the latter sub-resources overriding any sub-resource that comes before.
Sub-resources can set their own values for some attributes; if they do, they will be merged together with the attribute set on the main resource. The attributes that support this behavior are the following:
- `environment`: environment variables from the application and from sub-resources will be merged together, with later resources overriding values set in the application or previous resources
- `migration_command`: commands from the application and from sub-resources will be concatenated together joined with '&&' and run as a single shell command. The migration will only succeed if all the commands succeed
- `restart_command`: commands from the application and from sub-resources will be evaluated in order
- `symlink_before_migrate`: will be concatenated as a single array
- `callbacks`: sub-resources callbacks will be invoked first, followed by the application callbacks
Usage
-----
To use the application cookbook we recommend creating a cookbook named after the application, e.g. `my_app`. In `metadata.rb` you should declare a dependency on this cookbook and any framework cookbook the application may need. For example a Rails application may include:
The application cookbook provides a central framework to deploy applications
using Chef. Generally this will be web applications using things like Rails,
Django, or NodeJS, but the framework makes no specific assumptions. The core
`application` resource provides DSL support and helpers, but the heavy lifting
is all done in specific plugins detailed below. Each deployment starts with
an `application` resource:
```ruby
depends 'application'
depends 'application_ruby'
application '/path/to/deploy' do
owner 'root'
group 'root'
# ...
end
```
The default recipe should describe your application using the `application` LWRP; you may also include additional recipes, for example to set up a database, queues, search engines and other components of your application.
A recipe using this LWRP may look like this:
The `application` resource uses the Poise subresource system for plugins. This
means you configure the steps of the deployment like normal recipe code inside
the `application` resource, with a few special additions:
```ruby
application 'my_app' do
path '/deploy/to/dir'
owner 'app-user'
group 'app-group'
application '/path/to/deploy' do
# Application resource properties.
owner 'root'
group 'root'
repository 'http://git.example.com/my-app.git'
revision 'production'
# Apply the rails LWRP from application_ruby
rails do
# Rails-specific configuration. See the README in the
# application_ruby cookbook for more information.
# Subresources, like normal recipe code.
package 'ruby'
git '/path/to/deploy' do
repository 'https://github.com/example/myapp.git'
end
# Apply the passenger_apache2 LWRP, also from application_ruby
passenger_apache2 do
# Passenger-specific configuration.
application_rails '/path/to/deploy' do
database 'mysql://dbhost/myapp'
end
end
```
You can of course use any code necessary to determine the value of attributes:
When evaluating the recipe inside the `application` resource, it first checks
for `application_#{resource}`, as well as looking for an LWRP of the same name
in any cookbook starting with `application_`. This means that a resource named
`application_foo` can be used as `foo` inside the `application` resource:
```ruby
application 'my_app' do
repository 'http://git.example.com/my-app.git'
revision node.chef_environment == 'production' ? 'production' : 'develop'
application '/path/to/deploy' do
owner 'root'
group 'root'
rails '/path/to/deploy' do
database 'mysql://dbhost/myapp'
end
end
```
Attributes from the application and from sub-resources are merged together:
Additionally if a resource inside the `application` block doesn't have a name,
it uses the same name as the application resource itself:
```ruby
application 'my_app' do
restart_command 'kill -1 `cat /var/run/one.pid`'
environment 'LC_ALL' => 'en', 'FOO' => 'bar'
application '/path/to/deploy' do
owner 'root'
group 'root'
rails do
restart_command 'touch /tmp/something'
environment 'LC_ALL' => 'en_US'
end
passenger_apache2 do
environment 'FOO' => 'baz'
end
end
# at the end, you will have:
#
# restart_command #=> kill -1 `cat /var/run/one.pid` && touch /tmp/something
# environment #=> LC_ALL=en_US FOO=baz
```
Most databases have the concept of migrations (or you can just use your own):
```ruby
application 'my_app' do
path '/deploy/to/dir'
owner 'app-user'
group 'app-group'
repository 'http://git.example.com/my-app.git'
revision 'production'
php do
migrate true
migration_command 'your-applications-migrate-command'
database 'mysql://dbhost/myapp'
end
end
```
This will run `your-applications-migrate-command`, with the current directory set to the directory of the current checkout.
Other than those two special features, the recipe code inside the `application`
resource is processed just like any other recipe.
To use the application cookbook, we recommend creating a role named after the application, e.g. `my_app`. Create a Ruby DSL role in your chef-repo, or create the role directly with knife.
## Available Plugins
* [`application_git`](https://github.com/poise/application_git) Deploy
application code from a git repository.
* [`application_ruby`](https://github.com/poise/application_ruby) Manage Ruby
deployments, such as Rails or Sinatra applications.
* [`application_python`](https://github.com/poise/application_python) Manage
Python deployments, such as Django or Flask applications.
* [`application_javascript`](https://github.com/poise/application_javascript)
Manage server-side JavaScript deployments using Node.js or io.js.
* `application_java` *Coming soon!*
* `application_go` *Coming soon!*
* `application_erlang` *Coming soon!*
## Requirements
Chef 12 or newer is required.
## Resources
### `application`
The `application` resource has top-level configuration properties for each
deployment and acts as a container for other deployment plugin resources.
```ruby
name 'my_app'
description 'My application deployment'
run_list([
'recipe[my_app::default]'
])
application '/opt/test_sinatra' do
git 'https://github.com/example/my_sinatra_app.git'
bundle_install do
deployment true
end
unicorn do
port 9000
end
end
```
License and Authors
-------------------
- Author: Adam Jacob (<adam@opscode.com>)
- Author: Andrea Campi (<andrea.campi@zephirworks.com.com>)
- Author: Joshua Timberman (<joshua@opscode.com>)
- Author: Noah Kantrowitz (<noah@opscode.com>)
- Author: Seth Chisamore (<schisamo@opscode.com>)
#### Actions
```text
Copyright 2009-2013, Opscode, Inc.
* `:deploy` Deploy the application. *(default)*
* `:start` - Run `:start` on all subresources that support it.
* `:stop` - Run `:stop` on all subresources that support it.
* `:restart` - Run `:restart` on all subresources that support it.
* `:reload` - Run `:reload` on all subresources that support it.
#### Properties
* `path` Path to deploy the application to. *(name attribute)*
* `environment` Environment variables for all application deployment steps.
* `group` System group to deploy the application as.
* `owner` System user to deploy the application as.
* `action_on_update` Action to run on the application resource when any
subresource is updated. *(default: restart)*
* `action_on_update_immediately` Run the `action_on_update` notification with
`:immediately`. *(default: false)*
### `application_cookbook_file`, `application_file`, `application_template`
The `application_cookbook_file`, `application_file`, and `application_template`
resources extend the core Chef resources to take some application-level
configuration in to account:
```ruby
application '/opt/myapp' do
template 'myapp.conf' do
source 'myapp.conf.erb'
end
end
```
If the resource name is a relative path, it will be expanded relative to the
application path. If an owner or group is declared for the application, those
will be the default user and group for the resource.
All other actions and properties are the same as the similar resource in core Chef.
## Examples
Some test recipes are available as examples for common application frameworks:
* [Sinatra](https://github.com/poise/application_ruby/blob/master/test/cookbooks/application_ruby_test/recipes/sinatra.rb)
* [Rails](https://github.com/poise/application_ruby/blob/master/test/cookbooks/application_ruby_test/recipes/rails.rb)
* [Flask](https://github.com/poise/application_python/blob/master/test/cookbooks/application_python_test/recipes/flask.rb)
* [Django](https://github.com/poise/application_python/blob/master/test/cookbooks/application_python_test/recipes/django.rb)
* [Express](https://github.com/poise/application_javascript/blob/master/test/cookbooks/application_javascript_test/recipes/express.rb)
## Upgrading From 4.x
While the overall design of the revamped application resource is similar to the
4.x version, some changes will need to be made. The `name` property no longer
exists, with the name attribute being used as the path to the deployment.
The `packages` property has been removed as this is more easily handled via
normal recipe code.
The SCM-related properties like `repository` and `revision` are now handled by
normal plugins. If you were deploying from a private git repository you will
likely want to use the `application_git` cookbook, otherwise just use the
built-in `git` or `svn` resources as per normal.
The properties related to the `deploy` resource like `strategy` and `symlinks`
have been removed. The `deploy` resource is no longer used so these aren't
relevant. As a side effect of this, you'll likely want to point the upgraded
deployment at a new folder or manually clean the `current` and `shared` folders
from the existing folder. The pseudo-Capistrano layout used by the `deploy`
resource has few benefits in a config-managed world and introduced a lot of
complexity and moving pieces that are no longer required.
With the removal of the `deploy` resource, the callback properties and commands
are no longer used as well. Subresources no longer use the complex
actions-as-callbacks arrangement as existed before, instead following normal
Chef recipe flow. Individual subresources may need to be tweaked to work with
newer versions of the cookbooks they come from, though most have stayed similar
in overall approach.
## Database Migrations and Chef
Several of the web application deployment plugins include optional support to
run database migrations from Chef. For "toy" applications where the app and
database run together on a single machine, this is fine and is a nice time
saver. For anything more complex I highly recommend not running database
migrations from Chef. Some initial operations like creating the database and/or
database user are more reasonable as they tend to be done only once and by their
nature the application does not yet have users so some level of eventual
consistency is more acceptable. With migrations on a production application, I
encourage using Chef and the application cookbooks to handle deploying the code
and writing configuration files, but use something more specific to run the
actual migration task. [Fabric](http://www.fabfile.org/),
[Capistrano](http://capistranorb.com/), and [Rundeck](http://rundeck.org/) are
all good choices for this orchestration tooling.
Migrations can generally be applied idempotently but they have unique
constraints (pun definitely intended) that make them tricky in a Chef-like,
convergence-based system. First and foremost is that many table alterations
lock the table for updating for at least some period of time. That can mean that
while staging the new code or configuration data can happen within a window, the
migration itself needs to be run in careful lockstep with the rest of the
deployment process (eg. moving things in and out of load balancers). Beyond
that, while most web frameworks have internal idempotence checks for migrations,
running the process on two servers at the same time can have unexpected effects.
Overall migrations are best thought of as a procedural step rather than a
declaratively modeled piece of the system.
## Application Signals and Updates
The `application` resource exposes `start`, `stop`, `restart`, and `reload`
actions which will dispatch to any subresources attached to the application.
This allows for generic application-level restart or reload signals that will
work with any type of deployment.
Additionally the `action_on_update` property is used to set a default
notification so any subresource that updates will trigger an application
restart or reload. This can be disabled by setting `action_on_update false` if
you want to take manual control of service restarts.
## Sponsors
Development sponsored by [Chef Software](https://www.chef.io/), [Symonds & Son](http://symondsandson.com/), and [Orion](https://www.orionlabs.co/).
The Poise test server infrastructure is sponsored by [Rackspace](https://rackspace.com/).
## License
Copyright 2015, Noah Kantrowitz
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
```

View File

@ -0,0 +1,25 @@
#
# Copyright 2015, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
module PoiseApplication
autoload :AppMixin, 'poise_application/app_mixin'
autoload :Error, 'poise_application/error'
autoload :Resources, 'poise_application/resources'
autoload :ServiceMixin, 'poise_application/service_mixin'
autoload :Utils, 'poise_application/utils'
autoload :VERSION, 'poise_application/version'
end

View File

@ -0,0 +1,61 @@
#
# Copyright 2015, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require 'poise/utils'
require 'poise_application/app_mixin'
module PoiseApplication
# A helper mixin for `file`-like resources to make them take application
# resource data. Relative paths are expanded against the application path and
# the app owner/group are the default user/group for the resource.
#
# @api private
# @since 5.1.0
module AppFileMixin
include Poise::Utils::ResourceProviderMixin
module Resource
include PoiseApplication::AppMixin
def initialize(*)
super
# So our lazy default below can work. Not needed on 12.7+.
remove_instance_variable(:@path) if instance_variable_defined?(:@path)
end
# @!attribute path
# Override the default path to be relative to the app path.
# @return [String]
attribute(:path, kind_of: String, default: lazy { parent ? ::File.expand_path(name, parent.path) : name })
# @!attribute group
# Override the default group to be the app group if unspecified.
# @return [String, Integer]
attribute(:group, kind_of: [String, Integer, NilClass], default: lazy { parent && parent.group })
# @!attribute user
# Override the default user to be the app owner if unspecified.
# @return [String, Integer]
attribute(:user, kind_of: [String, Integer, NilClass], default: lazy { parent && parent.owner })
end
module Provider
include PoiseApplication::AppMixin
end
end
end

View File

@ -0,0 +1,69 @@
#
# Copyright 2015, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require 'chef/mash'
require 'poise/provider'
require 'poise/resource'
require 'poise/utils'
module PoiseApplication
# A helper mixin for application resources and providers. These are things
# intended to be used as subresources of the `application` resource.
#
# @since 5.0.0
module AppMixin
include Poise::Utils::ResourceProviderMixin
# A helper mixin for application resources.
module Resource
include Poise::Resource
# Set the parent type and optional flag.
poise_subresource(:application, true)
# @!attribute path
# Base path for the application.
# @return [String]
attribute(:path, kind_of: String, name_attribute: true)
# A delegator for accessing the application state. If no application
# parent is found, the state will be tracked internally within the
# resource.
#
# @return [Hash<Symbol, Object>]
def app_state
if parent
parent.app_state
else
# If there isn't a parent, just track within the resource.
@local_app_state ||= Mash.new
end
end
# Environment variables stored in the application state.
#
# @return [Hash<String, String>]
def app_state_environment
app_state[:environment] ||= Mash.new
end
end
module Provider
include Poise::Provider
end
end
end

View File

@ -0,0 +1,17 @@
#
# Copyright 2015, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require 'poise_application/resources'

View File

@ -0,0 +1,24 @@
#
# Copyright 2015, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
module PoiseApplication
# Base exception class for poise-application errors.
#
# @since 5.0.0
class Error < Exception
end
end

View File

@ -0,0 +1,29 @@
#
# Copyright 2015, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require 'poise_application/resources/application'
require 'poise_application/resources/application_cookbook_file'
require 'poise_application/resources/application_file'
require 'poise_application/resources/application_template'
module PoiseApplication
# Chef resources and providers for poise-application.
#
# @since 5.0.0
module Resources
end
end

View File

@ -0,0 +1,259 @@
#
# Copyright 2015, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require 'chef/dsl/recipe' # On 12.4+ this will pull in chef/dsl/resources.
require 'chef/resource'
require 'chef/provider'
require 'poise'
module PoiseApplication
module Resources
# (see Application::Resource)
# @since 5.0.0
module Application
# An `application` resource to manage application deployment.
#
# @since 5.0.0
# @provides application
# @action deploy
# @action start
# @action stop
# @action restart
# @action reload
# @example
# application '/srv/myapp' do
# git '...'
# poise_service 'myapp' do
# command '/srv/myapp/main'
# end
# end
class Resource < Chef::Resource
include Poise(container: true, container_namespace: false)
provides(:application)
actions(:deploy, :start, :stop, :restart, :reload)
# @!attribute path
# Application base path.
# @return [String]
attribute(:path, kind_of: String, name_attribute: true)
# @!attribute environment
# Environment variables to set for the whole application.
# @return [Hash<String, String>]
attribute(:environment, kind_of: Hash, default: lazy { Mash.new })
# @!attribute owner
# System user that will own the application. This can be overriden in
# individual subresources.
# @return [String]
attribute(:owner, kind_of: String)
# @!attribute group
# System group that will own the application. This can be overriden in
# individual subresources.
# @return [String]
attribute(:group, kind_of: String)
# @!attribute action_on_update
# Action to run when any subresource is updated. Defaults to `:restart`.
# @return [String, Symbol, nil, false]
attribute(:action_on_update, kind_of: [Symbol, String, NilClass, FalseClass], default: :restart)
# @!attribute action_on_update_immediately
# Run the {#action_on_update} notification with `:immediately`.
# @return [Boolean]
attribute(:action_on_update_immediately, equal_to: [true, false], default: false)
# Run the DSL rewire when the resource object is created.
# @api private
def initialize(*args)
super
_rewire_dsl! if node
end
# Application-specific state values used as a way to communicate between
# subresources.
#
# @return [Mash]
# @example
# if new_resource.parent && new_resource.parent.app_state['gemfile_path']
def app_state
@app_state ||= Mash.new(environment: environment)
end
# Override Container#register_subresource to add our action_on_update.
#
# @api private
def register_subresource(resource)
super.tap do |added|
if added && action_on_update
Chef::Log.debug("[#{self}] Registering #{action_on_update_immediately ? 'immediate ' : ''}#{action_on_update} notification from #{resource}")
resource.notifies action_on_update.to_sym, self, (action_on_update_immediately ? :immediately : :delayed)
end
end
end
private
# Find all resources that need to be rewired. This is anything with a
# name starting with application_.
#
# @return [Array<String>]
def _rewire_resources
if defined?(Chef::DSL::Resources)
# Chef >= 12.4.
Chef::DSL::Resources.instance_methods
else
# Chef < 12.4 >= 12.0.
Chef::Resource.descendants.map do |klass|
klass.node_map.instance_variable_get(:@map).keys + if klass.dsl_name.include?('::')
# Probably not valid.
# :nocov:
[]
# :nocov:
else
# Needed for things that don't call provides().
[klass.dsl_name]
end
end.flatten
end.map {|name| name.to_s }.select {|name| name.start_with?('application_') }.uniq
end
# Find all cookbooks that might contain LWRPs matching our name scheme.
#
# @return [Array<String>]
def _rewire_cookbooks
# Run context might be unset during test setup.
if run_context
run_context.cookbook_collection.keys.select {|cookbook_name| cookbook_name.start_with?('application_') }
else
[]
end
end
# Build the mapping of new_name => old_name for each resource to rewire.
#
# @return [Hash<String, String>]
def _rewire_map
application_cookbooks = _rewire_cookbooks
_rewire_resources.inject({}) do |memo, name|
# Grab the resource class to check if it is an LWRP.
klass = Chef::Resource.resource_for_node(name.to_sym, node)
# Find the part to trim. Check for LWRP first, then just application_.
trim = if klass < Chef::Resource::LWRPBase
application_cookbooks.find {|cookbook_name| name.start_with?(cookbook_name) && name != cookbook_name } || 'application'
else
# Non-LWRPs are assumed to have a better name.
'application'
end
# Map trimmed to untrimmed.
memo[name[trim.length+1..-1]] = name
memo
end
end
# Build new DSL methods to implement the foo -> application_foo behavior.
#
# @return [void]
def _rewire_dsl!
# Generate stub methods for all the rewiring.
_rewire_map.each do |new_name, old_name|
# This is defined as a singleton method on self so it looks like
# the DSL but is scoped to just this context.
define_singleton_method(new_name) do |name=nil, *args, &block|
# Store the caller to correct the source_line.
created_at = caller[0]
public_send(old_name, name, *args) do
# Set the declared type to be the native name.
self.declared_type = self.class.resource_name
# Fix the source location. For Chef 12.4 we could do this with the
# declared_at parameter on the initial send.
self.source_line = created_at
# Run the original block.
instance_exec(&block) if block
end
end
end
end
end
# Provider for `application`.
#
# @since 5.0.0
# @see Resource
# @provides application
class Provider < Chef::Provider
include Poise
provides(:application)
# `deploy` action for `application`. Creates the application base folder.
#
# @return [void]
def action_deploy
notifying_block do
directory new_resource.path do
owner new_resource.owner
group new_resource.group
mode '755'
end
end
end
# `start` action for `application`. Proxies to subresources.
#
# @return [void]
def action_start
proxy_action(:start)
end
# `stop` action for `application`. Proxies to subresources.
#
# @return [void]
def action_stop
proxy_action(:stop)
end
# `restart` action for `application`. Proxies to subresources.
#
# @return [void]
def action_restart
proxy_action(:restart)
end
# `reload` action for `application`. Proxies to subresources.
#
# @return [void]
def action_reload
proxy_action(:reload)
end
private
# Proxy an action to any subresources that support it.
#
# @param action [Symbol] Action to proxy.
# @return [void]
def proxy_action(action)
Chef::Log.debug("[#{new_resource} Running proxied #{action} action")
new_resource.subresources.each do |r|
begin
r.run_action(action) if r.allowed_actions.include?(action)
rescue Chef::Exceptions::UnsupportedAction
# Don't care, just move on.
end
end
end
end
end
end
end

View File

@ -0,0 +1,54 @@
#
# Copyright 2015, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require 'poise_application/app_file_mixin'
module PoiseApplication
module Resources
# (see ApplicationCookbookFile::Resource)
# @since 5.1.0
module ApplicationCookbookFile
# An `application_cookbook_file` resource to manage Chef cookbook_files inside and
# Application cookbook deployment.
#
# @provides application_cookbook_file
# @action create
# @action create_if_missing
# @action delete
# @action touch
# @example
# application '/srv/myapp' do
# cookbook_file 'myapp.conf' do
# source 'myapp.conf'
# end
# end
class Resource < Chef::Resource::CookbookFile
include PoiseApplication::AppFileMixin
provides(:application_cookbook_file)
actions(:create, :create_if_missing, :delete, :touch)
subclass_providers!
def initialize(*args)
super
# For older Chef.
@resource_name = :application_cookbook_file
end
end
end
end
end

View File

@ -0,0 +1,54 @@
#
# Copyright 2015, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require 'poise_application/app_file_mixin'
module PoiseApplication
module Resources
# (see ApplicationFile::Resource)
# @since 5.1.0
module ApplicationFile
# An `application_file` resource to manage Chef files inside and
# Application cookbook deployment.
#
# @provides application_file
# @action create
# @action create_if_missing
# @action delete
# @action touch
# @example
# application '/srv/myapp' do
# file 'myapp.conf' do
# source 'myapp.conf.erb'
# end
# end
class Resource < Chef::Resource::File
include PoiseApplication::AppFileMixin
provides(:application_file)
actions(:create, :create_if_missing, :delete, :touch)
subclass_providers!
def initialize(*args)
super
# For older Chef.
@resource_name = :application_file
end
end
end
end
end

View File

@ -0,0 +1,54 @@
#
# Copyright 2015, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require 'poise_application/app_file_mixin'
module PoiseApplication
module Resources
# (see ApplicationTemplate::Resource)
# @since 5.1.0
module ApplicationTemplate
# An `application_template` resource to manage Chef templates inside and
# Application cookbook deployment.
#
# @provides application_template
# @action create
# @action create_if_missing
# @action delete
# @action touch
# @example
# application '/srv/myapp' do
# template 'myapp.conf' do
# source 'myapp.conf.erb'
# end
# end
class Resource < Chef::Resource::Template
include PoiseApplication::AppFileMixin
provides(:application_template)
actions(:create, :create_if_missing, :delete, :touch)
subclass_providers!
def initialize(*args)
super
# For older Chef.
@resource_name = :application_template
end
end
end
end
end

View File

@ -0,0 +1,116 @@
#
# Copyright 2015, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require 'chef/resource'
require 'chef/provider'
require 'poise/utils'
require 'poise_service/service_mixin'
require 'poise_service/utils'
require 'poise_application/app_mixin'
require 'poise_application/utils'
module PoiseApplication
# Mixin for application services. This is any resource that will be part of
# an application deployment and involves running a persistent service.
#
# @api public
# @since 5.0.0
# @example
# module MyApp
# class Resource < Chef::Resource
# include Poise
# provides(:my_app)
# include PoiseApplication::ServiceMixin
# end
#
# class Provider < Chef::Provider
# include Poise
# provides(:my_app)
# include PoiseApplication::ServiceMixin
#
# def action_enable
# notifying_block do
# template '/etc/myapp.conf' do
# # ...
# end
# end
# super
# end
#
# def service_options(r)
# super
# r.command('myapp --serve')
# end
# end
# end
module ServiceMixin
include Poise::Utils::ResourceProviderMixin
# Mixin for application service resources.
#
# @see ServiceMixin
module Resource
include PoiseService::ServiceMixin::Resource
include PoiseApplication::AppMixin::Resource
module ClassMethods
# @api private
def included(klass)
super
klass.extend(ClassMethods)
klass.class_exec do
attribute(:path, kind_of: String, name_attribute: true)
# Redefines from the PoiseService version so we get a better default.
attribute(:service_name, kind_of: String, default: lazy { PoiseService::Utils.parse_service_name(path) })
attribute(:user, kind_of: [String, Integer], default: lazy { parent ? parent.owner : 'root' })
end
end
end
extend ClassMethods
end
# Mixin for application service providers.
#
# @see ServiceMixin
module Provider
include PoiseService::ServiceMixin::Provider
include PoiseApplication::AppMixin::Provider
private
# Abstract hook to set parameters on {#service_resource} when it is
# created. This is required to set at least `resource.command`.
#
# @api public
# @param resource [Chef::Resource] Resource instance to set parameters on.
# @return [void]
# @example
# def service_options(resource)
# super
# resource.command('myapp --serve')
# end
def service_options(resource)
super
resource.directory(new_resource.path)
resource.user(new_resource.user)
resource.environment.update(new_resource.app_state_environment) if new_resource.parent
end
end
end
end

View File

@ -0,0 +1,51 @@
#
# Copyright 2015, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require 'etc'
module PoiseApplication
# Utility methods for PoiseApplication.
#
# @api public
# @since 5.0.0
module Utils
# Methods are also available as module-level methods as well as a mixin.
extend self
# Try to find the primary group name for a given user.
#
# @param user [String, Integer] User to check, if given as an integer this
# is used as a UID, otherwise it is the username.
# @return [String]
# @example
# attribute(:group, kind_of: [String, Integer], default: lazy { PoiseApplication::Utils.primary_group_for(user) })
def primary_group_for(user)
# Force a reload in case any users were created earlier in the run.
Etc.endpwent
Etc.endgrent
user = if user.is_a?(Integer)
Etc.getpwuid(user)
else
Etc.getpwnam(user.to_s)
end
Etc.getgrgid(user.gid).name
rescue ArgumentError
# One of the get* calls exploded. ¯\_(ツ)_/¯
user.to_s
end
end
end

View File

@ -0,0 +1,20 @@
#
# Copyright 2015, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
module PoiseApplication
VERSION = '5.1.0'
end

View File

@ -1,15 +1,11 @@
#
# Author:: Noah Kantrowitz <noah@opscode.com>
# Cookbook Name:: application
# Library:: default
#
# Copyright:: 2011-2012, Opscode, Inc <legal@opscode.com>
# Copyright 2015, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
@ -18,172 +14,6 @@
# limitations under the License.
#
require "chef/mixin/from_file"
class Chef
class Resource
# Monkey-Patch the blacklists to prevent infinite recursion in #to_json and similar
# (this is global state,thus the set-union operator to change it idempotently + to not leak)
[ :@application, :@application_provider ].each do |ivar|
FORBIDDEN_IVARS << ivar unless FORBIDDEN_IVARS.include?(ivar)
HIDDEN_IVARS << ivar unless HIDDEN_IVARS.include?(ivar)
end
end
end
class ApplicationCookbook
module OptionsCollector
def options
@options ||= {}
end
def method_missing(method_sym, value=nil, &block)
super
rescue NameError
value ||= block
method_sym = method_sym.to_s.chomp('=').to_sym
options[method_sym] = value if value
options[method_sym] ||= nil
end
end
module ResourceBase
def self.included(klass)
klass.actions :before_compile, :before_deploy, :before_migrate, :before_symlink, :before_restart, :after_restart
klass.attribute :id, :kind_of => String, :name_attribute => true
klass.attribute :environment, :kind_of => Hash, :default => {}
klass.attribute :purge_before_symlink, :kind_of => Array, :default => []
klass.attribute :create_dirs_before_symlink, :kind_of => Array, :default => []
klass.attribute :symlinks, :kind_of => Hash, :default => {}
klass.attribute :symlink_before_migrate, :kind_of => Hash, :default => {}
klass.attribute :migration_command, :kind_of => [String, NilClass], :default => nil
klass.attribute :application
klass.attribute :application_provider
klass.attribute :type
end
def restart_command(arg=nil, &block)
arg ||= block
raise "Invalid restart command" unless !arg || arg.is_a?(String) || arg.is_a?(Proc)
@restart_command = arg if arg
@restart_command
end
def method_missing(name, *args)
if application.respond_to? name
application.send(name, *args)
else
super
end
end
class OptionsBlock
include ApplicationCookbook::OptionsCollector
end
def options_block(options=nil, &block)
options ||= {}
if block
collector = OptionsBlock.new
collector.instance_eval(&block)
options.update(collector.options)
end
options
end
def find_matching_role(role, single=true, &block)
return nil if !role
nodes = []
if node['roles'].include? role
nodes << node
end
if !single || nodes.empty?
search(:node, "role:#{role} AND chef_environment:#{node.chef_environment}") do |n|
nodes << n
end
end
if block
nodes.each do |n|
yield n
end
else
if single
nodes.first
else
nodes
end
end
end
def find_database_server(role)
dbm = find_matching_role(role)
Chef::Log.warn("No node with role #{role}") if role && !dbm
if respond_to?(:database) && database.has_key?('host')
database['host']
elsif dbm && dbm.attribute?('cloud')
dbm['cloud']['local_ipv4']
elsif dbm
dbm['ipaddress']
end
end
end
module ProviderBase
def self.included(klass)
klass.send(:include, Chef::Mixin::FromFile)
end
def deploy_provider
@deploy_provider ||= begin
provider = @deploy_resource.provider_for_action(:nothing)
provider.load_current_resource
provider
end
end
def release_path
deploy_provider.release_path
end
def shared_path
@deploy_resource.shared_path
end
def callback(what, callback_code=nil)
Chef::Log.debug("Got callback #{what}: #{callback_code.inspect}")
@collection = Chef::ResourceCollection.new
case callback_code
when Proc
Chef::Log.info "#{@new_resource} running callback #{what}"
safe_recipe_eval(&callback_code)
when String
callback_file = "#{release_path}/#{callback_code}"
unless ::File.exist?(callback_file)
raise RuntimeError, "Can't find your callback file #{callback_file}"
end
run_callback_from_file(callback_file)
when nil
nil
else
raise RuntimeError, "You gave me a callback I don't know what to do with: #{callback_code.inspect}"
end
end
def run_callback_from_file(callback_file)
if ::File.exist?(callback_file)
Dir.chdir(release_path) do
Chef::Log.info "#{@new_resource} running deploy hook #{callback_file}"
safe_recipe_eval { from_file(callback_file) }
end
end
end
def safe_recipe_eval(&callback_code)
recipe_eval(&callback_code)
converge if respond_to?(:converge)
end
end
end
raise 'Halite is not compatible with no_lazy_load false, please set no_lazy_load true in your Chef configuration file.' unless Chef::Config[:no_lazy_load]
$LOAD_PATH << File.expand_path('../../files/halite_gem', __FILE__)
require "poise_application/cheftie"

View File

@ -1,11 +0,0 @@
if defined?(ChefSpec)
def deploy_application(resource)
ChefSpec::Matchers::ResourceMatcher.new(:application, :deploy, resource)
end
def force_deploy_application(resource)
ChefSpec::Matchers::ResourceMatcher.new(:application, :force_deploy, resource)
end
end

File diff suppressed because one or more lines are too long

View File

@ -1,191 +0,0 @@
#
# Author:: Noah Kantrowitz <noah@opscode.com>
# Cookbook Name:: application
# Provider:: default
#
# Copyright:: 2011-2012, Opscode, Inc <legal@opscode.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
include ApplicationCookbook::ProviderBase
action :deploy do
before_compile
before_deploy
run_deploy
end
action :force_deploy do
before_compile
before_deploy
run_deploy(true)
end
action :restart do
before_compile
run_actions_with_context(:before_restart, @run_context)
run_restart
run_actions_with_context(:after_restart, @run_context)
@new_resource.updated_by_last_action(true)
end
protected
def before_compile
new_resource.application_provider self
new_resource.sub_resources.each do |resource|
resource.application_provider self
resource.run_action :before_compile
end
end
def before_deploy
new_resource.packages.each do |pkg,ver|
package pkg do
action :install
version ver if ver && ver.length > 0
end
end
directory new_resource.path do
owner new_resource.owner
group new_resource.group
mode '0755'
recursive true
end
directory "#{new_resource.path}/shared" do
owner new_resource.owner
group new_resource.group
mode '0755'
recursive true
end
if new_resource.deploy_key
if ::File.exists?(new_resource.deploy_key)
deploy_key = open(new_resource.deploy_key, &:read)
else
deploy_key = new_resource.deploy_key
end
file "#{new_resource.path}/id_deploy" do
content deploy_key
owner new_resource.owner
group new_resource.group
mode '0600'
end
template "#{new_resource.path}/deploy-ssh-wrapper" do
source "deploy-ssh-wrapper.erb"
cookbook "application"
owner new_resource.owner
group new_resource.group
mode "0755"
variables :id => new_resource.name, :deploy_to => new_resource.path, :strict_ssh => new_resource.strict_ssh
end
end
ruby_block "#{new_resource.name} before_deploy" do
block do
new_resource.sub_resources.each do |resource|
resource.run_action :before_deploy
end
callback(:before_deploy, new_resource.before_deploy)
end
end
end
def run_deploy(force = false)
# Alias to a variable so I can use in sub-resources
new_resource = @new_resource
# Also alias to variable so it can be used in sub-resources
app_provider = self
@deploy_resource = send(new_resource.strategy.to_sym, new_resource.name) do
action force ? :force_deploy : :deploy
scm_provider new_resource.scm_provider
revision new_resource.revision
repository new_resource.repository
enable_submodules new_resource.enable_submodules
user new_resource.owner
group new_resource.group
keep_releases new_resource.keep_releases
deploy_to new_resource.path
ssh_wrapper "#{new_resource.path}/deploy-ssh-wrapper" if new_resource.deploy_key
shallow_clone new_resource.shallow_clone
rollback_on_error new_resource.rollback_on_error
all_environments = ([new_resource.environment]+new_resource.sub_resources.map{|res| res.environment}).inject({}){|acc, val| acc.merge(val)}
environment all_environments
migrate new_resource.migrate
all_migration_commands = ([new_resource.migration_command]+new_resource.sub_resources.map{|res| res.migration_command}).select{|cmd| cmd && !cmd.empty?}
migration_command all_migration_commands.join(' && ')
restart_command do
([new_resource]+new_resource.sub_resources).each do |res|
cmd = res.restart_command
if cmd.is_a? Proc
app_provider.deploy_provider.instance_eval(&cmd) # @see libraries/default.rb
elsif cmd && !cmd.empty?
execute cmd do
user new_resource.owner
group new_resource.group
environment all_environments
end
end
end
end
purge_before_symlink (new_resource.purge_before_symlink + new_resource.sub_resources.map(&:purge_before_symlink)).flatten
create_dirs_before_symlink (new_resource.create_dirs_before_symlink + new_resource.sub_resources.map(&:create_dirs_before_symlink)).flatten
all_symlinks = [new_resource.symlinks]+new_resource.sub_resources.map{|res| res.symlinks}
symlinks all_symlinks.inject({}){|acc, val| acc.merge(val)}
all_symlinks_before_migrate = [new_resource.symlink_before_migrate]+new_resource.sub_resources.map{|res| res.symlink_before_migrate}
symlink_before_migrate all_symlinks_before_migrate.inject({}){|acc, val| acc.merge(val)}
before_migrate do
app_provider.send(:run_actions_with_context, :before_migrate, @run_context)
end
before_symlink do
app_provider.send(:run_actions_with_context, :before_symlink, @run_context)
end
before_restart do
app_provider.send(:run_actions_with_context, :before_restart, @run_context)
end
after_restart do
app_provider.send(:run_actions_with_context, :after_restart, @run_context)
end
end
end
def run_actions_with_context(action, context)
new_resource.sub_resources.each do |resource|
saved_run_context = resource.instance_variable_get :@run_context
resource.instance_variable_set :@run_context, context
resource.run_action action
resource.instance_variable_set :@run_context, saved_run_context
end
callback(action, new_resource.send(action))
end

View File

@ -1,178 +0,0 @@
#
# Author:: Noah Kantrowitz <noah@opscode.com>
# Cookbook Name:: application
# Resource:: default
#
# Copyright:: 2011-2012, Opscode, Inc <legal@opscode.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require 'weakref'
include Chef::DSL::Recipe
def initialize(*args)
super
@action = :deploy
@sub_resources = []
end
actions :deploy, :force_deploy
attribute :name, :kind_of => String, :name_attribute => true
attribute :environment_name, :kind_of => String, :default => (node.chef_environment =~ /_default/ ? "production" : node.chef_environment)
attribute :path, :kind_of => String
attribute :owner, :kind_of => String
attribute :group, :kind_of => String
attribute :keep_releases, :kind_of => Integer, :default => 5
attribute :strategy, :kind_of => [String, Symbol], :default => :deploy_revision
attribute :scm_provider, :kind_of => [Class, String, Symbol]
attribute :revision, :kind_of => String
attribute :repository, :kind_of => String
attribute :enable_submodules, :kind_of => [TrueClass, FalseClass], :default => false
attribute :environment, :kind_of => Hash, :default => {}
attribute :deploy_key, :kind_of => [String, NilClass], :default => nil
attribute :strict_ssh, :kind_of => [TrueClass, FalseClass], :default => false
attribute :shallow_clone, :kind_of => [TrueClass, FalseClass], :default => false
attribute :force, :kind_of => [TrueClass, FalseClass], :default => false
attribute :rollback_on_error, :kind_of => [TrueClass, FalseClass], :default => true
attribute :purge_before_symlink, :kind_of => Array, :default => []
attribute :create_dirs_before_symlink, :kind_of => Array, :default => []
attribute :symlinks, :kind_of => Hash, :default => {}
attribute :symlink_before_migrate, :kind_of => Hash, :default => {}
attribute :migrate, :kind_of => [TrueClass, FalseClass], :default => false
attribute :migration_command, :kind_of => [String, NilClass], :default => nil
attribute :packages, :kind_of => [Array, Hash], :default => []
attribute :application_provider
attr_reader :sub_resources
def restart_command(arg=nil, &block)
arg ||= block
set_or_return(:restart_command, arg, :kind_of => [Proc, String])
end
# Callback fires before deploy is started.
def before_deploy(arg=nil, &block)
arg ||= block
set_or_return(:before_deploy, arg, :kind_of => [Proc, String])
end
# Callback fires before migration is run.
def before_migrate(arg=nil, &block)
arg ||= block
set_or_return(:before_migrate, arg, :kind_of => [Proc, String])
end
# Callback fires before symlinking
def before_symlink(arg=nil, &block)
arg ||= block
set_or_return(:before_symlink, arg, :kind_of => [Proc, String])
end
# Callback fires before restart
def before_restart(arg=nil, &block)
arg ||= block
set_or_return(:before_restart, arg, :kind_of => [Proc, String])
end
# Callback fires after restart
def after_restart(arg=nil, &block)
arg ||= block
set_or_return(:after_restart, arg, :kind_of => [Proc, String])
end
def release_path
application_provider.release_path
end
def shared_path
application_provider.shared_path
end
def method_missing(name, *args, &block)
# Build the set of names to check for a valid resource
lookup_path = ["application_#{name}"]
run_context.cookbook_collection.each do |cookbook_name, cookbook_ver|
if cookbook_name.start_with?("application_")
lookup_path << "#{cookbook_name}_#{name}"
end
end
lookup_path << name
resource = nil
# Try to find our resource
lookup_path.each do |resource_name|
begin
Chef::Log.debug "Trying to load application resource #{resource_name} for #{name}"
resource = super(resource_name.to_sym, self.name, &block)
break
rescue NameError => e
# Works on any MRI ruby
if e.name == resource_name.to_sym || e.inspect =~ /\b#{resource_name}\b/
next
else
raise e
end
end
end
raise NameError, "No resource found for #{name}. Tried #{lookup_path.join(', ')}" unless resource
# Enforce action :nothing in case people forget
resource.action :nothing
# Make this a weakref to prevent a cycle between the application resource and the sub resources
resource.application WeakRef.new(self)
resource.type name
@sub_resources << resource
resource
end
def do_i_respond_to?(*args)
name = args.first.to_s
# Build the set of names to check for a valid resource
lookup_path = ["application_#{name}"]
run_context.cookbook_collection.each do |cookbook_name, cookbook_ver|
if cookbook_name.start_with?("application_")
lookup_path << "#{cookbook_name}_#{name}"
end
end
lookup_path << name
found = false
# Try to find our resource
lookup_path.each do |resource_name|
begin
Chef::Log.debug "Looking for application resource #{resource_name} for #{name}"
Chef::Resource.resource_for_node(resource_name.to_sym, node)
found = true
break
rescue NameError => e
# Keep calm and carry on
end
end
found
end
# If we are using a current version of ruby, use respond_to_missing?
# instead of respond_to? so we provide proper behavior
if(Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('1.9.1'))
def respond_to_missing?(*args)
super || do_i_respond_to?(*args)
end
else
def respond_to?(*args)
super || do_i_respond_to?(*args)
end
end
def to_ary
nil
end
alias :to_a :to_ary

View File

@ -1,8 +0,0 @@
#!/usr/bin/env bash
#
# Deploy SSH Wrapper
# App: <%= @id %>
#
# Rendered by Chef - local changes will be replaced
/usr/bin/env ssh <% unless @strict_ssh %>-o "StrictHostKeyChecking=no" <% end %>-i "<%= @deploy_to %>/id_deploy" $@

View File

@ -0,0 +1,10 @@
# Application_Git Changelog
## v1.1.0
* [#2](https://github.com/poise/application_git/issues/2) Inherit user and group values from the parent `application` resource.
* [#3](https://github.com/poise/application_git/issues/3) Fix usage with users created during the current Chef run.
## v1.0.0
* Initial release.

View File

@ -0,0 +1,108 @@
# Application_Git Cookbook
[![Build Status](https://img.shields.io/travis/poise/application_git.svg)](https://travis-ci.org/poise/application_git)
[![Gem Version](https://img.shields.io/gem/v/poise-application-git.svg)](https://rubygems.org/gems/poise-application-git)
[![Cookbook Version](https://img.shields.io/cookbook/v/application_git.svg)](https://supermarket.chef.io/cookbooks/application_git)
[![Coverage](https://img.shields.io/codecov/c/github/poise/application_git.svg)](https://codecov.io/github/poise/application_git)
[![Gemnasium](https://img.shields.io/gemnasium/poise/application_git.svg)](https://gemnasium.com/poise/application_git)
[![License](https://img.shields.io/badge/license-Apache_2-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0)
A [Chef](https://www.chef.io/) cookbook to handle deploying code from git when
using the [application cookbook](https://github.com/poise/application).
## Quick Start
To deploy from a private GitHub repository:
```ruby
application '/srv/myapp' do
git 'git@github.com:example/myapp.git' do
deploy_key chef_vault_item('deploy_keys', 'myapp')['key']
end
end
```
## Requirements
Chef 12 or newer is required.
## Resources
### `application_git`
The `application_git` resource deploys code from git. It extends the core `git`
resource to support deploy keys and disabling strict host key verification.
```ruby
application '/srv/myapp' do
git 'git@github.com:example/myapp.git'
end
```
#### Actions
All actions work the same as the core `git` resource.
* `:sync` Clone and checkout the requested revision *(default)*
* `:checkout` Checkout the request revision. If the repository isn't already
cloned, this action does nothing.
* `:export` Export the repository without the `.git` folder.
#### Properties
All properties from the core `git` resource work the same way with the following
additions:
* `deploy_key` SSH key to use with git. Can be specified either as a path to
key file already created or as a string value containing the key directly.
* `strict_ssh` Enable strict SSH host key checking. *(default: false)*
### DSL Usage
The `application_git` resource can be used directly as a replacement for the
core `git` resource:
```ruby
application_git '/srv/myapp' do
repository 'git@github.com:example/myapp.git'
deploy_key chef_vault_item('deploy_keys', 'myapp')['key']
end
```
Within the `application` resource, a simplified DSL is available. As with other
`application` plugins, the default name of the resource if unspecified is the
application path. The following two examples are equivalent:
```ruby
application '/srv/myapp' do
git do
repository 'git@github.com:example/myapp.git'
end
end
application '/srv/myapp' do
git 'git@github.com:example/myapp.git'
end
```
## Sponsors
Development sponsored by [Chef Software](https://www.chef.io/), [Symonds & Son](http://symondsandson.com/), and [Orion](https://www.orionlabs.co/).
The Poise test server infrastructure is sponsored by [Rackspace](https://rackspace.com/).
## License
Copyright 2015-2016, Noah Kantrowitz
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

View File

@ -0,0 +1,17 @@
#
# Copyright 2015-2016, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require 'poise_application_git'

View File

@ -0,0 +1,21 @@
#
# Copyright 2015-2016, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require 'poise_application_git/resource'
module PoiseApplicationGit
end

View File

@ -0,0 +1,17 @@
#
# Copyright 2015-2016, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require 'poise_application_git/resource'

View File

@ -0,0 +1,204 @@
#
# Copyright 2015-2016, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require 'zlib'
require 'chef/provider'
require 'chef/resource'
require 'poise_application/app_mixin'
require 'poise_application/resources/application'
require 'poise_application_git/safe_string'
module PoiseApplicationGit
# An `application_git` resource to clone application code from git.
#
# @since 1.0.0
# @provides application_git
# @action sync
# @action checkout
# @action export
# @example
# application '/srv/myapp' do
# git 'git@github.com:example/myapp.git' do
# deploy_key data_bag_item('deploy_keys', 'myapp')['key']
# end
# end
class Resource < Chef::Resource::Git
include PoiseApplication::AppMixin
provides(:application_git)
# @api private
def initialize(*args)
super
# Because the superclass declares this, we have to as well. Should be
# removable at some point when Chef makes everything use the provider
# resolver system instead.
@resource_name = :application_git
@provider = PoiseApplicationGit::Provider
# Clear defaults in older versions of Chef.
remove_instance_variable(:@group) if instance_variable_defined?(:@group)
remove_instance_variable(:@user) if instance_variable_defined?(:@user)
end
# @!attribute group
# Group to run git as. Defaults to the application group.
# @return [String, Integer, nil, false]
attribute(:group, kind_of: [String, Integer, NilClass, FalseClass], default: lazy { parent && parent.group })
# @!attribute strict_ssh
# Enable strict SSH host key checking. Defaults to false.
# @return [Boolean]
attribute(:strict_ssh, equal_to: [true, false], default: false)
# @!attribute user
# User to run git as. Defaults to the application owner.
# @return [String, Integer, nil, false]
attribute(:user, kind_of: [String, Integer, NilClass, FalseClass], default: lazy { parent && parent.owner })
# @api private
def after_created
# Allow using the repository as the name in an application block.
if parent && !repository
destination(parent.path)
repository(name)
end
end
# @!attribute deploy_key
# SSH deploy key as either a string value or a path to a key file.
# @return [String]
def deploy_key(val=nil)
# Use a SafeString for literal deploy keys so they aren't shown.
val = SafeString.new(val) if val && !deploy_key_is_local?(val)
set_or_return(:deploy_key, val, kind_of: String)
end
# Default SSH wrapper path.
#
# @api private
# @return [String]
def ssh_wrapper_path
@ssh_wrapper_path ||= ::File.expand_path("~#{user}/.ssh/ssh_wrapper_#{Zlib.crc32(name)}")
end
# Guess if the deploy key is a local path or literal value.
#
# @api private
# @param key [String, nil] Key value to check. Defaults to self.key.
# @return [Boolean]
def deploy_key_is_local?(key=nil)
key ||= deploy_key
key && key[0] == '/'
end
# Path to deploy key.
#
# @api private
# @return [String]
def deploy_key_path
@deploy_key_path ||= if deploy_key_is_local?
deploy_key
else
::File.expand_path("~#{user}/.ssh/id_deploy_#{Zlib.crc32(name)}")
end
end
end
# Provider for `application_git`.
#
# @since 1.0.0
# @see Resource
# @provides application_git
class Provider < Chef::Provider::Git
include PoiseApplication::AppMixin
provides(:application_git)
# @api private
def initialize(*args)
super
# Set the SSH wrapper path in a late-binding kind of way. This better
# supports situations where the user doesn't exist until Chef converges.
new_resource.ssh_wrapper(new_resource.ssh_wrapper_path) if new_resource.deploy_key
end
# @api private
def whyrun_supported?
false # Just not dealing with this right now
end
# Hack our special login in before load_current_resource runs because that
# needs access to the git remote.
#
# @api private
def load_current_resource
include_recipe('git')
notifying_block do
create_dotssh
write_deploy_key
write_ssh_wrapper
end if new_resource.deploy_key
super
end
private
# Create a .ssh folder for the user.
#
# @return [void]
def create_dotssh
directory ::File.expand_path("~#{new_resource.user}/.ssh") do
owner new_resource.user
group new_resource.group
mode '755'
end
end
# Copy the deploy key to a file if needed.
#
# @return [void]
def write_deploy_key
# Check if we have a local path or some actual content
return if new_resource.deploy_key_is_local?
file new_resource.deploy_key_path do
owner new_resource.user
group new_resource.group
mode '600'
content new_resource.deploy_key
sensitive true
end
end
# Create the SSH wrapper script.
#
# @return [void]
def write_ssh_wrapper
# Write out the GIT_SSH script, it should already be enabled above
file new_resource.ssh_wrapper_path do
owner new_resource.user
group new_resource.group
mode '700'
content %Q{#!/bin/sh\n/usr/bin/env ssh #{'-o "StrictHostKeyChecking=no" ' unless new_resource.strict_ssh}-i "#{new_resource.deploy_key_path}" $@\n}
end
end
# Patch back in the `#git` from the git provider. This otherwise conflicts
# with the `#git` defined by the DSL, which gets included in such a way
# that the DSL takes priority.
def git(*args, &block)
Chef::Provider::Git.instance_method(:git).bind(self).call(*args, &block)
end
end
end

View File

@ -0,0 +1,25 @@
#
# Copyright 2015-2016, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
module PoiseApplicationGit
# A string that won't be shown in Chef error output
class SafeString < String
def to_text
'"suppressed sensitive value"'
end
end
end

View File

@ -0,0 +1,20 @@
#
# Copyright 2015-2016, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
module PoiseApplicationGit
VERSION = '1.1.0'
end

View File

@ -0,0 +1,19 @@
#
# Copyright 2015-2016, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
raise 'Halite is not compatible with no_lazy_load false, please set no_lazy_load true in your Chef configuration file.' unless Chef::Config[:no_lazy_load]
$LOAD_PATH << File.expand_path('../../files/halite_gem', __FILE__)
require "poise_application_git/cheftie"

View File

@ -0,0 +1 @@
{"name":"application_git","version":"1.1.0","description":"A plugin for poise-application to deploy applications from git.","long_description":"# Application_Git Cookbook\n\n[![Build Status](https://img.shields.io/travis/poise/application_git.svg)](https://travis-ci.org/poise/application_git)\n[![Gem Version](https://img.shields.io/gem/v/poise-application-git.svg)](https://rubygems.org/gems/poise-application-git)\n[![Cookbook Version](https://img.shields.io/cookbook/v/application_git.svg)](https://supermarket.chef.io/cookbooks/application_git)\n[![Coverage](https://img.shields.io/codecov/c/github/poise/application_git.svg)](https://codecov.io/github/poise/application_git)\n[![Gemnasium](https://img.shields.io/gemnasium/poise/application_git.svg)](https://gemnasium.com/poise/application_git)\n[![License](https://img.shields.io/badge/license-Apache_2-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0)\n\nA [Chef](https://www.chef.io/) cookbook to handle deploying code from git when\nusing the [application cookbook](https://github.com/poise/application).\n\n## Quick Start\n\nTo deploy from a private GitHub repository:\n\n```ruby\napplication '/srv/myapp' do\n git 'git@github.com:example/myapp.git' do\n deploy_key chef_vault_item('deploy_keys', 'myapp')['key']\n end\nend\n```\n\n## Requirements\n\nChef 12 or newer is required.\n\n## Resources\n\n### `application_git`\n\nThe `application_git` resource deploys code from git. It extends the core `git`\nresource to support deploy keys and disabling strict host key verification.\n\n```ruby\napplication '/srv/myapp' do\n git 'git@github.com:example/myapp.git'\nend\n```\n\n#### Actions\n\nAll actions work the same as the core `git` resource.\n\n* `:sync` Clone and checkout the requested revision *(default)*\n* `:checkout` Checkout the request revision. If the repository isn't already\n cloned, this action does nothing.\n* `:export` Export the repository without the `.git` folder.\n\n#### Properties\n\nAll properties from the core `git` resource work the same way with the following\nadditions:\n\n* `deploy_key` SSH key to use with git. Can be specified either as a path to\n key file already created or as a string value containing the key directly.\n* `strict_ssh` Enable strict SSH host key checking. *(default: false)*\n\n### DSL Usage\n\nThe `application_git` resource can be used directly as a replacement for the\ncore `git` resource:\n\n```ruby\napplication_git '/srv/myapp' do\n repository 'git@github.com:example/myapp.git'\n deploy_key chef_vault_item('deploy_keys', 'myapp')['key']\nend\n```\n\nWithin the `application` resource, a simplified DSL is available. As with other\n`application` plugins, the default name of the resource if unspecified is the\napplication path. The following two examples are equivalent:\n\n```ruby\napplication '/srv/myapp' do\n git do\n repository 'git@github.com:example/myapp.git'\n end\nend\n\napplication '/srv/myapp' do\n git 'git@github.com:example/myapp.git'\nend\n```\n\n## Sponsors\n\nDevelopment sponsored by [Chef Software](https://www.chef.io/), [Symonds & Son](http://symondsandson.com/), and [Orion](https://www.orionlabs.co/).\n\nThe Poise test server infrastructure is sponsored by [Rackspace](https://rackspace.com/).\n\n## License\n\nCopyright 2015-2016, Noah Kantrowitz\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\nhttp://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n","maintainer":"Noah Kantrowitz","maintainer_email":"noah@coderanger.net","license":"Apache 2.0","platforms":{},"dependencies":{"git":">= 0.0.0","poise":"~> 2.0","application":"~> 5.0"},"recommendations":{},"suggestions":{},"conflicting":{},"providing":{},"replacing":{},"attributes":{},"groupings":{},"recipes":{}}

View File

@ -0,0 +1,5 @@
# Application_Javascript Changelog
## v1.0.0
Initial release!

View File

@ -0,0 +1,132 @@
# Application_Javascript Cookbook
[![Build Status](https://img.shields.io/travis/poise/application_javascript.svg)](https://travis-ci.org/poise/application_javascript)
[![Gem Version](https://img.shields.io/gem/v/poise-application-javascript.svg)](https://rubygems.org/gems/poise-application-javascript)
[![Cookbook Version](https://img.shields.io/cookbook/v/application_javascript.svg)](https://supermarket.chef.io/cookbooks/application_javascript)
[![Coverage](https://img.shields.io/codecov/c/github/poise/application_javascript.svg)](https://codecov.io/github/poise/application_javascript)
[![Gemnasium](https://img.shields.io/gemnasium/poise/application_javascript.svg)](https://gemnasium.com/poise/application_javascript)
[![License](https://img.shields.io/badge/license-Apache_2-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0)
A [Chef](https://www.chef.io/) cookbook to deploy server-side JavaScript
applications using Node.js or io.js.
## Quick Start
To deploy an Express application from git:
```ruby
application '/srv/myapp' do
git 'https://github.com/example/myapp.git'
npm_install
npm_start
end
```
## Requirements
Chef 12 or newer is required.
## Resources
### `application_javascript`
The `application_javascript` resource installs a JavaScript runtime for the
deployment.
```ruby
application '/srv/myapp' do
javascript '3'
end
```
All actions and properties are the same as the [`javascript_runtime` resource](https://github.com/poise/poise-javascript#javascript_runtime).
### `application_javascript_service`
The `application_javascript_javascript_service` resource creates a service for a
JavaScript command.
```ruby
application '/srv/myapp' do
javascript_service 'main.js'
end
```
#### Actions
* `:enable` Create, enable and start the service. *(default)*
* `:disable` Stop, disable, and destroy the service.
* `:start` Start the service.
* `:stop` Stop the service.
* `:restart` Stop and then start the service.
* `:reload` Send the configured reload signal to the service.
#### Properties
* `command` Command to run. *(name attribute)*
* `path` Base path for the application. *(default: application path)*
* `service_name` Name of the service to create. *(default: auto-detect)*
# `user` User to run the service as. *(default: application owner)*
### `application_node_package`
The `application_node_package` resource installs NPM packages for the deployment.
```ruby
application '/srv/myapp' do
node_package 'grunt-cli'
end
```
All actions and properties are the same as the [`node_package` resource](https://github.com/poise/poise-javascript#node_package),
except that the `group` and `user` properties default to the application-level
data if not specified.
### `application_npm_start`
The `application_npm_start` resource creates a service for a JavaScript
application using `npm start`.
```ruby
application '/srv/myapp' do
npm_start
end
```
#### Actions
* `:enable` Create, enable and start the service. *(default)*
* `:disable` Stop, disable, and destroy the service.
* `:start` Start the service.
* `:stop` Stop the service.
* `:restart` Stop and then start the service.
* `:reload` Send the configured reload signal to the service.
#### Properties
* `path` Base path for the application. *(default: name attribute)*
* `command` NPM subcommand to run. *(default: start)*
* `service_name` Name of the service to create. *(default: auto-detect)*
# `user` User to run the service as. *(default: application owner)*
## Sponsors
Development sponsored by [Chef Software](https://www.chef.io/), [Symonds & Son](http://symondsandson.com/), and [Orion](https://www.orionlabs.co/).
The Poise test server infrastructure is sponsored by [Rackspace](https://rackspace.com/).
## License
Copyright 2015, Noah Kantrowitz
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

View File

@ -0,0 +1,23 @@
#
# Copyright 2015, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
module PoiseApplicationJavascript
autoload :AppMixin, 'poise_application_javascript/app_mixin'
autoload :Error, 'poise_application_javascript/error'
autoload :Resources, 'poise_application_javascript/resources'
autoload :VERSION, 'poise_application_javascript/version'
end

View File

@ -0,0 +1,67 @@
#
# Copyright 2015, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require 'poise/backports'
require 'poise/utils'
require 'poise_application/app_mixin'
require 'poise_javascript/javascript_command_mixin'
module PoiseApplicationJavascript
# A helper mixin for Javascript application resources and providers.
#
# @since 4.0.0
module AppMixin
include Poise::Utils::ResourceProviderMixin
# A helper mixin for Javascript application resources.
module Resource
include PoiseApplication::AppMixin::Resource
include PoiseJavascript::JavascriptCommandMixin::Resource
# @!attribute parent_javascript
# Override the #parent_javascript from JavascriptCommandMixin to grok the
# application level parent as a default value.
# @return [PoiseJavascript::Resources::JavascriptRuntime::Resource, nil]
parent_attribute(:javascript, type: :javascript_runtime, optional: true, default: lazy { app_state_javascript.equal?(self) ? nil : app_state_javascript })
# @attribute app_state_javascript
# The application-level Javascript parent.
# @return [PoiseJavascript::Resources::JavascriptRuntime::Resource, nil]
def app_state_javascript(javascript=Poise::NOT_PASSED)
unless javascript == Poise::NOT_PASSED
app_state[:javascript] = javascript
end
app_state[:javascript]
end
# A merged hash of environment variables for both the application state
# and parent javascript.
#
# @return [Hash<String, String>]
def app_state_environment_javascript
env = app_state_environment
env = env.merge(parent_javascript.javascript_environment) if parent_javascript
env
end
end
# A helper mixin for Javascript application providers.
module Provider
include PoiseApplication::AppMixin::Provider
end
end
end

View File

@ -0,0 +1,17 @@
#
# Copyright 2015, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require 'poise_application_javascript/resources'

View File

@ -0,0 +1,25 @@
#
# Copyright 2015, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require 'poise_application/error'
module PoiseApplicationJavascript
# Base exception class for poise-application-javascript errors.
#
# @since 1.0.0
class Error < PoiseApplication::Error
end
end

View File

@ -0,0 +1,22 @@
#
# Copyright 2015, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require 'poise_application_javascript/resources/javascript'
require 'poise_application_javascript/resources/javascript_execute'
require 'poise_application_javascript/resources/javascript_service'
require 'poise_application_javascript/resources/node_package'
require 'poise_application_javascript/resources/npm_install'
require 'poise_application_javascript/resources/npm_start'

View File

@ -0,0 +1,64 @@
#
# Copyright 2015, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require 'poise_javascript/resources/javascript_runtime'
require 'poise_application_javascript/app_mixin'
module PoiseApplicationJavascript
module Resources
# (see Javascript::Resource)
# @since 1.0.0
module Javascript
# An `application_javascript` resource to manage Javascript runtimes
# inside an Application cookbook deployment.
#
# @provides application_javascript
# @provides application_javascript_runtime
# @action install
# @action uninstall
# @example
# application '/app' do
# javascript '3'
# end
class Resource < PoiseJavascript::Resources::JavascriptRuntime::Resource
include PoiseApplicationJavascript::AppMixin
provides(:application_javascript)
# Need the double javascript for application resource rewriting.
provides(:application_javascript_runtime)
container_default(false)
subclass_providers!
# We want to run the base class version of this, not the one from the
# mixin. HULK SMASH.
def npm_binary
self.class.superclass.instance_method(:npm_binary).bind(self).call
end
# Set this resource as the app_state's parent javascript.
#
# @api private
def after_created
super.tap do |val|
app_state_javascript(self)
end
end
end
end
end
end

View File

@ -0,0 +1,88 @@
#
# Copyright 2015, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require 'poise_javascript/resources/javascript_execute'
require 'poise_application_javascript/app_mixin'
module PoiseApplicationJavascript
module Resources
# (see JavascriptExecute::Resource)
# @since 1.0.0
module JavascriptExecute
# An `application_javascript_execute` resource to run Javascript commands inside an
# Application cookbook deployment.
#
# @provides application_javascript_execute
# @action run
# @example
# application '/srv/myapp' do
# javascript_execute 'setup.py install'
# end
class Resource < PoiseJavascript::Resources::JavascriptExecute::Resource
include PoiseApplicationJavascript::AppMixin
provides(:application_javascript_execute)
def initialize(*args)
super
# Clear some instance variables so my defaults work.
remove_instance_variable(:@cwd)
remove_instance_variable(:@group)
remove_instance_variable(:@user)
end
# #!attribute cwd
# Override the default directory to be the app path if unspecified.
# @return [String]
attribute(:cwd, kind_of: [String, NilClass, FalseClass], default: lazy { parent && parent.path })
# #!attribute group
# Override the default group to be the app group if unspecified.
# @return [String, Integer]
attribute(:group, kind_of: [String, Integer, NilClass, FalseClass], default: lazy { parent && parent.group })
# #!attribute user
# Override the default user to be the app owner if unspecified.
# @return [String, Integer]
attribute(:user, kind_of: [String, Integer, NilClass, FalseClass], default: lazy { parent && parent.owner })
end
# The default provider for `application_javascript_execute`.
#
# @see Resource
# @provides application_javascript_execute
class Provider < PoiseJavascript::Resources::JavascriptExecute::Provider
provides(:application_javascript_execute)
private
# Override environment to add the application envivonrment instead.
#
# @return [Hash]
def environment
super.tap do |environment|
# Don't use the app_state_environment_javascript because we already have
# those values in place.
environment.update(new_resource.app_state_environment)
# Re-apply the resource environment for correct ordering.
environment.update(new_resource.environment) if new_resource.environment
end
end
end
end
end
end

View File

@ -0,0 +1,59 @@
#
# Copyright 2015, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require 'chef/provider'
require 'chef/resource'
require 'poise'
require 'poise_application_javascript/service_mixin'
module PoiseApplicationJavascript
module Resources
# (see JavascriptService::Resource)
# @since 1.0.0
module JavascriptService
class Resource < Chef::Resource
include PoiseApplicationJavascript::ServiceMixin
provides(:application_javascript_service)
# @!attribute command
# Command to run.
# @return [String]
attribute(:command, kind_of: String, name_attribute: true)
# @!attribute path
# Override {PoiseApplicationJavascript::ServiceMixin#path} to make it
# not the name_attribute.
# @return [String]
attribute(:path, kind_of: String, default: lazy { parent && parent.path })
end
class Provider < Chef::Provider
include PoiseApplicationJavascript::ServiceMixin
provides(:application_javascript_service)
private
# (see PoiseApplication::ServiceMixin#service_options)
def service_options(resource)
super
resource.javascript_command(new_resource.command)
end
end
end
end
end

View File

@ -0,0 +1,63 @@
#
# Copyright 2015, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require 'poise_javascript/resources/node_package'
require 'poise_application_javascript/app_mixin'
module PoiseApplicationJavascript
module Resources
# (see NodePackage::Resource)
# @since 1.0.0
module NodePackage
# An `application_node_package` resource to install NPM packages inside
# an Application cookbook deployment.
#
# @provides application_node_package
# @action install
# @action upgrade
# @action remove
# @example
# application '/app' do
# node_package %w{grunt-cli gulp}
# end
class Resource < PoiseJavascript::Resources::NodePackage::Resource
include PoiseApplicationJavascript::AppMixin
provides(:application_node_package)
subclass_providers!
def initialize(*args)
super
# For older Chef.
@resource_name = :application_node_package
end
# #!attribute group
# Override the default group to be the app group if unspecified.
# @return [String, Integer]
attribute(:group, kind_of: [String, Integer, NilClass], default: lazy { parent && parent.group })
# #!attribute user
# Override the default user to be the app owner if unspecified.
# @return [String, Integer]
attribute(:user, kind_of: [String, Integer, NilClass], default: lazy { parent && parent.owner })
# @todo This should handle relative paths against parent.path.
end
end
end
end

View File

@ -0,0 +1,45 @@
#
# Copyright 2015, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require 'poise_javascript/resources/npm_install'
require 'poise_application_javascript/app_mixin'
module PoiseApplicationJavascript
module Resources
# (see NpmInstall::Resource)
# @since 1.0.0
module NpmInstall
# An `application_npm_install` resource to install package
# dependencies inside an Application cookbook deployment.
#
# @provides application_npm_install
# @action install
# @example
# application '/app' do
# npm_install
# end
class Resource < PoiseJavascript::Resources::NpmInstall::Resource
include PoiseApplicationJavascript::AppMixin
provides(:application_npm_install)
subclass_providers!
# @todo This should handle relative paths against parent.path.
end
end
end
end

View File

@ -0,0 +1,78 @@
#
# Copyright 2015, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require 'shellwords'
require 'chef/provider'
require 'chef/resource'
require 'poise'
require 'poise_application_javascript/service_mixin'
module PoiseApplicationJavascript
module Resources
# (see NpmStart::Resource)
# @since 1.0.0
module NpmStart
# An `application_npm_start` resource to create a service for a Javascript
# application using `npm start`.
#
# @provides application_npm_start
# @action enable
# @action disable
# @action start
# @action stop
# @action restart
# @action reload
# @example
# application '/app' do
# npm_start
# end
class Resource < Chef::Resource
include PoiseApplicationJavascript::ServiceMixin
provides(:application_npm_start)
# @!attribute command
# NPM sub-command to run. Defaults to `start`.
# @return [String, Array<String>]
attribute(:command, kind_of: [String, Array], default: 'start')
end
# The default provider for `application_npm_start`.
#
# @see Resource
# @provides application_npm_start
class Provider < Chef::Provider
include PoiseApplicationJavascript::ServiceMixin
provides(:application_npm_start)
private
# (see PoiseApplication::ServiceMixin#service_options)
def service_options(resource)
super
npm_cmd = [new_resource.npm_binary] + Array(new_resource.command)
resource.javascript_command(Shellwords.join(npm_cmd))
# Make sure node is on $PATH because grrr.
new_path = [::File.dirname(new_resource.javascript), (new_resource.app_state_environment_javascript['PATH'] || ENV['PATH']).to_s].join(::File::PATH_SEPARATOR)
resource.environment['PATH'] = new_path
end
end
end
end
end

View File

@ -0,0 +1,57 @@
#
# Copyright 2015, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require 'poise/utils'
require 'poise_application/service_mixin'
require 'poise_languages/utils'
require 'poise_application_javascript/app_mixin'
module PoiseApplicationJavascript
# A helper mixin for Javascript service resources and providers.
#
# @since 1.0.0
module ServiceMixin
include Poise::Utils::ResourceProviderMixin
# A helper mixin for Javascript service resources.
module Resource
include PoiseApplication::ServiceMixin::Resource
include PoiseApplicationJavascript::AppMixin::Resource
end
# A helper mixin for Javascript service providers.
module Provider
include PoiseApplication::ServiceMixin::Provider
include PoiseApplicationJavascript::AppMixin::Provider
# Set up the service for running Javascript stuff.
def service_options(resource)
super
# Closure scoping for #javascript_command below.
self_ = self
# Create a new singleton method that fills in `node` for you.
resource.define_singleton_method(:javascript_command) do |val|
resource.command("#{self_.new_resource.javascript} #{PoiseLanguages::Utils.absolute_command(val, path: self_.new_resource.app_state_environment_javascript['PATH'])}")
end
# Include env vars as needed.
resource.environment.update(new_resource.parent_javascript.javascript_environment) if new_resource.parent_javascript
end
end
end
end

View File

@ -0,0 +1,19 @@
#
# Copyright 2015, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
module PoiseApplicationJavascript
VERSION = '1.0.0'
end

View File

@ -0,0 +1,19 @@
#
# Copyright 2015, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
raise 'Halite is not compatible with no_lazy_load false, please set no_lazy_load true in your Chef configuration file.' unless Chef::Config[:no_lazy_load]
$LOAD_PATH << File.expand_path('../../files/halite_gem', __FILE__)
require "poise_application_javascript/cheftie"

File diff suppressed because one or more lines are too long

View File

@ -1,201 +0,0 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

View File

@ -1,64 +0,0 @@
## Description
This cookbook is designed to be able to describe and deploy Node.js web applications using Upstart.
Note that this cookbook provides the Node-specific bindings for the `application` cookbook; you will find general documentation in that cookbook.
## Requirements
Chef 0.10.0 or higher required (for Chef environment use).
Upstart 1.4 or higher for the use of `setuid` in the default Upstart configuration template.
This requirement can be worked around by specifying a custom template.
The following Opscode cookbooks are dependencies:
* [application](https://github.com/opscode-cookbooks/application)
* [nodejs](https://github.com/mdxp/nodejs-cookbook)
## Resources/Providers
The `nodejs` sub-resource LWRP deals with deploying Node.js applications using Upstart. It is not meant to be used by itself; make sure you are familiar with the `application` cookbook before proceeding.
### Attribute Parameters
- **npm**: If `true`, `npm` will be used to install the dependencies specified in `packages.json`. Defaults to `true`.
- **template**: The name of the template that will be used to create the Upstart configuration file. If specified, it will be looked up in the application cookbook. Defaults to `nodejs.upstart.conf.erb` from this cookbook.
- **entry_point**: The argument to pass to node. Defaults to `app.js`.
## Usage
Here is an example hello world application using [Express](http://expressjs.com):
```
application "hello-world" do
path "/srv/node-hello-world"
owner "www-data"
group "www-data"
packages ["git"]
repository "git://github.com/visionmedia/express.git"
nodejs do
entry_point "examples/hello-world"
end
end
```
## License and Author
Author:: Conrad Kramer (<conrad@kramerapps.com>)
Copyright 2013, Kramer Software Productions, LLC.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

View File

@ -1,12 +0,0 @@
name "application_nodejs"
maintainer "Conrad Kramer"
maintainer_email "conrad@kramerapps.com"
license "Apache 2.0"
description "Deploys and configures Node.js applications"
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version "2.0.1"
depends "nodejs"
depends "application"
supports 'ubuntu', ">= 12.04"

View File

@ -1,130 +0,0 @@
#
# Author:: Conrad Kramer <conrad@kramerapps.com>
# Cookbook Name:: application_node
# Resource:: node
#
# Copyright:: 2013, Kramer Software Productions, LLC. <conrad@kramerapps.com>
#
# Licensed under the Apache License, Version 2.0 (the 'License');
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an 'AS IS' BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
include Chef::DSL::IncludeRecipe
action :before_compile do
r = new_resource
if new_resource.npm
include_recipe 'nodejs::npm'
end
unless new_resource.restart_command
new_resource.restart_command do
service "#{r.application.name}_nodejs" do
if platform?('ubuntu') && node[:platform_version].to_f >= 14.04
provider Chef::Provider::Service::Systemd
else
provider Chef::Provider::Service::Upstart
end
supports :restart => true, :start => true, :stop => true
action [:enable, :restart]
end
end
end
new_resource.environment.update({
'NODE_ENV' => r.environment_name
})
end
action :before_deploy do
new_resource.environment['NODE_ENV'] = new_resource.environment_name
r = new_resource
service "#{r.application.name}_nodejs" do
if platform?('ubuntu') && node[:platform_version].to_f >= 14.04
provider Chef::Provider::Service::Systemd
else
provider Chef::Provider::Service::Upstart
end
end
if platform?('ubuntu') && node[:platform_version].to_f >= 14.04
execute "systemctl daemon-reload" do
command "systemctl daemon-reload"
action :nothing
end
template "#{r.application.name}_nodejs.systemd.service.erb" do
path "/lib/systemd/system/#{r.application.name}_nodejs.service"
source r.template ? r.template : 'nodejs.systemd.service.erb'
cookbook r.template ? r.cookbook_name.to_s : 'application_nodejs'
owner 'root'
group 'root'
mode '0644'
variables(
:user => r.owner,
:group => r.group,
:app_dir => r.release_path,
:entry => r.entry_point,
:environment => r.environment
)
notifies :run, "execute[systemctl daemon-reload]", :delayed
notifies :restart, "service[#{r.application.name}_nodejs]", :delayed
end
else
template "#{new_resource.application.name}.upstart.conf" do
path "/etc/init/#{r.application.name}_nodejs.conf"
source r.template ? r.template : 'nodejs.upstart.conf.erb'
cookbook r.template ? r.cookbook_name.to_s : 'application_nodejs'
owner 'root'
group 'root'
mode '0644'
variables(
:user => r.owner,
:group => r.group,
:app_dir => r.release_path,
:entry => r.entry_point,
:environment => r.environment
)
notifies :restart, "service[#{r.application.name}_nodejs]", :delayed
end
end
end
action :before_migrate do
if new_resource.npm
execute 'npm install' do
cwd new_resource.release_path
user new_resource.owner
group new_resource.group
environment new_resource.environment.merge({ 'HOME' => new_resource.shared_path })
end
end
end
action :before_symlink do
end
action :before_restart do
end
action :after_restart do
end

View File

@ -1,4 +0,0 @@
[Service]
ExecStart=/usr/bin/env node <%= @entry %>
User=<%= @user %>
Group=<%= @group %>

View File

@ -1,19 +0,0 @@
#!upstart
description "Node.js Application Server"
start on (local-filesystems and net-device-up IFACE!=lo)
stop on [!12345]
console log
<% @environment.each do |key, value| -%>
env <%= key %>="<%= value %>"
<% end -%>
<% unless @user.nil? -%>
setuid <%= @user %>
<% end -%>
<% unless @group.nil? -%>
setgid <%= @group %>
<% end -%>
chdir <%= @app_dir %>
exec /usr/bin/env node <%= @entry %>

View File

@ -0,0 +1,86 @@
# Application_Ruby Changelog
## v4.0.1
* Correct `gem_binary` results for `application_ruby`.
## v4.0.0
* Massive rewrite on top of newer Chef patterns. See the 4.0 README for details.
## v3.0.2
* No changes, bumping version to get bits in various places in sync.
## v3.0.0
* Major version bump. Breaking backwards compatibility with Chef 10.
## v2.2.0
* [COOK-3895](https://tickets.opscode.com/browse/COOK-3895) - application_ruby use_omnibus_ruby attr needs to default to false.
* [COOK-3894](https://tickets.opscode.com/browse/COOK-3894) - application_ruby cookbook needs version bump to pick up application v4.0 cookbook.
* [COOK-2079](https://tickets.opscode.com/browse/COOK-2079) - Attempting to touch restart.txt should not cause a chef-client run to fail.
## v2.1.4
* [COOK-3625](https://tickets.opscode.com/browse/COOK-3625) - Fix an issue where unicorn fails when node does not provide cpu count.
## v2.1.2
* [COOK-3616](https://tickets.opscode.com/browse/COOK-3616) - Simplify log symlinking for rails apps.
## v2.1.0
* [COOK-3367](https://tickets.opscode.com/browse/COOK-3367) - Support more of unicorn's configuration.
* [COOK-3124](https://tickets.opscode.com/browse/COOK-3124) - Add `memcached_template` attribute to so alternative templates may be used.
## v2.0.0
### Bug
* [COOK-3306]: Multiple Memory Leaks in Application Cookbook.
* [COOK-3219]: `application_ruby` cookbook bundle install in 1.9.3-based omnibus installs 1.9.x gems into ruby 2.0 apps.
## v1.1.4
* [COOK-2806]: Including `passenger_apache2::mod_rails` does not enable passenger.
## v1.1.2
* [COOK-2638]: cookbook attribute is not treated as a string when specifying `database_yml_template`.
* [COOK-2525]: application_ruby: split runit template into multiple lines.
## v1.1.0
* [COOK-2362] - `application_ruby` unicorn uses `run_restart`.
* [COOK-2363] - `application_ruby` unicorn should set `log_template_name` and `run_template_name`.
## v1.0.10
* [COOK-2260] - pin runit version.
## v1.0.8
* [COOK-2159] - cookbook attribute is not treated as a string.
## v1.0.6
* [COOK-1481] - unicorn provider in application_ruby cookbook should run its restart command as root.
## v1.0.4
* [COOK-1572] - allow specification of 'bundle' command via attribute.
## v1.0.2
* [COOK-1360] - fix typo in README.
* [COOK-1374] - use runit attribute in unicorn run script.
* [COOK-1408] - use user and group from parent resource for runit service.
## v1.0.0
* [COOK-1247] - Initial release - relates to COOK-634.
* [COOK-1248] - special cases memcached.
* [COOK-1258] - Precompile assets for Rails 3.
* [COOK-1297] - Unicorn sub-resource should allow strings for 'port' attribute.

View File

@ -0,0 +1,271 @@
# Application_Ruby Cookbook
[![Build Status](https://img.shields.io/travis/poise/application_ruby.svg)](https://travis-ci.org/poise/application_ruby)
[![Gem Version](https://img.shields.io/gem/v/poise-application-ruby.svg)](https://rubygems.org/gems/poise-application-ruby)
[![Cookbook Version](https://img.shields.io/cookbook/v/application_ruby.svg)](https://supermarket.chef.io/cookbooks/application_ruby)
[![Coverage](https://img.shields.io/codecov/c/github/poise/application_ruby.svg)](https://codecov.io/github/poise/application_ruby)
[![Gemnasium](https://img.shields.io/gemnasium/poise/application_ruby.svg)](https://gemnasium.com/poise/application_ruby)
[![License](https://img.shields.io/badge/license-Apache_2-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0)
A [Chef](https://www.chef.io/) cookbook to deploy Ruby applications.
## Quick Start
To deploy a Rails application from git:
```ruby
application '/srv/myapp' do
git 'https://github.com/example/myapp.git'
bundle_install do
deployment true
without %w{development test}
end
rails do
database 'sqlite3:///db.sqlite3'
secret_token 'd78fe08df56c9'
migrate true
end
unicorn do
port 8000
end
end
```
## Requirements
Chef 12 or newer is required.
## Resources
### `application_bundle_install`
The `application_bundle_install` resource installs gems using Bundler for a
deployment.
```ruby
application '/srv/myapp' do
bundle_install do
deployment true
without %w{development test}
end
end
```
All actions and properties are the same as the [`bundle_install` resource](https://github.com/poise/poise-ruby#bundle_install).
### `application_rackup`
The `application_rackup` resource creates a service for `rackup`.
```ruby
application '/srv/myapp' do
rackup do
port 8000
end
end
```
#### Actions
* `:enable` Create, enable and start the service. *(default)*
* `:disable` Stop, disable, and destroy the service.
* `:start` Start the service.
* `:stop` Stop the service.
* `:restart` Stop and then start the service.
* `:reload` Send the configured reload signal to the service.
#### Properties
* `path` Base path for the application. *(name attribute)*
* `port` Port to listen on. *(default: 80)*
* `service_name` Name of the service to create. *(default: auto-detect)*
# `user` User to run the service as. *(default: application owner)*
### `application_rails`
The `application_rails` resource
```ruby
application '/srv/myapp' do
rails do
database 'sqlite3:///db.sqlite3'
secret_token 'd78fe08df56c9'
migrate true
end
end
```
#### Actions
* `:deploy` Create config files and run required deployments steps. *(default)*
#### Properties
* `path` Base path for the application. *(name attribute)*
* `database` Database settings for Rails. See [the database section
below](#database-parameters) for more information. *(option collector)*
* `migrate` Run database migrations. *(default: false)*
* `precompile_assets` Run `rake assets:precompile`. *(default: auto-detect)()
* `rails_env` Rails environment name. *(default: node.chef_environment)*
* `secret_token` Secret token for Rails session verification et al.
* `secrets_mode` Secrets configuration mode. Set to `:yaml` to generate a
Rails 4.2 secrets.yml. Set to `:initializer` to update
`config/initializers/secret_token.rb`. *(default: auto-detect)*
**NOTE:** At this time `secrets_mode :initializer` is not implemented.
#### Database Parameters
The database parameters can be set in three ways: URL, hash, and block.
If you have a single URL for the parameters, you can pass it directly to
`database`:
```ruby
rails do
database 'mysql2://myuser@dbhost/myapp'
end
```
Passing a single URL will also set the `$DATABASE_URL` environment variable
automatically for compatibility with Heroku-based applications.
As with other option collector resources, you can pass individual settings as
either a hash or block:
```ruby
rails do
database do
adapter 'mysql2'
username 'myuser'
host 'dbhost'
database 'myapp'
end
end
rails do
database({
adapter: 'mysql2',
username: 'myuser',
host: 'dbhost',
database: 'myapp',
})
end
```
### `application_ruby`
The `application_ruby` resource installs a Ruby runtime for the deployment.
```ruby
application '/srv/myapp' do
ruby '2.2'
end
```
All actions and properties are the same as the [`ruby_runtime` resource](https://github.com/poise/poise-ruby#ruby_runtime).
### `application_ruby_gem`
The `application_ruby_gem` resource installs Ruby gems for the deployment.
```ruby
application '/srv/myapp' do
ruby_gem 'rake'
end
```
All actions and properties are the same as the [`ruby_gem` resource](https://github.com/poise/poise-ruby#ruby_gem).
### `application_ruby_execute`
The `application_ruby_execute` resource runs Ruby commands for the deployment.
```ruby
application '/srv/myapp' do
ruby_execute 'rake'
end
```
All actions and properties are the same as the [`ruby_execute` resource](https://github.com/poise/poise-ruby#ruby_execute),
except that the `cwd`, `environment`, `group`, and `user` properties default to
the application-level data if not specified.
### `application_thin`
The `application_thin` resource creates a service for `thin`.
```ruby
application '/srv/myapp' do
thin do
port 8000
end
end
```
#### Actions
* `:enable` Create, enable and start the service. *(default)*
* `:disable` Stop, disable, and destroy the service.
* `:start` Start the service.
* `:stop` Stop the service.
* `:restart` Stop and then start the service.
* `:reload` Send the configured reload signal to the service.
#### Properties
* `path` Base path for the application. *(name attribute)*
* `config_path` Path to a Thin configuration file.
* `port` Port to listen on. *(default: 80)*
* `service_name` Name of the service to create. *(default: auto-detect)*
# `user` User to run the service as. *(default: application owner)*
### `application_unicorn`
The `application_unicorn` resource creates a service for `unicorn`.
```ruby
application '/srv/myapp' do
unicorn do
port 8000
end
end
```
#### Actions
* `:enable` Create, enable and start the service. *(default)*
* `:disable` Stop, disable, and destroy the service.
* `:start` Start the service.
* `:stop` Stop the service.
* `:restart` Stop and then start the service.
* `:reload` Send the configured reload signal to the service.
#### Properties
* `path` Base path for the application. *(name attribute)*
* `port` Port to listen on. *(default: 80)*
* `service_name` Name of the service to create. *(default: auto-detect)*
# `user` User to run the service as. *(default: application owner)*
## Sponsors
Development sponsored by [Chef Software](https://www.chef.io/), [Symonds & Son](http://symondsandson.com/), and [Orion](https://www.orionlabs.co/).
The Poise test server infrastructure is sponsored by [Rackspace](https://rackspace.com/).
## License
Copyright 2015, Noah Kantrowitz
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

View File

@ -0,0 +1,24 @@
#
# Copyright 2015, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
module PoiseApplicationRuby
autoload :AppMixin, 'poise_application_ruby/app_mixin'
autoload :Error, 'poise_application_ruby/error'
autoload :Resources, 'poise_application_ruby/resources'
autoload :ServiceMixin, 'poise_application_ruby/service_mixin'
autoload :VERSION, 'poise_application_ruby/version'
end

View File

@ -0,0 +1,92 @@
#
# Copyright 2015, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require 'poise/backports'
require 'poise/utils'
require 'poise_application/app_mixin'
require 'poise_ruby/ruby_command_mixin'
module PoiseApplicationRuby
# A helper mixin for Ruby application resources and providers.
#
# @since 4.0.0
module AppMixin
include Poise::Utils::ResourceProviderMixin
# A helper mixin for Ruby application resources.
module Resource
include PoiseApplication::AppMixin::Resource
include PoiseRuby::RubyCommandMixin::Resource
# @!attribute parent_ruby
# Override the #parent_ruby from RubyCommandMixin to grok the
# application level parent as a default value.
# @return [PoiseRuby::Resources::RubyRuntime::Resource, nil]
parent_attribute(:ruby, type: :ruby_runtime, optional: true, default: lazy { app_state_ruby.equal?(self) ? nil : app_state_ruby })
# @!attribute parent_bundle
# Parent bundle install context.
# @return [PoiseRuby::Resources::BundleInstall::Resource, nil]
parent_attribute(:bundle, type: :ruby_runtime, optional: true, auto: false, default: lazy { app_state_bundle.equal?(self) ? nil : app_state_bundle })
# @attribute app_state_ruby
# The application-level Ruby parent.
# @return [PoiseRuby::Resources::RubyRuntime::Resource, nil]
def app_state_ruby(ruby=Poise::NOT_PASSED)
unless ruby == Poise::NOT_PASSED
app_state[:ruby] = ruby
end
app_state[:ruby]
end
# @attribute app_state_bundle
# The application-level Bundle parent.
# @return [PoiseRuby::Resources::BundleInstall::Resource, nil]
def app_state_bundle(bundle=Poise::NOT_PASSED)
unless bundle == Poise::NOT_PASSED
app_state[:bundle] = bundle
end
app_state[:bundle]
end
# A merged hash of environment variables for both the application state
# and parent ruby.
#
# @return [Hash<String, String>]
def app_state_environment_ruby
env = app_state_environment
env = env.merge(parent_ruby.ruby_environment) if parent_ruby
env['BUNDLE_GEMFILE'] = parent_bundle.gemfile_path if parent_bundle
env
end
# Update ruby_from_parent to transfer {#parent_bundle} too.
#
# @param resource [Chef::Resource] Resource to inherit from.
# @return [void]
def ruby_from_parent(resource)
super
parent_bundle(resource.parent_bundle) if resource.parent_bundle
end
end
# A helper mixin for Ruby application providers.
module Provider
include PoiseApplication::AppMixin::Provider
end
end
end

View File

@ -0,0 +1,17 @@
#
# Copyright 2015, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require 'poise_application_ruby/resources'

View File

@ -0,0 +1,25 @@
#
# Copyright 2015, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require 'poise_application/error'
module PoiseApplicationRuby
# Base exception class for poise-application-ruby errors.
#
# @since 4.0.0
class Error < PoiseApplication::Error
end
end

View File

@ -0,0 +1,24 @@
#
# Copyright 2015, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require 'poise_application_ruby/resources/bundle_install'
require 'poise_application_ruby/resources/rackup'
require 'poise_application_ruby/resources/rails'
require 'poise_application_ruby/resources/ruby'
require 'poise_application_ruby/resources/ruby_execute'
require 'poise_application_ruby/resources/ruby_gem'
require 'poise_application_ruby/resources/thin'
require 'poise_application_ruby/resources/unicorn'

View File

@ -0,0 +1,54 @@
#
# Copyright 2015, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require 'poise_ruby/resources/bundle_install'
require 'poise_application_ruby/app_mixin'
module PoiseApplicationRuby
module Resources
# (see BundleInstall::Resource)
# @since 4.0.0
module BundleInstall
# An `application_bundle_install` resource to install a
# [Bundler](http://bundler.io/) Gemfile in a web application.
#
# @note
# This resource is not idempotent itself, it will always run `bundle
# install`.
# @example
# application '/srv/my_app' do
# bundle_install
# end
class Resource < PoiseRuby::Resources::BundleInstall::Resource
include PoiseApplicationRuby::AppMixin
provides(:application_bundle_install)
subclass_providers!
# Set this resource as the app_state's parent bundle.
#
# @api private
def after_created
super.tap do |val|
app_state_bundle(self)
end
end
end
end
end
end

View File

@ -0,0 +1,70 @@
#
# Copyright 2015, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require 'chef/provider'
require 'chef/resource'
require 'poise_application_ruby/service_mixin'
module PoiseApplicationRuby
module Resources
# (see Rackup::Resource)
# @since 4.0.0
module Rackup
class Resource < Chef::Resource
include PoiseApplicationRuby::ServiceMixin
provides(:application_rackup)
# @!attribute port
# TCP port to listen on. Defaults to 80.
# @return [String, Integer]
attribute(:port, kind_of: [String, Integer], default: 80)
end
class Provider < Chef::Provider
include PoiseApplicationRuby::ServiceMixin
provides(:application_rackup)
private
# Find the path to the config.ru. If the resource path was to a
# directory, apparent /config.ru.
#
# @return [String]
def configru_path
@configru_path ||= if ::File.directory?(new_resource.path)
::File.join(new_resource.path, 'config.ru')
else
new_resource.path
end
end
# Set up service options for rackup.
#
# @param resource [PoiseService::Resource] Service resource.
# @return [void]
def service_options(resource)
super
resource.ruby_command("rackup --port #{new_resource.port}")
resource.directory(::File.dirname(configru_path))
# Older versions of rackup ignore all signals.
resource.stop_signal('KILL')
end
end
end
end
end

View File

@ -0,0 +1,260 @@
#
# Copyright 2015, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require 'chef/provider'
require 'chef/resource'
require 'poise_application_ruby/app_mixin'
module PoiseApplicationRuby
module Resources
# (see Rails::Resource)
module Rails
# An `application_rails` resource to configure Ruby on Rails applications.
#
# @since 4.0.0
# @provides application_rails
# @action deploy
# @example
# application '/srv/myapp' do
# git '...'
# bundle_install
# rails do
# database do
# host node['rails_host']
# end
# end
# unicorn do
# port 8080
# end
# end
class Resource < Chef::Resource
include PoiseApplicationRuby::AppMixin
provides(:application_rails)
actions(:deploy)
# @!attribute database
# Option collector attribute for Rails database configuration.
# @return [Hash]
# @example Setting via block
# database do
# adapter 'postgresql'
# database 'blog'
# end
# @example Setting via URL
# database 'postgresql://localhost/blog'
attribute(:database, option_collector: true, parser: :parse_database_url)
# @!attribute database_config
# Template content attribute for the contents of database.yml.
# @todo Redo this doc to cover the actual attributes created.
# @return [Poise::Helpers::TemplateContent]
attribute(:database_config, template: true, default_source: 'database.yml.erb', default_options: lazy { default_database_options })
# @!attribute migrate
# Run database migrations. This is a bad idea for real apps. Please
# do not use it.
# @return [Boolean]
attribute(:migrate, equal_to: [true, false], default: false)
# @!attribute precompile_assets
# Set to true to run rake assets:precompile. By default will try to
# auto-detect if Sprockets is in use by looking at config/initializers.
# @see #default_precompile_assets
# @return [Boolean]
attribute(:precompile_assets, equal_to: [true, false], default: lazy { default_precompile_assets })
# @!attribute rails_env
# Rails environment name. Defaults to the Chef environment name or
# `production` if none is set.
# @see #default_rails_env
# @return [String]
attribute(:rails_env, kind_of: String, default: lazy { default_rails_env })
# @!attribute secret_token
# Secret token for Rails session verification and other purposes. On
# Rails 4.2 this will be used for secret_key_base. If not set, no
# secrets configuration is written.
# @return [String]
attribute(:secret_token, kind_of: [String, FalseClass])
# @!attribute secrets_config
# Template content attribute for the contents of secrets.yml. Only
# used when secrets_mode is :yaml.
# @todo Redo this doc to cover the actual attributes created.
# @return [Poise::Helpers::TemplateContent]
attribute(:secrets_config, template: true, default_source: 'secrets.yml.erb', default_options: lazy { default_secrets_options })
# @!attribute secrets_mode
# Secrets configuration mode. Set to `:yaml` to generate a Rails 4.2
# secrets.yml. Set to `:initializer` to update
# `config/initializers/secret_token.rb`. If unspecified this is
# auto-detected based on what files exist.
# @return [Symbol]
attribute(:secrets_mode, equal_to: [:yaml, :initializer], default: lazy { default_secrets_mode })
private
# Check if we should run the precompile by default. Looks for the
# assets initializer because that is not present with --skip-sprockets.
#
# @return [Boolean]
def default_precompile_assets
::File.exists?(::File.join(path, 'config', 'initializers', 'assets.rb'))
end
# Check the default environment name.
#
# @return [String]
def default_rails_env
node.chef_environment == '_default' ? 'production' : node.chef_environment
end
# Format a single URL for the database.yml
#
# @return [Hash]
def parse_database_url(url)
{'url' => url}
end
# Default template variables for the database.yml.
#
# @return [Hash<Symbol, Object>]
def default_database_options
db_config = {'encoding' => 'utf8', 'reconnect' => true, 'pool' => 5}.merge(database)
{
config: {
rails_env => db_config
},
}
end
# Check which secrets configuration mode is in use based on files.
#
# @return [Symbol]
def default_secrets_mode
::File.exists?(::File.join(path, 'config', 'initializers', 'secret_token.rb')) ? :initialize : :yaml
end
# Default template variables for the secrets.yml.
#
# @return [Hash<Symbol, Object>]
def default_secrets_options
{
config: {
rails_env => {
'secret_key_base' => secret_token,
}
},
}
end
end
# Provider for `application_rails`.
#
# @since 4.0.0
# @see Resource
# @provides application_rails
class Provider < Chef::Provider
include PoiseApplicationRuby::AppMixin
provides(:application_rails)
# `deploy` action for `application_rails`. Ensure all configuration
# files are created and other deploy tasks resolved.
#
# @return [void]
def action_deploy
set_state
notifying_block do
write_database_yml unless new_resource.database.empty?
write_secrets_config if new_resource.secret_token
precompile_assets if new_resource.precompile_assets
run_migrations if new_resource.migrate
end
end
private
# Set app_state variables for future services et al.
def set_state
new_resource.app_state_environment[:RAILS_ENV] = new_resource.rails_env
new_resource.app_state_environment[:DATABASE_URL] = new_resource.database['url'] if new_resource.database['url']
end
# Create a database.yml config file.
def write_database_yml
file ::File.join(new_resource.path, 'config', 'database.yml') do
user new_resource.parent.owner
group new_resource.parent.group
mode '640'
content new_resource.database_config_content
end
end
# Dispatch to the correct config writer based on the mode.
def write_secrets_config
case new_resource.secrets_mode
when :yaml
write_secrets_yml
when :initializer
write_secrets_initializer
end
end
# Write a Rails 4.2-style secrets.yml.
def write_secrets_yml
file ::File.join(new_resource.path, 'config', 'secrets.yml') do
user new_resource.parent.owner
group new_resource.parent.group
mode '640'
content new_resource.secrets_config_content
end
end
# In-place update a config/initializers/secret_token.rb file.
def write_secrets_initializer
# @todo Implement initalizer-style secret support.
raise NotImplementedError.new('Sorry, intializer-style secrets loading is not yet supported.')
end
# Precompile assets using the rake task.
def precompile_assets
# Currently this will always run so the resource will always update :-/
# Better fix would be to shell_out! and parse the output?
ruby_execute 'rake assets:precompile' do
command %w{rake assets:precompile}
user new_resource.parent.owner
group new_resource.parent.group
cwd new_resource.parent.path
environment new_resource.app_state_environment
ruby_from_parent new_resource
parent_bundle new_resource.parent_bundle if new_resource.parent_bundle
end
end
# Run database migrations using the rake task.
def run_migrations
# Currently this will always run so the resource will always update :-/
# Better fix would be to shell_out! and parse the output?
ruby_execute 'rake db:migrate' do
command %w{rake db:migrate}
user new_resource.parent.owner
group new_resource.parent.group
cwd new_resource.parent.path
environment new_resource.app_state_environment
ruby_from_parent new_resource
parent_bundle new_resource.parent_bundle if new_resource.parent_bundle
end
end
end
end
end
end

View File

@ -0,0 +1,63 @@
#
# Copyright 2015, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require 'poise_ruby/resources/ruby_runtime'
require 'poise_application_ruby/app_mixin'
module PoiseApplicationRuby
module Resources
# (see Ruby::Resource)
# @since 4.0.0
module Ruby
# An `application_ruby` resource to manage Ruby runtimes
# inside an Application cookbook deployment.
#
# @provides application_ruby
# @provides application_ruby_runtime
# @action install
# @action uninstall
# @example
# application '/app' do
# ruby '2'
# end
class Resource < PoiseRuby::Resources::RubyRuntime::Resource
include PoiseApplicationRuby::AppMixin
provides(:application_ruby)
provides(:application_ruby_runtime)
container_default(false)
subclass_providers!
# Rebind the parent class #gem_binary instead of the one from
# RubyCommandMixin (by way of AppMixin)
def gem_binary(*args, &block)
self.class.superclass.instance_method(:gem_binary).bind(self).call(*args, &block)
end
# Set this resource as the app_state's parent ruby.
#
# @api private
def after_created
super.tap do |val|
app_state_ruby(self)
end
end
end
end
end
end

View File

@ -0,0 +1,89 @@
#
# Copyright 2015, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require 'poise_ruby/resources/ruby_execute'
require 'poise_application_ruby/app_mixin'
module PoiseApplicationRuby
module Resources
# (see RubyExecute::Resource)
# @since 4.0.0
module RubyExecute
# An `application_ruby_execute` resource to run Ruby commands inside an
# Application cookbook deployment.
#
# @provides application_ruby_execute
# @action run
# @example
# application '/srv/myapp' do
# ruby_execute 'rake build'
# end
class Resource < PoiseRuby::Resources::RubyExecute::Resource
include PoiseApplicationRuby::AppMixin
provides(:application_ruby_execute)
def initialize(*args)
super
# Clear some instance variables so my defaults work.
remove_instance_variable(:@cwd)
remove_instance_variable(:@group)
remove_instance_variable(:@user)
end
# #!attribute cwd
# Override the default directory to be the app path if unspecified.
# @return [String]
attribute(:cwd, kind_of: [String, NilClass, FalseClass], default: lazy { parent && parent.path })
# #!attribute group
# Override the default group to be the app group if unspecified.
# @return [String, Integer]
attribute(:group, kind_of: [String, Integer, NilClass, FalseClass], default: lazy { parent && parent.group })
# #!attribute user
# Override the default user to be the app owner if unspecified.
# @return [String, Integer]
attribute(:user, kind_of: [String, Integer, NilClass, FalseClass], default: lazy { parent && parent.owner })
end
# The default provider for `application_ruby_execute`.
#
# @see Resource
# @provides application_ruby_execute
class Provider < PoiseRuby::Resources::RubyExecute::Provider
provides(:application_ruby_execute)
private
# Override environment to add the application envivonrment instead.
#
# @return [Hash]
def environment
super.tap do |environment|
# Don't use the app_state_environment_ruby because we already have
# those values in place.
environment.update(new_resource.app_state_environment)
# Re-apply the resource environment for correct ordering.
environment.update(new_resource.environment) if new_resource.environment
end
end
end
end
end
end

View File

@ -0,0 +1,46 @@
#
# Copyright 2015, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require 'poise_ruby/resources/ruby_gem'
require 'poise_application_ruby/app_mixin'
module PoiseApplicationRuby
module Resources
# (see RubyGem::Resource)
# @since 4.0.0
module RubyGem
# An `application_ruby_gem` resource to install Ruby gems inside an
# Application cookbook deployment.
#
# @provides application_ruby_gem
# @action install
# @action upgrade
# @action remove
# @example
# application '/srv/myapp' do
# ruby_gem 'rack'
# end
class Resource < PoiseRuby::Resources::RubyGem::Resource
include PoiseApplicationRuby::AppMixin
provides(:application_ruby_gem)
subclass_providers!
end
end
end
end

View File

@ -0,0 +1,64 @@
#
# Copyright 2015, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require 'chef/provider'
require 'chef/resource'
require 'poise_application_ruby/service_mixin'
module PoiseApplicationRuby
module Resources
# (see Thin::Resource)
# @since 4.0.0
module Thin
class Resource < Chef::Resource
include PoiseApplicationRuby::ServiceMixin
provides(:application_thin)
attribute(:port, kind_of: [String, Integer], default: 80)
attribute(:config_path, kind_of: String)
end
class Provider < Chef::Provider
include PoiseApplicationRuby::ServiceMixin
provides(:application_thin)
private
# Find the path to the config.ru. If the resource path was to a
# directory, apparent /config.ru.
#
# @return [String]
def configru_path
@configru_path ||= if ::File.directory?(new_resource.path)
::File.join(new_resource.path, 'config.ru')
else
new_resource.path
end
end
# (see PoiseApplication::ServiceMixin#service_options)
def service_options(resource)
super
cmd = "thin --rackup #{configru_path} --port #{new_resource.port}"
cmd << " --config #{::File.expand_path(new_resource.config_path, new_resource.path)}" if new_resource.config_path
resource.ruby_command(cmd)
end
end
end
end
end

View File

@ -0,0 +1,87 @@
#
# Copyright 2015, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require 'chef/provider'
require 'chef/resource'
require 'poise_application_ruby/service_mixin'
module PoiseApplicationRuby
module Resources
# (see Unicorn::Resource)
# @since 4.0.0
module Unicorn
# An `application_unicorn` resource to manage a unicorn web application
# server.
#
# @since 4.0.0
# @provides application_unicorn
# @action enable
# @action disable
# @action start
# @action stop
# @action restart
# @action reload
# @example
# application '/srv/myapp' do
# git '...'
# bundle_install
# unicorn do
# port 8080
# end
# end
class Resource < Chef::Resource
include PoiseApplicationRuby::ServiceMixin
provides(:application_unicorn)
# @!attribute port
# Port to bind to.
attribute(:port, kind_of: [String, Integer], default: 80)
end
# Provider for `application_unicorn`.
#
# @since 4.0.0
# @see Resource
# @provides application_unicorn
class Provider < Chef::Provider
include PoiseApplicationRuby::ServiceMixin
provides(:application_unicorn)
private
# Find the path to the config.ru. If the resource path was to a
# directory, apparent /config.ru.
#
# @return [String]
def configru_path
@configru_path ||= if ::File.directory?(new_resource.path)
::File.join(new_resource.path, 'config.ru')
else
new_resource.path
end
end
# Set service resource options.
def service_options(resource)
super
resource.ruby_command("unicorn --port #{new_resource.port} #{configru_path}")
end
end
end
end
end

View File

@ -0,0 +1,66 @@
#
# Copyright 2015, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require 'poise/utils'
require 'poise_application/service_mixin'
require 'poise_languages/utils'
require 'poise_ruby/bundler_mixin'
require 'poise_application_ruby/app_mixin'
module PoiseApplicationRuby
# A helper mixin for Ruby service resources and providers.
#
# @since 4.0.0
module ServiceMixin
include Poise::Utils::ResourceProviderMixin
# A helper mixin for Ruby service resources.
module Resource
include PoiseApplication::ServiceMixin::Resource
include PoiseApplicationRuby::AppMixin::Resource
end
# A helper mixin for Ruby service providers.
module Provider
include PoiseApplication::ServiceMixin::Provider
include PoiseApplicationRuby::AppMixin::Provider
include PoiseRuby::BundlerMixin
# Set up the service for running Ruby stuff.
def service_options(resource)
super
# Closure scoping for #ruby_command below.
self_ = self
# Create a new singleton method that fills in Python for you.
resource.define_singleton_method(:ruby_command) do |val|
path = self_.new_resource.app_state_environment_ruby['PATH']
cmd = if self_.new_resource.parent_bundle
bundle_exec_command(val, path: path)
else
"#{self_.new_resource.ruby} #{PoiseLanguages::Utils.absolute_command(val, path: path)}"
end
resource.command(cmd)
end
# Include env vars as needed.
resource.environment.update(new_resource.parent_ruby.ruby_environment) if new_resource.parent_ruby
resource.environment['BUNDLE_GEMFILE'] = new_resource.parent_bundle.gemfile_path if new_resource.parent_bundle
end
end
end
end

View File

@ -0,0 +1,19 @@
#
# Copyright 2015, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
module PoiseApplicationRuby
VERSION = '4.0.1'
end

View File

@ -0,0 +1,19 @@
#
# Copyright 2015, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
raise 'Halite is not compatible with no_lazy_load false, please set no_lazy_load true in your Chef configuration file.' unless Chef::Config[:no_lazy_load]
$LOAD_PATH << File.expand_path('../../files/halite_gem', __FILE__)
require "poise_application_ruby/cheftie"

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,3 @@
# Generated by Chef for <%= @new_resource.to_s %>
<%= @config.to_yaml %>

View File

@ -0,0 +1,3 @@
# Generated by Chef for <%= @new_resource.to_s %>
<%= @config.to_yaml %>

View File

@ -0,0 +1,4 @@
~FC007
~FC023
~FC024
~FC048

113
cookbooks/dmg/CHANGELOG.md Normal file
View File

@ -0,0 +1,113 @@
# dmg Cookbook CHANGELOG
This file is used to list changes made in each version of the dmg cookbook.
## 3.1.0 (2017-01-18)
- Fixed pkg,mpkg installation when it was using mounted app name while it was actually mounted under different name for some applications
- Cookstyle fixes
## 3.0.0 (2016-09-06)
- Add chef_version metadata
- Run the specs against a mock of OS X
- Testing updates
- Require Chef 12+
## v2.4.0 (2016-04-26)
- Added support for local .dmg files with the file property. See the readme for details
- Resolved all rubocop warnings
## v2.3.0 (2015-10-20)
- Add new headers property to the LWRP for custom http headers. See the readme for more information
- Removed pivotal tracker example in the readme
- Added travis and cookbook version badges to the readme
- Added a .foodcritic file to exclude rules
- Updated chefignore and .gitignore files
- Updated platforms in Test Kitchen
- Added standard Rubocop file
- Updated Travis to test using ChefDK for the latest deps
- Added a Berksfile
- Updated contributing and testing docs
- Updated Gemfile with the latest testing deps
- Added maintainers.md and maintainers.toml
- Added rakefile for simplified testing
- Added source_url and issues_url metadata
- Added basic converge chefspec
## v2.2.2 (2014-11-12)
- # 23, add chefspec matchers
## v2.2.0 (2014-02-25)
- [COOK-4285] Accept long EULAs
## v2.1.4 (2014-01-26)
- [COOK-4157] - dmg_package LWRP broken due to "puts" instead of "system"
- [COOK-4065] - dmg cookbook outputs the name of packages when checking if they are installed
## v2.1.2
Cleaning up merge errors
## v2.1.0
### Bug
- **[COOK-3946](https://tickets.chef.io/browse/COOK-3946)** - Syntax error in resources/package.rb
- **[COOK-2672](https://tickets.chef.io/browse/COOK-2672)** - EULA for package is displayed instead accepted
## v2.0.8
Adding a Chef 10 compatibility check in provider
## v2.0.6
# BUG
- [COOK-3302] - Sometimes hdiutil detach fails due to cfprefsd running in background
# IMPROVEMENT
- Adding foodcritic and rubocop to .travis.yml
## v2.0.4
### Bug
- **[COOK-3331](https://tickets.chef.io/browse/COOK-3331)** - Fix an issue where `dmg_package` with no source raises an exception
## v2.0.2
### Bug
- **[COOK-3578](https://tickets.chef.io/browse/COOK-3578)** - Support `package_id`s with spaces
- **[COOK-3302](https://tickets.chef.io/browse/COOK-3302)** - Fix an issue where `hdiutil detach` fails due to `cfprefsd` running in the background
## v2.0.0
### Bug
- **[COOK-3389](https://tickets.chef.io/browse/COOK-3389)** - Use `rsync` instead of `cp` (potentially a breaking change on some systems)
## v1.1.0
- [COOK-1847] - accept owner parameter for installing packages
## v1.0.0
- [COOK-852] - Support "pkg" in addition to "mpkg" package types
## v0.7.0
- [COOK-854] - use `cp -R` instead of `cp -r`
- [COOK-855] - specify a file or directory to check for prior install
## v0.6.0
- option to install software that is an .mpkg inside a .dmg
- ignore failure on chmod in case mode is already set, or is root owned

View File

@ -0,0 +1,2 @@
Please refer to
https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/CONTRIBUTING.MD

View File

@ -0,0 +1,18 @@
<!-- This is a generated file. Please do not edit directly -->
# Maintainers
This file lists how this cookbook project is maintained. When making changes to the system, this
file tells you who needs to review your patch - you need a review from an existing maintainer
for the cookbook to provide a :+1: on your pull request. Additionally, you need
to not receive a veto from a Lieutenant or the Project Lead.
Check out [How Cookbooks are Maintained](https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/CONTRIBUTING.MD)
for details on the process and how to become a maintainer or the project lead.
# Project Maintainer
* [Tim Smith](https://github.com/tas50)
# Maintainers
* [Jennifer Davis](https://github.com/sigje)
* [Tim Smith](https://github.com/tas50)
* [Thom May](https://github.com/thommay)

146
cookbooks/dmg/README.md Normal file
View File

@ -0,0 +1,146 @@
# dmg Cookbook
[![Build Status](https://travis-ci.org/chef-cookbooks/dmg.svg?branch=master)](https://travis-ci.org/chef-cookbooks/dmg) [![Cookbook Version](https://img.shields.io/cookbook/v/dmg.svg)](https://supermarket.chef.io/cookbooks/dmg)
Resource to install OS X applications (.app) from dmg files.
## Requirements
### Platforms
- Mac OS X
### Chef
- Chef 12.1+
### Cookbooks
- none
## Resources/Providers
### dmg_package
This resource will install a DMG "Package". It will retrieve the DMG from a remote URL, mount it using OS X's `hdid`, copy the application (.app directory) to the specified destination (/Applications), and detach the image using `hdiutil`. The dmg file will be stored in the `Chef::Config[:file_cache_path]`. If you want to install an application that has already been downloaded (not using the `source` parameter), copy it to the appropriate location. You can find out what directory this is with the following command on the node to run chef:
```bash
knife exec -E 'p Chef::Config[:file_cache_path]' -c /etc/chef/client.rb
```
Optionally, the LWRP can install an "mpkg" or "pkg" package using installer(8).
#### Actions
- :install - Installs the application.
#### Parameter attributes:
- `app` - This is the name of the application used by default for the /Volumes directory and the .app directory copied to /Applications.
- `source` - remote URL for the dmg to download if specified. Default is nil.
- `file` - local dmg full file path. Default is nil.
- `owner` - owner that should own the package installation.
- `destination` - directory to copy the .app into. Default is /Applications.
- `checksum` - sha256 checksum of the dmg to download. Default is nil.
- `type` - type of package, "app", "pkg" or "mpkg". Default is "app". When using "pkg" or "mpkg", the destination must be /Applications.
- `volumes_dir` - Directory under /Volumes where the dmg is mounted. Not all dmgs are mounted into a /Volumes location matching the name of the dmg. If not specified, this will use the name attribute.
- `package_id` - Package id registered with pkgutil when a pkg or mpkg is installed
- `dmg_name` - Specify the name of the dmg if it is not the same as `app`, or if the name has spaces.
- `dmg_passphrase` - Specify a passphrase to use to unencrypt the dmg while mounting.
- `accept_eula` - Specify whether to accept the EULA. Certain dmgs require acceptance of EULA before mounting. Can be true or false, defaults to false.
- `headers` - Allows custom HTTP headers (like cookies) to be set on the remote_file resource.
#### Examples
Install `/Applications/Tunnelblick.app` from the primary download site.
```ruby
dmg_package 'Tunnelblick' do
source 'http://tunnelblick.googlecode.com/files/Tunnelblick_3.1.2.dmg'
checksum 'a3fae60b6833175f32df20c90cd3a3603a'
action :install
end
```
Install Google Chrome. Uses the `dmg_name` because the application name has spaces. Installs in `/Applications/Google Chrome.app`.
```ruby
dmg_package 'Google Chrome' do
dmg_name 'googlechrome'
source 'https://dl-ssl.google.com/chrome/mac/stable/GGRM/googlechrome.dmg'
checksum '7daa2dc5c46d9bfb14f1d7ff4b33884325e5e63e694810adc58f14795165c91a'
action :install
end
```
Install Dropbox. Uses `volumes_dir` because the mounted directory is different than the name of the application directory. Installs in `/Applications/Dropbox.app`.
```ruby
dmg_package 'Dropbox' do
volumes_dir 'Dropbox Installer'
source 'http://www.dropbox.com/download?plat=mac'
checksum 'b4ea620ca22b0517b75753283ceb82326aca8bc3c86212fbf725de6446a96a13'
action :install
end
```
Install MacIrssi to `~/Applications` from the local file downloaded to the cache path into an Applications directory in the current user's home directory. Chef should run as a non-root user for this.
```ruby
directory "#{ENV['HOME']}/Applications"
dmg_package 'MacIrssi' do
destination "#{ENV['HOME']}/Applications"
action :install
end
```
Install Virtualbox to `/Applications` from the .mpkg:
```ruby
dmg_package 'Virtualbox' do
source 'http://dlc.sun.com.edgesuite.net/virtualbox/4.0.8/VirtualBox-4.0.8-71778-OSX.dmg'
type 'mpkg'
end
```
Install pgAdmin to `/Applications` and automatically accept the EULA:
```ruby
dmg_package 'pgAdmin3' do
source 'http://wwwmaster.postgresql.org/redir/198/h/pgadmin3/release/v1.12.3/osx/pgadmin3-1.12.3.dmg'
checksum '9435f79d5b52d0febeddfad392adf82db9df159196f496c1ab139a6957242ce9'
accept_eula true
end
```
Install Silverlight, with idempotence check based on pkgutil:
```ruby
dmg_package 'Silerlight' do
source 'http://silverlight.dlservice.microsoft.com/download/D/C/2/DC2D5838-9138-4D25-AA92-52F61F7C51E6/runtime/Silverlight.dmg'
type 'pkg'
checksum '6d4a0ad4552d9815531463eb3f467fb8cf4bffcc'
package_id 'com.microsoft.installSilverlightPlugin'
end
```
## License & Authors
**Author:** Cookbook Engineering Team ([cookbooks@chef.io](mailto:cookbooks@chef.io))
**Copyright:** 2011-2015, Chef Software, Inc.
```
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
```

View File

@ -0,0 +1,20 @@
#
# Cookbook:: dmg
# Attributes:: default
#
# Copyright:: 2011-2016, Chef Software, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
default['dmg']['base_dir'] = '/Applications'
default['dmg']['cache_dir'] = Chef::Config[:file_cache_path]

View File

@ -1,5 +1,8 @@
#
# Copyright 2012, Opscode, Inc.
# Cookbook:: dmg
# Library:: matchers
#
# Copyright:: 2014-2016, Fletcher Nichol <fnichol@nichol.ca>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@ -14,14 +17,8 @@
# limitations under the License.
#
require File.expand_path('../support/helpers', __FILE__)
describe 'postgresql::default' do
include Helpers::Postgresql
it 'installs the postgresql client packages' do
node['postgresql']['client']['packages'].each do |pkg|
package(pkg).must_be_installed
end
if defined?(ChefSpec)
def install_dmg_package(app)
ChefSpec::Matchers::ResourceMatcher.new(:dmg_package, :install, app)
end
end

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,95 @@
#
# Cookbook:: dmg
# Provider:: package
#
# Copyright:: 2011-2016, Chef Software, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
include Chef::Mixin::ShellOut
use_inline_resources if defined?(use_inline_resources)
def load_current_resource
@dmgpkg = Chef::Resource::DmgPackage.new(new_resource.name)
@dmgpkg.app(new_resource.app)
Chef::Log.debug("Checking for application #{new_resource.app}")
@dmgpkg.installed(installed?)
end
action :install do
unless @dmgpkg.installed
volumes_dir = new_resource.volumes_dir ? new_resource.volumes_dir : new_resource.app
dmg_name = new_resource.dmg_name ? new_resource.dmg_name : new_resource.app
dmg_file = if new_resource.file.nil?
"#{Chef::Config[:file_cache_path]}/#{dmg_name}.dmg"
else
new_resource.file
end
remote_file "#{dmg_file} - #{@dmgpkg.name}" do
path dmg_file
source new_resource.source
headers new_resource.headers if new_resource.headers
checksum new_resource.checksum if new_resource.checksum
end if new_resource.source
passphrase_cmd = new_resource.dmg_passphrase ? "-passphrase #{new_resource.dmg_passphrase}" : ''
ruby_block "attach #{dmg_file}" do
block do
cmd = shell_out("hdiutil imageinfo #{passphrase_cmd} '#{dmg_file}' | grep -q 'Software License Agreement: true'")
software_license_agreement = cmd.exitstatus.zero?
raise "Requires EULA Acceptance; add 'accept_eula true' to package resource" if software_license_agreement && !new_resource.accept_eula
accept_eula_cmd = new_resource.accept_eula ? 'echo Y | PAGER=true' : ''
shell_out!("#{accept_eula_cmd} hdiutil attach #{passphrase_cmd} '#{dmg_file}' -mountpoint '/Volumes/#{volumes_dir}' -quiet")
end
not_if "hdiutil info #{passphrase_cmd} | grep -q 'image-path.*#{dmg_file}'"
end
case new_resource.type
when 'app'
execute "rsync --force --recursive --links --perms --executability --owner --group --times '/Volumes/#{volumes_dir}/#{new_resource.app}.app' '#{new_resource.destination}'" do
user new_resource.owner if new_resource.owner
end
file "#{new_resource.destination}/#{new_resource.app}.app/Contents/MacOS/#{new_resource.app}" do
mode '755'
ignore_failure true
end
when 'mpkg', 'pkg'
execute "installation_file=$(ls '/Volumes/#{volumes_dir}' | grep '.#{new_resource.type}$') && sudo installer -pkg \"/Volumes/#{volumes_dir}/$installation_file\" -target /" do
# Prevent cfprefsd from holding up hdiutil detach for certain disk images
environment('__CFPREFERENCES_AVOID_DAEMON' => '1') if Gem::Version.new(node['platform_version']) >= Gem::Version.new('10.8')
end
end
execute "hdiutil detach '/Volumes/#{volumes_dir}' || hdiutil detach '/Volumes/#{volumes_dir}' -force"
end
end
private
def installed?
if ::File.directory?("#{new_resource.destination}/#{new_resource.app}.app")
Chef::Log.info "Already installed; to upgrade, remove \"#{new_resource.destination}/#{new_resource.app}.app\""
true
elsif shell_out("pkgutil --pkgs='#{new_resource.package_id}'").exitstatus.zero?
Chef::Log.info "Already installed; to upgrade, try \"sudo pkgutil --forget '#{new_resource.package_id}'\""
true
else
false
end
end

View File

@ -1,8 +1,8 @@
#
# Cookbook Name:: application
# Cookbook Name:: dmg
# Recipe:: default
#
# Copyright:: 2012, Opscode, Inc <legal@opscode.com>
# Copyright 2011-2016, Chef Software, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@ -16,4 +16,3 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Empty placeholder recipe, use the LWRPs, see README.md.

View File

@ -0,0 +1,39 @@
# Encoding: utf-8
# Cookbook:: dmg
# Resource:: package
#
# Copyright:: 2011-2016, Joshua Timberman
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
actions :install
attribute :app, kind_of: String, name_attribute: true
attribute :source, kind_of: String, default: nil
attribute :file, kind_of: String, default: nil
attribute :owner, kind_of: String, default: nil
attribute :destination, kind_of: String, default: '/Applications'
attribute :checksum, kind_of: String, default: nil
attribute :volumes_dir, kind_of: String, default: nil
attribute :dmg_name, kind_of: String, default: nil
attribute :type, kind_of: String, default: 'app'
attribute :installed, kind_of: [TrueClass, FalseClass], default: false
attribute :package_id, kind_of: String, default: nil
attribute :dmg_passphrase, kind_of: String, default: nil
attribute :accept_eula, kind_of: [TrueClass, FalseClass], default: false
attribute :headers, kind_of: Hash, default: nil
def initialize(name, run_context = nil)
super
@action = :install
end

View File

@ -0,0 +1 @@
~FC016

257
cookbooks/git/CHANGELOG.md Normal file
View File

@ -0,0 +1,257 @@
# git Cookbook CHANGELOG
This file is used to list changes made in each version of the git cookbook.
## 6.0.0 (2017-02-14)
- Fail on deprecations is now enabled so we're fully Chef 13 compatible
- Define the chefspec matchers properly
- Remove the legacy platform mappings that fail on Chef 13
- Improve the test cookbook / integration tests
- Convert config LWRP to a custom resource and make it fully idempotent
- Require Chef 12.5 or later
## 5.0.2 (2017-01-18)
- Remove arch for the metadata
- Avoid deprecation warning during testing
- respond_to?(:chef_version) for < 12.6 compat
## 5.0.1 (2016-09-15)
- Clarify we require Chef 12.1 or later
## 5.0.0 (2016-09-02)
- Require Chef 12 or later
- Don't depend on the windows cookbook since windows_package is built into Chef 12
- Updates for testing
## v4.6.0 (2016-07-05)
- Added support for compiling git on suse
- Added the ability to pass a new group property to the config provider
- Documented the git_config provider
- Added the tar package on RHEL/Fedora for source installs as some minimal installs lack this package
- Added suse, opensuse, and opensuseleap as supported platforms in the metadata
- Switched to inspec for testing
- Switched to cookstyle for Ruby linting
- Added Travis integration testing of Debian 7/8
## v4.5.0 (2016-04-28)
- Update git versions to 2.8.1
## v4.4.1 (2016-03-31)
- PR #95 support 32 bit and 64 bit installs on windows @smurawski
## v4.4.0 (2016-03-23)
- PR #93 bump to latest git @ksubrama
## v4.3.7 (2016-02-03)
- PR #90 port node[git][server][export_all] to true/false @scalp42
- PR #89 make attributes more wrapper friendly @scalp42
- Update testing deps + rubocop fixes
- README fix @zverulacis
## v4.3.6 (2016-01-25)
- Windows fixes
## v4.3.5 (2015-12-15)
- Fixed installation on Windows nodes
- Removed the last of the Chef 10 compatibility code
- Added up to date contributing and testing docs
- Updated test deps in the Gemfile
- Removed test kitchen digital ocean config
- Test with kitchen-docker in Travis CI
- Removed uncessary windows cookbook entry from the Berksfile
- Added the chef standard rubocop.yml file and resolved all warnings
- Added chefignore file
- Removed bin dir
- Added maintainers.md and maintainers.toml files
- Added travis and supermarket version badges to the readme
## v4.3.4 (2015-09-06)
- Fixing package_id on OSX
- Adding 2.5.1 data for Windows
## v4.3.3 (2015-07-27)
- # 76: Use checksum keyname instead of value in source recipe
## v4.3.2 (2015-07-27)
- Fixing up Windows provider (issue #73)
- Supporting changes to source_prefix in source provider (#62)
## v4.3.1 (2015-07-23)
- Fixing up osx_dmg_source_url
## v4.3.0 (2015-07-20)
- Removing references to node attributes from provider code
- Name-spacing of client resource property names
- Addition of windows recipe
- Creation of package recipe
## v4.2.4 (2015-07-19)
- Fixing source provider selection bug from 4.2.3
## v4.2.3 (2015-07-18)
- mac_os_x provider mapping
- various rubocops
## v4.2.2 (2015-04-23)
- Fix up action in Chef::Resource::GitService
- Adding matchers
## v4.2.1 (2015-04-17)
- Fixing Chef 11 support.
- Adding provider mapping file
## v4.2.0 (2015-04-15)
- Converting recipes to resources.
- Keeping recipe interface for backwards compat
## v4.1.0 (2014-12-23)
- Fixing windows package checksums
- Various test coverage additions
## v4.0.2 (2014-04-23)
- [COOK-4482] - Add FreeBSD support for installing git client
## v4.0.0 (2014-03-18)
- [COOK-4397] Only use_inline_resources on Chef 11
## v3.1.0 (2014-03-12)
- [COOK-4392] - Cleanup git_config LWRP
## v3.0.0 (2014-02-28)
[COOK-4387] Add git_config type [COOK-4388] Fix up rubocops [COOK-4390] Add integration tests for default and server suites
## v2.10.0 (2014-02-25)
- [COOK-4146] - wrong dependency in git::source for rhel 6
- [COOK-3947] - Git cookbook adds itself to the path every run
## v2.9.0
Updating to depend on cookbook yum ~> 3 Fixing style to pass rubocop Updating test scaffolding
## v2.8.4
fixing metadata version error. locking to 3.0
## v2.8.1
Locking yum dependency to '< 3'
## v2.8.0
### Bug
- [COOK-3433] - git::server does not correctly set git-daemon's base-path on Debian
## v2.7.0
### Bug
- **[COOK-3624](https://tickets.chef.io/browse/COOK-3624)** - Don't restart `xinetd` on each Chef client run
- **[COOK-3482](https://tickets.chef.io/browse/COOK-3482)** - Force git to add itself to the current process' PATH
### New Feature
- **[COOK-3223](https://tickets.chef.io/browse/COOK-3223)** - Support Omnios and SmartOS package installs
## v2.6.0
### Improvement
- **[COOK-3193](https://tickets.chef.io/browse/COOK-3193)** - Add proper debian packages
## v2.5.2
### Bug
- [COOK-2813]: Fix bad string interpolation in source recipe
## v2.5.0
- Relax runit version constraint (now depend on 1.0+).
## v2.4.0
- [COOK-2734] - update git versions
## v2.3.0
- [COOK-2385] - update git::server for `runit_service` resource support
## v2.2.0
- [COOK-2303] - git::server support for RHEL `platform_family`
## v2.1.4
- [COOK-2110] - initial test-kitchen support (only available in GitHub repository)
- [COOK-2253] - pin runit dependency
## v2.1.2
- [COOK-2043] - install git on ubuntu 12.04 not git-core
## v2.1.0
The repository didn't have pushed commits, and so the following changes from earlier-than-latest versions wouldn't be available on the community site. We're releasing 2.1.0 to correct this.
- [COOK-1943] - Update to git 1.8.0
- [COOK-2020] - Add setup option attributes to Git Windows package install
## v2.0.0
This version uses `platform_family` attribute, making the cookbook incompatible with older versions of Chef/Ohai, hence the major version bump.
- [COOK-1668] - git cookbook fails to run due to bad `platform_family` call
- [COOK-1759] - git::source needs additional package for rhel `platform_family`
## v1.1.2
- [COOK-2020] - Add setup option attributes to Git Windows package install
## v1.1.0
- [COOK-1943] - Update to git 1.8.0
## v1.0.2
- [COOK-1537] - add recipe for source installation
## v1.0.0
- [COOK-1152] - Add support for Mac OS X
- [COOK-1112] - Add support for Windows
## v0.10.0
- [COOK-853] - Git client installation on CentOS
## v0.9.0
- Current public release

View File

@ -0,0 +1,2 @@
Please refer to
https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/CONTRIBUTING.MD

View File

@ -0,0 +1,15 @@
<!-- This is a generated file. Please do not edit directly -->
# Maintainers
This file lists how this cookbook project is maintained. When making changes to the system, this file tells you who needs to review your patch - you need a review from an existing maintainer for the cookbook to provide a :+1: on your pull request. Additionally, you need to not receive a veto from a Lieutenant or the Project Lead.
Check out [How Cookbooks are Maintained](https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/CONTRIBUTING.MD) for details on the process and how to become a maintainer or the project lead.
# Project Maintainer
* [Tim Smith](https://github.com/tas50)
# Maintainers
* [Jennifer Davis](https://github.com/sigje)
* [Tim Smith](https://github.com/tas50)
* [Thom May](https://github.com/thommay)

161
cookbooks/git/README.md Normal file
View File

@ -0,0 +1,161 @@
# Git Cookbook
[![Build Status](https://travis-ci.org/chef-cookbooks/git.svg?branch=master)](https://travis-ci.org/chef-cookbooks/git) [![Cookbook Version](https://img.shields.io/cookbook/v/git.svg)](https://supermarket.chef.io/cookbooks/git)
Installs git_client from package or source. Optionally sets up a git service under xinetd.
## Scope
This cookbook is concerned with the Git SCM utility. It does not address ecosystem tooling or related projects.
## Requirements
### Platforms
The following platforms have been tested with Test Kitchen:
```
|---------------+-------|
| centos-6 | X |
|---------------+-------|
| centos-7 | X |
|---------------+-------|
| fedora | X |
|---------------+-------|
| debian-7 | X |
|---------------+-------|
| debian-8 | X |
|---------------+-------|
| ubuntu-14.04 | X |
|---------------+-------|
| ubuntu-16.04 | X |
|---------------+-------|
| openSUSE 13.2 | X |
|---------------+-------|
| openSUSE Leap | X |
|---------------+-------|
```
### Chef
- Chef 12.5+
### Cookbooks
- depends 'build-essential' - For compiling from source
- depends 'dmg' - For macOS Support
- depends 'yum-epel' - For older RHEL platform_family support
## Usage
Add `git::default`, `git::source` or `git::windows` to your run_list OR add `depends 'git', '~> 4.3'` to your cookbook's metadata.rb. include_recipe one of the recipes from your cookbook OR use the git_client resource directly, the same way you'd use core Chef resources (file, template, directory, package, etc).
## Resources Overview
- `git_client`: Manages a Git client installation on a machine. Acts as a singleton when using the (default) package provider. Source provider available as well.
- `git_service`: Sets up a Git service via xinetd. WARNING: This is insecure and will probably be removed in the future
- `git_config`: Sets up Git configuration on a node.
### git_client
The `git_client` resource manages the installation of a Git client on a machine.
#### Example
```ruby
git_client 'default' do
action :install
end
```
### git_config
The `git_config` resource manages the configuration of Git client on a machine.
#### Example
```ruby
git_config 'url.https://github.com/.insteadOf' do
value 'git://github.com/'
scope 'system'
options '--add'
end
```
#### Properties
Currently, there are distinct sets of resource properties, used by the providers for source, package, macos, and windows.
# used by linux package providers
- `package_name` - Package name to install on Linux machines. Defaults to a calculated value based on platform.
- `package_version` - Defaults to nil.
- `package_action` - Defaults to `:install`
# used by source providers
- `source_prefix` - Defaults to '/usr/local'
- `source_url` - Defaults to a calculated URL based on source_version
- `source_version` - Defaults to 2.7.4
- `source_use_pcre` - configure option for build. Defaults to false
- `source_checksum` - Defaults to a known value for the 2.7.4 source tarball
# used by OSX package providers
- `osx_dmg_app_name` - Defaults to 'git-2.7.1-intel-universal-mavericks'
- `osx_dmg_package_id` - Defaults to 'GitOSX.Installer.git271.git.pkg'
- `osx_dmg_volumes_dir` - Defaults to 'Git 2.7.1 Mavericks Intel Universal'
- `osx_dmg_url` - Defaults to Sourceforge
- `osx_dmg_checksum` - Defaults to the value for 2.7.1
# used by the Windows package providers
- `windows_display_name` - Windows display name
- `windows_package_url` - Defaults to the Internet
- `windows_package_checksum` - Defaults to the value for 2.7.4
## Recipes
This cookbook ships with ready to use, attribute driven recipes that utilize the `git_client` and `git_service` resources. As of cookbook 4.x, they utilize the same attributes layout scheme from the 3.x. Due to some overlap, it is currently impossible to simultaneously install the Git client as a package and from source by using the "manipulate a the node attributes and run a recipe" technique. If you need both, you'll need to utilize the git_client resource in a recipe.
## Attributes
### Windows
- `node['git']['version']` - git version to install
- `node['git']['url']` - URL to git package
- `node['git']['checksum']` - package SHA256 checksum
- `node['git']['display_name']` - `windows_package` resource Display Name (makes the package install idempotent)
### Mac OS X
- `node['git']['osx_dmg']['url']` - URL to git package
- `node['git']['osx_dmg']['checksum']` - package SHA256 checksum
### Linux
- `node['git']['prefix']` - git install directory
- `node['git']['version']` - git version to install
- `node['git']['url']` - URL to git tarball
- `node['git']['checksum']` - tarball SHA256 checksum
- `node['git']['use_pcre']` - if true, builds git with PCRE enabled
## License & Authors
- Author:: Joshua Timberman ([joshua@chef.io](mailto:joshua@chef.io))
- Author:: Sean OMeara ([sean@sean.io](mailto:sean@sean.io))
- Copyright:: 2009-2017, Chef Software, Inc.
```
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
```

View File

@ -0,0 +1,47 @@
#
# Author:: Jamie Winsor (<jamie@vialstudios.com>)
# Cookbook:: git
# Attributes:: default
#
# Copyright:: 2008-2016, Chef Software, Inc.
#
# Licensed under the Apache License, Version 2.0 (the 'License');
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an 'AS IS' BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
case node['platform_family']
when 'windows'
default['git']['version'] = '2.8.1'
if node['kernel']['machine'] == 'x86_64'
default['git']['architecture'] = '64'
default['git']['checksum'] = '5e5283990cc91d1e9bd0858f8411e7d0afb70ce26e23680252fb4869288c7cfb'
else
default['git']['architecture'] = '32'
default['git']['checksum'] = '17418c2e507243b9c98db161e9e5e8041d958b93ce6078530569b8edaec6b8a4'
end
default['git']['url'] = 'https://github.com/git-for-windows/git/releases/download/v%{version}.windows.1/Git-%{version}-%{architecture}-bit.exe'
default['git']['display_name'] = "Git version #{node['git']['version']}"
when 'mac_os_x'
default['git']['osx_dmg']['app_name'] = 'git-2.8.1-intel-universal-mavericks'
default['git']['osx_dmg']['volumes_dir'] = 'Git 2.8.1 Mavericks Intel Universal'
default['git']['osx_dmg']['package_id'] = 'GitOSX.Installer.git281Universal.git.pkg'
default['git']['osx_dmg']['url'] = 'http://sourceforge.net/projects/git-osx-installer/files/git-2.8.1-intel-universal-mavericks.dmg/download'
default['git']['osx_dmg']['checksum'] = 'c2912895a1e2018d9be4c646765d511f7c82e0114275505dbd13d1ac70c62023'
else
default['git']['prefix'] = '/usr/local'
default['git']['version'] = '2.8.1'
default['git']['url'] = 'https://nodeload.github.com/git/git/tar.gz/v%{version}'
default['git']['checksum'] = 'e08503ecaf5d3ac10c40f22871c996a392256c8d038d16f52ebf974cba29ae42'
default['git']['use_pcre'] = false
end
default['git']['server']['base_path'] = '/srv/git'
default['git']['server']['export_all'] = true

View File

@ -0,0 +1,48 @@
module GitCookbook
module Helpers
# linux packages default to distro offering
def parsed_package_name
return new_resource.package_name if new_resource.package_name
return 'git-core' if node['platform'] == 'ubuntu' && node['platform_version'].to_f < 10.10
return 'developer/versioning/git' if node['platform'] == 'omnios'
return 'scmgit' if node['platform'] == 'smartos'
'git'
end
def parsed_package_version
return new_resource.package_version if new_resource.package_version
end
# source
def parsed_source_url
return new_resource.source_url if new_resource.source_url
"https://nodeload.github.com/git/git/tar.gz/v#{new_resource.source_version}"
end
def parsed_source_checksum
return new_resource.source_checksum if new_resource.source_checksum
'8d53703d75890c03e26a915c7af3b7b98d8cfb94382f685a9bcbee1eeaec47b4' # 2.7.4 tarball
end
# windows
def parsed_windows_display_name
return new_resource.windows_display_name if new_resource.windows_display_name
"Git version #{parsed_windows_package_version}"
end
def parsed_windows_package_version
return new_resource.windows_package_version if new_resource.windows_package_version
'2.7.4'
end
def parsed_windows_package_url
return new_resource.windows_package_url if new_resource.windows_package_url
"https://github.com/git-for-windows/git/releases/download/v%#{parsed_windows_package_version}.windows.1/Git-%#{parsed_windows_package_version}-32-bit.exe"
end
def parsed_windows_package_checksum
return new_resource.windows_package_checksum if new_resource.windows_package_checksum
'49601d5102df249d6f866ecfa1eea68eb5672acc1dbb7e4051099e792f6da5fc'
end
end
end

View File

@ -0,0 +1,16 @@
if defined?(ChefSpec)
ChefSpec.define_matcher(:git_client)
ChefSpec.define_matcher(:git_service)
def set_git_config(resource_name) # rubocop:disable Style/AccessorMethodName
ChefSpec::Matchers::ResourceMatcher.new(:git_config, :set, resource_name)
end
def install_git_client(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:git_client, :install, resource_name)
end
def install_git_service(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:git_service, :install, resource_name)
end
end

View File

@ -0,0 +1,13 @@
class Chef
class Provider
class GitClient < Chef::Provider::LWRPBase
use_inline_resources
def whyrun_supported?
true
end
include GitCookbook::Helpers
end
end
end

View File

@ -0,0 +1,26 @@
class Chef
class Provider
class GitClient
class Osx < Chef::Provider::GitClient
include Chef::DSL::IncludeRecipe
provides :git_client, os: 'mac_os_x'
action :install do
dmg_package 'GitOSX-Installer' do
app new_resource.osx_dmg_app_name
package_id new_resource.osx_dmg_package_id
volumes_dir new_resource.osx_dmg_volumes_dir
source new_resource.osx_dmg_url
checksum new_resource.osx_dmg_checksum
type 'pkg'
action :install
end
end
action :delete do
end
end
end
end
end

Some files were not shown because too many files have changed in this diff Show More