Skip to content
This repository was archived by the owner on Nov 30, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ services: docker

env:
global:
- secure: "KlrhCf/nRXd4szf51jfW1U5qyTHK4L1ioDjuWwUWoXPyuRqfMdDS1xbI92UZPQzfW46odRr2TLFrA/WxvV2pzS3ByB2g85nJjYcf2sokXL+w8VKs0TGvra0njOwU6rm8ZTTp4TB4nLOlhkTXCAP2GunkVX8DXYTAVO1QX68HJI/vDyRbLXFJavytyGJeaJnxguLKLB7acgHk1mxw8LPsZya0CVgNzaVOcWsZRAwmmP3gm5myofpxKC+w8IufkXaO//HbDsgsLWQL3AwS6+SPU3RrtA47Cssz5BttfZeSSma0olw8phE8UHcNoD6z9rZnokv+p6e3vov3zjJKapPBkOQKDSYL+1d9MapHx4GJEQy6MrCNuhSLF0tQkESrmuul/YOm2qiexXgwx3NG+0VBunG5xyDprfGLXmWzHCLPKaBVMABnJwpyBbSOya3YoSzAuyeP6a7yJSazB5Vm3GW9+fCLP2c1Dd8UYwZVmlEtLBQilB6PkIgixZvypLRpKOX6BBLWYlHKzKQzxx37tYdQPB8OFbQs5nuBYW5uDqS75etWE3Gv11uFk6yk+PZnNTVJeShH4Rvw91psZnJUswpCt9BfLBjefXn6NJQpiDnmCITkthfv/np/giAYOKED1cqxTpwx8wYOo+0Le2npa8yyP02qt751xblDPUvYZWiu8Bw="
- secure: "sXKZDMGoJsYZe1zgmD6IO569Q4OlSzU4icDI5it106JYfWJwghc0COXU3xKNUrOCWMHG2v8jRGjjF/45gMLJ0Op8ouZMFPo3r+q2LzNF/Y0n1bZtRuIoGaTSzZCIOYFmilJE/35a48rO1Bhz1oldYHPbn/5G/8j4XZT1awR4OT8qx0Rx9+eRPeHF/ftauJ25+zwjej24eyW2HBJeO3z7hG4c8vgu3DPo9FbN6+8gjvpWXsybrqV5Dvx1cRbKd/LqjM1wAlS8OJI9GTuUoUCt2hYGWPX0EIAwfswBX72ySmNiHSF7Bt6FIYbqyDbZpuyIxyTue9DBszlTNGi8RcHA3J0vZXxCXgUYOuh6i41+MhJ6m5w04iW9w05q6aX0vSQ/0/qQhemwJ+qBydZTt6pOv8sIGMx96wZI9oGGgKBluXxqicTvB8dOSHOxfx0KVWi8aKSnuoA0A/ejvI7k87LA4O4NT+OTvm+UIXD0hb77pOsNB9g2GLpDbuQe64Zk3Rxx/4jf4kaGKZebj430md7SggrVPMJCOq4wqdqM1HqCkADHzNavdOcToZajV4KmOXwu8bF/5pwJ66Yf3Ibs9dLFFnI8USTNlPau0aEsq+jgTSij+SB7XH8d964I8Rt9sNUQpT7mVI7dKmQI697sj1gtl5v/h7Mer+QXXv2tWo87gGg="
addons:
apt:
sources:
Expand All @@ -25,13 +25,17 @@ install:
- eval "$(chef shell-init bash)"
- openssl aes-256-cbc -K $encrypted_264707aa6565_key -iv $encrypted_264707aa6565_iv -in codenamephp.pem.enc -out codenamephp.pem -d
- gem install github_changelog_generator
- gem install activesupport

script:
- chef exec rake default documentation
- chef exec rake default

deploy:
- provider: script
on:
branch: master
skip_cleanup: true
script: chef exec rake release

after_script:
- chef exec rake documentation
27 changes: 5 additions & 22 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,15 @@
# Change Log

## [v2.0.0](https://github.com/codenamephp/chef.cookbook.dev/tree/v2.0.0) (2018-08-17)
[Full Changelog](https://github.com/codenamephp/chef.cookbook.dev/compare/v1.0.0...v2.0.0)
## [Unreleased](https://github.com/codenamephp/chef.cookbook.bash/tree/HEAD)

**Implemented enhancements:**

- DNSMasq: Use drop folder \(/etc/dnsmasq.d\) for config [\#12](https://github.com/codenamephp/chef.cookbook.dev/issues/12)
- Remove jdk recipe [\#9](https://github.com/codenamephp/chef.cookbook.dev/issues/9)
- Add gnome-terminal [\#7](https://github.com/codenamephp/chef.cookbook.dev/issues/7)
- Init for all users with data dir [\#4](https://github.com/codenamephp/chef.cookbook.bash/issues/4)
- Add github token to changelog generator [\#2](https://github.com/codenamephp/chef.cookbook.bash/issues/2)

## [v1.0.0](https://github.com/codenamephp/chef.cookbook.dev/tree/v1.0.0) (2018-06-06)
[Full Changelog](https://github.com/codenamephp/chef.cookbook.dev/compare/v0.2.0...v1.0.0)
**Closed issues:**

**Merged pull requests:**

- Update metadata.rb [\#6](https://github.com/codenamephp/chef.cookbook.dev/pull/6) ([bastianschwarz](https://github.com/bastianschwarz))

## [v0.2.0](https://github.com/codenamephp/chef.cookbook.dev/tree/v0.2.0) (2018-06-05)
**Implemented enhancements:**

- Add Visual Studio Code [\#2](https://github.com/codenamephp/chef.cookbook.dev/issues/2)
- Move to new structure and travis [\#1](https://github.com/codenamephp/chef.cookbook.dev/issues/1)

**Merged pull requests:**

- Deleting Berksfile.lock since it will cause the relase to fail \(stove… [\#5](https://github.com/codenamephp/chef.cookbook.dev/pull/5) ([bastianschwarz](https://github.com/bastianschwarz))
- Release 1.0.0 [\#4](https://github.com/codenamephp/chef.cookbook.dev/pull/4) ([bastianschwarz](https://github.com/bastianschwarz))
- Merge master [\#3](https://github.com/codenamephp/chef.cookbook.dev/pull/3) ([bastianschwarz](https://github.com/bastianschwarz))
- Lets see if auto changelog works [\#1](https://github.com/codenamephp/chef.cookbook.bash/issues/1)



Expand Down
57 changes: 13 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Chef Cookbook Dev
[![Build Status](https://travis-ci.org/codenamephp/chef.cookbook.dev.svg?branch=dev)](https://travis-ci.org/codenamephp/chef.cookbook.dev)
# Chef Cookbook Bash
[![Build Status](https://travis-ci.org/codenamephp/chef.cookbook.bash.svg?branch=dev)](https://travis-ci.org/codenamephp/chef.cookbook.bash)

Cookbook that contains recipes for dev tools, like vscode, chrome, openjdk ...
Makes sure bash is installed and handles bash configurations

## Requirements

Expand All @@ -15,20 +15,15 @@ Cookbook that contains recipes for dev tools, like vscode, chrome, openjdk ...

### Cookbook Depdendencies

- [resolver][resolver_url]

## Tools
- [Google Chrome][chrome_url]
- [Visual Studio Code][vscode_url]
- [DNS Masq][dnsmasq_url]
- [gnome-terminal][gnome-terminal_url]
- [apt][apt_url]
- [bashrc_manager][bashrc_manager_url]

## Usage

Add the cookbook to your Berksfile:

```ruby
cookbook 'codenamephp_dev'
cookbook 'codenamephp_bash'
```

Add the tools cookbook to your runlist, e.g. in a role:
Expand All @@ -39,46 +34,20 @@ Add the tools cookbook to your runlist, e.g. in a role:
"chef_type": "role",
"json_class": "Chef::Role",
"run_list": [
"recipe[codenamephp_dev::chrome]"
"recipe[codenamephp_bash]"
]
}
```

Note that the default recipe is a No-Op, so you need to add the tools you want

### Attributes

#### resolver
- `['resolver']['nameservers']` The array of ips to add to the resolver config. Defaults to `['127.0.0.1', '8.8.8.8', '8.8.4.4', '10.0.2.3']`
There are currently no attributes.

## Recipes

### Default
The default cookbook (as stated multiple times) is a No-Op. Pick and choose the tools you want via the recipes.

### Chrome
Adds the google apt repository and installs [Google Chrome][chrome_url] from package.

### DNSMasq
Purges the [Avahi Deamon][avahi_url] which is installed at least on Ubuntu and tends to occupy ports. Also the [resolver Cookbook][resolver_url]
is used to add localhost, [Google DNS][google_dns_url] and `10.0.2.3` which is needed in [VirtualBox][virutalbox_url] for network operations to work.
The IPs can be overridden/added to via the attributes.

At last, [DNSMasq][dnsmasq_url] is installed and the local domain and all subdomains is resolved to `127.0.0.1`.

### gnome-terminal
Just installs the gnome-terminal from package.

### Unzip
Just installs unzip from package (no gui client is installed)

### VSCode
Adds the VSCode package repository to apt and installs [VSCode][vscode_url] from package.
The default recipe initializes the bashrc.d folder using the /etc/skel and for each user with uid > 1000 (so all non-system users) that have a user directory. No special
configs are added. Since all files from the folder are used, you can just add your configs as a template using your own cookbook.

[chrome_url]: https://www.google.de/chrome
[vscode_url]: https://code.visualstudio.com/
[dnsmasq_url]: https://wiki.archlinux.de/title/Dnsmasq
[gnome-terminal_url]: https://en.wikipedia.org/wiki/GNOME_Terminal
[resolver_url]: https://supermarket.chef.io/cookbooks/resolver
[avahi_url]: https://wiki.ubuntuusers.de/Avahi/
[google_dns_url]: https://developers.google.com/speed/public-dns/
[virtualbox_url]: https://www.virtualbox.org/
[apt_url]: https://supermarket.chef.io/cookbooks/apt
[bashrc_manager_url]: https://supermarket.chef.io/cookbooks/bashrc_manager
27 changes: 14 additions & 13 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
require 'active_support'
require 'active_support/core_ext'

# Checks if we are inside a Continuous Integration machine.
#
# @return [Boolean] whether we are inside a CI.
Expand All @@ -16,7 +19,7 @@ def concurrency
end

def origin_branch
ENV['TRAVIS_PULL_REQUEST_BRANCH'] || ENV['TRAVIS_BRANCH'] || 'dev'
ENV['TRAVIS_PULL_REQUEST_BRANCH'].presence || ENV['TRAVIS_BRANCH'].presence || 'dev'
end

task default: %w[style unit integration]
Expand All @@ -26,12 +29,7 @@ namespace :git do
task :setup do
sh 'git config --local user.name "Travis CI"'
sh 'git config --local user.email "[email protected]"'
sh 'git remote set-url --push origin "https://' + ENV['GH_TOKEN'].to_s + '@github.com/' + ENV['TRAVIS_REPO_SLUG'] + '.git"', verbose: false do |ok, status|
unless ok
raise "Command failed with status (#{status.exitstatus}): " \
'git remote set-url --push origin "https://[GITHUB_TOKEN_HIDDEN]@github.com/' + ENV['TRAVIS_REPO_SLUG'] + '.git"'
end
end
sh 'git remote set-url --push origin "https://' + ENV['GH_TOKEN'].to_s + '@github.com/' + ENV['TRAVIS_REPO_SLUG'] + '.git"', verbose: false
end
end

Expand Down Expand Up @@ -126,18 +124,21 @@ task :integration, %i[regexp action concurrency] => ci? || use_dokken? ? %w[inte
namespace :documentation do
desc 'Generate changelog'
task changelog: ['git:setup'] do
sh 'git clone [email protected]:' + ENV['TRAVIS_REPO_SLUG'] + '.git --branch ' + origin_branch + ' --single-branch .tmp'
sh 'cd .tmp'
sh 'github_changelog_generator'
sh 'git status'
sh 'git add CHANGELOG.md && git commit --allow-empty -m"[skip ci] Updated changelog" && git push origin ' + origin_branch
unless File.directory?('.tmp')
sh 'git clone "https://' + ENV['GH_TOKEN'].to_s + '@github.com/' + ENV['TRAVIS_REPO_SLUG'] + '.git" --branch ' + origin_branch + ' --single-branch .tmp'
end
Dir.chdir('.tmp') do
sh "github_changelog_generator -t #{ENV['GH_TOKEN']}"
sh 'git status'
sh 'git add CHANGELOG.md && git commit --allow-empty -m"[skip ci] Updated changelog" && git push origin ' + origin_branch
end
end

desc 'Generate changelog from current commit message for release'
task changelog_release: ['git:setup'] do
match = Regexp.new('\[RELEASE\s([\d\.]+)\]').match(ENV['TRAVIS_COMMIT_MESSAGE'])
unless match.nil?
sh 'github_changelog_generator --future-release ' + match[1].to_s
sh "github_changelog_generator -t #{ENV['GH_TOKEN']} --future-release #{match[1]}"
sh 'git status'
sh 'git add CHANGELOG.md && git commit --allow-empty -m"[skip ci] Updated changelog" && git push origin ' + ENV['TRAVIS_BRANCH']
end
Expand Down
1 change: 0 additions & 1 deletion attributes/default.rb
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
default['codenamephp_bash']['user'] = 'root'
1 change: 1 addition & 0 deletions metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@

supports 'debian', '~>9.1'

depends 'apt', '~> 7.0'
depends 'bashrc_manager', '~> 1.0'
32 changes: 27 additions & 5 deletions recipes/default.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,34 @@
#
# Cookbook:: codenamephp_dev
# Cookbook:: codenamephp_bash
# Recipe:: default
#
# Copyright:: 2017, The Authors, All Rights Reserved.
# Copyright:: 2018, The Authors, All Rights Reserved.

include_recipe 'apt'
package 'bash'

bashrc_manager 'dummy' do
user node['codenamephp_bash']['user']
content '# this file exists only to setup the bashrc drop folder'
directory 'create .bashrc.d folder in /etc/skel' do
path '/etc/skel/.bashrc.d'
mode 0o755
end

file 'copy default .bashrc to init in dropfolder' do
path '/etc/skel/.bashrc.d/init'
mode 0o755
content(lazy { ::File.open('/etc/skel/.bashrc').read })
action :create_if_missing
end

template '/etc/skel/.bashrc' do
source '.bashrc.erb'
mode 0o755
end

node['etc']['passwd'].each do |user, data|
next unless data['uid'].to_i >= 1000 && File.directory?(data['dir'])

bashrc_manager "init bashrc.d for user #{user}" do
user user
content '# this file exists only to setup the bashrc drop folder'
end
end
68 changes: 66 additions & 2 deletions spec/unit/recipes/default_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,76 @@
describe 'codenamephp_bash::default' do
context 'When all attributes are default, on an unspecified platform' do
let(:chef_run) do
runner = ChefSpec::SoloRunner.new
runner.converge(described_recipe)
ChefSpec::SoloRunner.new do |node|
node.override['etc']['passwd'] = []
end.converge(described_recipe)
end

it 'converges successfully' do
expect { chef_run }.to_not raise_error
end

it 'includes the apt cookbook' do
expect(chef_run).to include_recipe('apt')
end

it 'installs bash from package' do
expect(chef_run).to install_package('bash')
end

it 'copies the default .bashrc to init file in dropfolder' do
allow(File).to receive(:open).and_call_original
allow(File).to(receive(:open).with('/etc/skel/.bashrc') do
double = double(File)
allow(double).to receive(:read).and_return 'some content'
double
end)

expect(chef_run).to create_if_missing_file('copy default .bashrc to init in dropfolder').with(
path: '/etc/skel/.bashrc.d/init',
mode: 0o755,
content: 'some content'
)
end

it 'updates the skel .bashrc with template content' do
expect(chef_run).to create_template('/etc/skel/.bashrc').with(source: '.bashrc.erb', mode: 0o755)
end
end

context 'When users were detected' do
let(:chef_run) do
ChefSpec::SoloRunner.new do |node|
node.override['etc']['passwd'] = {
'user1' => { 'dir' => '/home/user1', 'uid' => 1000, 'gid' => 123 },
'user2' => { 'dir' => '/home/user2', 'uid' => 1001, 'gid' => 456 },
'user3' => { 'dir' => '/home/user3', 'uid' => 500, 'gid' => 789 },
'user4' => { 'dir' => '/home/user4', 'uid' => 1002, 'gid' => 789 }
}
end.converge(described_recipe)
end

before(:each) do
allow(File).to receive(:directory?).with(anything).and_call_original
allow(File).to receive(:directory?).with('/home/user1').and_return true
allow(File).to receive(:directory?).with('/home/user2').and_return true
allow(File).to receive(:directory?).with('/home/user3').and_return true
allow(File).to receive(:directory?).with('/home/user4').and_return false
end

it 'converges successfully' do
expect { chef_run }.to_not raise_error
end

it 'executes the resource for every user with a home directory' do
expect(chef_run).to add_bashrc_manager('init bashrc.d for user user1').with(
user: 'user1',
content: '# this file exists only to setup the bashrc drop folder'
)
expect(chef_run).to add_bashrc_manager('init bashrc.d for user user2').with(
user: 'user2',
content: '# this file exists only to setup the bashrc drop folder'
)
end
end
end
6 changes: 6 additions & 0 deletions templates/default/.bashrc.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Managed by Chef. Local changes will be overwritten.
# To manually add resources to the bashrc, create a file in the ~/.bashrc.d folder and add your changes there.

for file in ~/.bashrc.d/* ; do
source ${file}
done
23 changes: 23 additions & 0 deletions test/smoke/default/default_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,27 @@
describe command('bash') do
it { should exist }
end

describe file('/etc/skel/.bashrc') do
it { should exist }
it { should be_file }
its('content') { should match(%r{# To manually add resources to the bashrc, create a file in the \~\/\.bashrc\.d folder and add your changes there\.}) }
its('mode') { should cmp '0755' }
its('owner') { should eq 'root' }
end

describe file('/etc/skel/.bashrc.d') do
it { should exist }
it { should be_directory }
its('mode') { should cmp '0755' }
its('owner') { should eq 'root' }
end

describe file('/etc/skel/.bashrc.d/init') do
it { should exist }
it { should be_file }
its('content') { should match(%r{# \~\/\.bashrc: executed by bash\(1\) for non-login shells\.}) }
its('mode') { should cmp '0755' }
its('owner') { should eq 'root' }
end
end