├── .gitignore ├── .kitchen.cloud.yml ├── .kitchen.docker.yml ├── .kitchen.openstack.yml ├── .kitchen.yml ├── Berksfile ├── CHANGELOG.md ├── CONTRIBUTING.md ├── Gemfile ├── Gemfile.lock ├── LICENSE ├── README.md ├── Rakefile ├── TESTING.md ├── attributes ├── agent.rb ├── repository.rb └── server.rb ├── chefignore ├── ci-setup.sh ├── config └── cookstyle.yml ├── libraries ├── helpers.rb └── matchers.rb ├── metadata.rb ├── recipes ├── agent.rb ├── agent_linux.rb ├── agent_linux_install.rb ├── agent_windows.rb ├── agent_windows_install.rb ├── default.rb ├── java.rb ├── ohai.rb ├── repository.rb ├── server.rb ├── server_linux.rb ├── server_linux_install.rb ├── server_windows.rb └── server_windows_install.rb ├── resources ├── agent.rb ├── agent_autoregister_file.rb └── plugin.rb ├── spec ├── go_agent_autoregister_lwrp_spec.rb ├── go_agent_lwrp_spec.rb ├── go_agent_spec.rb ├── go_agent_windows_spec.rb ├── go_server_spec.rb ├── go_server_windows_spec.rb ├── libraries │ └── helpers_spec.rb ├── plugin_lwrp_spec.rb ├── shared_examples.rb └── spec_helper.rb ├── templates └── default │ ├── autoregister.properties.erb │ ├── go-agent-default.erb │ └── go-server-default.erb └── test ├── integration ├── default │ └── serverspec │ │ ├── go_agent_daemon_spec.rb │ │ ├── go_autoregister_spec.rb │ │ └── go_server_daemon_spec.rb └── golangagent │ └── serverspec │ ├── go_agent_daemon_spec.rb │ ├── go_autoregister_spec.rb │ └── go_server_daemon_spec.rb └── test_cookbook ├── metadata.rb └── recipes ├── agent_autoregister_file_lwrp.rb ├── default_agent_lwrp.rb ├── plugin_lwrp.rb └── single_agent_lwrp.rb /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # No need to keep my local .vagrant directory around 3 | .vagrant/ 4 | 5 | # Berkshelf's lock file contains local pathes when running vagrant 6 | Berksfile.lock 7 | 8 | .kitchen/ 9 | .kitchen.local.yml 10 | 11 | .bundle 12 | # installed with `bundle install --binstubs` 13 | bin/ 14 | 15 | .vendor/bundle/ 16 | 17 | HTML report generated by ChefSpec: 18 | chefspec.html 19 | -------------------------------------------------------------------------------- /.kitchen.cloud.yml: -------------------------------------------------------------------------------- 1 | ########################################################################## 2 | # Copyright 2017 ThoughtWorks, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ########################################################################## 16 | 17 | --- 18 | driver_config: 19 | digitalocean_api_key: <%= ENV['DIGITALOCEAN_API_KEY'] %> 20 | digitalocean_client_id: <%= ENV['DIGITALOCEAN_CLIENT_ID'] %> 21 | aws_access_key_id: <%= ENV['AWS_ACCESS_KEY'] %> 22 | aws_secret_access_key: <%= ENV['AWS_SECRET_KEY'] %> 23 | aws_ssh_key_id: <%= ENV['AWS_SSH_KEY_ID'] %> 24 | 25 | provisioner: 26 | name: chef_zero 27 | require_chef_omnibus: latest 28 | 29 | platforms: 30 | - name: ubuntu-12.04 31 | driver_plugin: digitalocean 32 | driver_config: 33 | image_id: 6374130 34 | flavor_id: 63 35 | region_id: 4 36 | ssh_key: <%= ENV['DIGITALOCEAN_SSH_KEY_PATH'] %> 37 | ssh_key_ids: <%= ENV['DIGITALOCEAN_SSH_KEY_IDS'] %> 38 | 39 | - name: amazon-2014.09.1 40 | driver_plugin: ec2 41 | driver_config: 42 | image_id: ami-b66ed3de 43 | region: us-east-1 44 | availability_zone: us-east-1b 45 | flavor_id: t2.micro 46 | username: ec2-user 47 | security_group_ids: <%= ENV['AWS_SECURITY_GROUP'] %> 48 | ssh_key: <%= ENV['AWS_SSH_KEY_PATH'] %> 49 | 50 | suites: 51 | - name: default 52 | run_list: 53 | - recipe[gocd] 54 | attributes: {} 55 | -------------------------------------------------------------------------------- /.kitchen.docker.yml: -------------------------------------------------------------------------------- 1 | ########################################################################## 2 | # Copyright 2017 ThoughtWorks, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ########################################################################## 16 | 17 | --- 18 | driver: 19 | name: docker 20 | privileged: true 21 | use_sudo: false 22 | 23 | provisioner: 24 | name: chef_zero 25 | require_chef_omnibus: 13 26 | 27 | platforms: 28 | - name: centos-6 29 | - name: centos-7 30 | - name: ubuntu-16.04 31 | - name: ubuntu-18.04 32 | 33 | suites: 34 | - name: default 35 | run_list: 36 | - recipe[gocd] 37 | attributes: 38 | gocd: 39 | server: 40 | max_mem: '2048m' 41 | min_mem: '512m' 42 | agent: 43 | count: 2 # good test for agent lwrp 44 | autoregister: 45 | key: 'auto-register-key' 46 | environments: ['staging', 'perf'] 47 | resources: ['foo', 'bar', 'baz'] 48 | hostname: 'example-host' 49 | - name: package_file 50 | run_list: 51 | - recipe[gocd] 52 | attributes: 53 | gocd: 54 | install_method: 'package_file' 55 | server: 56 | max_mem: '2048m' 57 | min_mem: '512m' 58 | agent: 59 | autoregister: 60 | key: 'auto-register-key' 61 | environments: ['staging', 'perf'] 62 | resources: ['foo', 'bar', 'baz'] 63 | hostname: 'example-host' 64 | -------------------------------------------------------------------------------- /.kitchen.openstack.yml: -------------------------------------------------------------------------------- 1 | ########################################################################## 2 | # Copyright 2017 ThoughtWorks, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ########################################################################## 16 | 17 | --- 18 | provisioner: 19 | name: chef_zero 20 | require_chef_omnibus: 12.4.1 21 | 22 | platforms: 23 | - name: debian 24 | driver: 25 | name: vagrant 26 | driver_config: 27 | box: 'debian-7.8-bpk-chef-12.4.1' 28 | customize: 29 | server_name: 'kt-go' 30 | flavor: 'v.c1.m2048.d5.e0' 31 | server_create_timeout: 540 32 | server_active_timeout: 540 33 | - name: windows 34 | provisioner: 35 | name: chef_solo 36 | require_chef_omnibus: 12.4.2 37 | driver: 38 | name: vagrant 39 | driver_config: 40 | box: 'windows-7-net45-2.0-chef-12.4.2' 41 | customize: 42 | flavor: 'v.c1.m2048.d20.e0' 43 | server_create_timeout: 1200 44 | server_active_timeout: 1200 45 | server_name: 'kt-go-win' 46 | 47 | suites: 48 | - name: default 49 | run_list: 50 | - recipe[gocd] 51 | - recipe[gocd_test::plugin_lwrp] 52 | attributes: 53 | apt: 54 | compile_time_update: true 55 | java: 56 | jdk_version: 8 57 | gocd: 58 | server: 59 | wait_up: 60 | retries: 120 61 | max_mem: '1024m' 62 | min_mem: '512m' 63 | agent: 64 | autoregister: 65 | key: 'auto-register-key' 66 | environments: ['staging', 'perf'] 67 | resources: ['foo', 'bar', 'baz'] 68 | hostname: 'example-host' 69 | -------------------------------------------------------------------------------- /.kitchen.yml: -------------------------------------------------------------------------------- 1 | ########################################################################## 2 | # Copyright 2017 ThoughtWorks, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ########################################################################## 16 | 17 | --- 18 | driver_plugin: vagrant 19 | driver: 20 | customize: 21 | memory: 4096 22 | 23 | provisioner: 24 | name: chef_zero 25 | require_chef_omnibus: 12.19.36 26 | 27 | platforms: 28 | - name: ubuntu-16.04 29 | driver: 30 | box: ubuntu/xenial64 31 | network: 32 | - [ 'private_network', { ip: '33.33.33.11' } ] 33 | - name: ubuntu-18.04 34 | driver: 35 | box: ubuntu/bionic64 36 | network: 37 | - [ 'private_network', { ip: '33.33.33.11' } ] 38 | - name: centos-6.8 39 | driver: 40 | network: 41 | - [ 'private_network', { ip: '33.33.33.12' } ] 42 | 43 | suites: 44 | - name: default 45 | run_list: ['recipe[gocd]'] 46 | -------------------------------------------------------------------------------- /Berksfile: -------------------------------------------------------------------------------- 1 | source 'https://supermarket.getchef.com' 2 | 3 | metadata 4 | 5 | group :test do 6 | cookbook 'gocd_test', path: 'test/test_cookbook' 7 | end 8 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # 3.0.1 2 | 3 | * [8f34eb6](https://github.com/gocd/go-cookbook/commit/8f34eb6) - Set correct package name for Windows based on arch 4 | * [ea191db](https://github.com/gocd/go-cookbook/commit/ea191db) - Update foodcritic version to 12.2.1 5 | 6 | # 3.0.0 7 | 8 | * Supports Chef 13 9 | 10 | ## Breaking Changes 11 | 12 | * [4f82f84](https://github.com/gocd/go-cookbook/commit/4f82f84) - The `resources` and `environments` properties in our custom resources `gocd_agent` and `gocd_agent_autoregister_file` are removed in favour of `autoregister_resources` and `autoregister_environments`. 13 | 14 | ## Fixes 15 | 16 | * [607f3e8](https://github.com/gocd/go-cookbook/commit/607f3e8) - Change all URLs from gocd.io to gocd.org 17 | * [5fd066f](https://github.com/gocd/go-cookbook/commit/5fd066f) - Update foodcritic version to use the one used on supermarket. 18 | * [5fd066f](https://github.com/gocd/go-cookbook/commit/5fd066f) - Update foodcritic licensing format. 19 | 20 | # 2.0.0 21 | 22 | ## Breaking changes 23 | 24 | * The attributes `go_server_host` and `go_server_port` are removed in favour of `go_server_url` 25 | 26 | ## Deprecations 27 | 28 | * The `resources` and `environments` properties in our custom resources `gocd_agent` and `gocd_agent_autoregister_file` are deprecated in favour of `autoregister_resources` and `autoregister_environments`. 29 | They will be removed in one of the upcoming releases. Please use `autoregister_resources` and `autoregister_environments` henceforth. 30 | 31 | ## Bug Fixes 32 | 33 | * [236f6cd](https://github.com/gocd/go-cookbook/commit/236f6cd) - Explicitly specify provider to be systemd for ubuntu 16.04. 34 | * [d637543](https://github.com/gocd/go-cookbook/commit/d637543) - Change package name for debian to include substring '_all'. 35 | 36 | 37 | # 1.3.2 38 | 39 | * Changes all URLs from go.cd to gocd.io. 40 | 41 | # 1.3.1 42 | 43 | * #93 Fix GO_SERVER_URL not being set correctly on windows 44 | * #92 fix several issues with installing server on windows 45 | * replaced obsolete gpg key 46 | * install golang agent as a binary from bintray 47 | 48 | # 1.3.0 49 | 50 | * rewritten chef resources to use new custom resource syntax 51 | * updated agent startup config files to use `GO_SERVER_URL` instead of host and port 52 | * by default install java 8 53 | * isolated gocd_agent_autoregister_file resource 54 | * added golang agent support 55 | * use apt cookbook >= 3.0 56 | 57 | # 1.2.0 58 | 59 | * Improved version handling and installing on windows #63 #67 60 | * fixed autoregister value - `daemon` #88 61 | * added maintainer and maintainer_email to metadata, #84 62 | 63 | # 1.1.1 64 | 65 | * Default to using latest version, when using a platform that supports it 66 | 67 | # 1.1.0 68 | 69 | * Improve support for installing GoCD on windows 70 | * Use https://download.go.cd for all repositories 71 | 72 | # 1.0.0 73 | 74 | Rewrite from scratch. 75 | 76 | * GH-26 now cookbook defaults to installing latest stable 77 | * GH-48 changed root of attributes to `gocd` 78 | * GH-50 - installing from non-official sources - custom package file or custom apt repository. 79 | * GH-56 - now agents can be provisioned with `gocd_agent` resource 80 | * GH-52 - added lots of tests 81 | * GH-59 - fixed 82 | * added small `gocd_plugin` resource which can be used to install Go server plugins. 83 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Contributing 2 | ============ 3 | 4 | Steps 5 | ----- 6 | 7 | Thanks for your interest in our GoCD cookbook! If you'd like to help out please: 8 | 9 | 1. Fork it 10 | 2. Create your feature branch (`git checkout -b my-new-feature`) 11 | 3. Add tests for the new feature; ensure they pass (`chef exec bundle exec rake`) 12 | 4. Commit your changes (`git commit -am 'Add some feature'`) 13 | 5. Push to the branch (`git push origin my-new-feature`) 14 | 6. Create a new Pull Request 15 | 16 | 17 | ## Testing 18 | 19 | ``` 20 | bundle install && chef exec rake -T 21 | ``` 22 | 23 | The above command indicates all the tests that can be run. 24 | 25 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gem 'chef', '~> 13' 4 | gem 'chefspec' 5 | gem 'foodcritic' 6 | gem 'berkshelf' 7 | gem 'test-kitchen' 8 | gem 'kitchen-vagrant' 9 | gem 'kitchen-ec2' 10 | gem 'kitchen-digitalocean' 11 | gem 'kitchen-docker' 12 | gem 'winrm-transport' 13 | gem 'guard' 14 | gem 'guard-foodcritic' 15 | gem 'guard-rubocop' 16 | gem 'guard-rspec' 17 | gem 'cookstyle' 18 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: https://rubygems.org/ 3 | specs: 4 | activesupport (5.2.3) 5 | concurrent-ruby (~> 1.0, >= 1.0.2) 6 | i18n (>= 0.7, < 2) 7 | minitest (~> 5.1) 8 | tzinfo (~> 1.1) 9 | addressable (2.6.0) 10 | public_suffix (>= 2.0.2, < 4.0) 11 | artifactory (3.0.0) 12 | ast (2.4.0) 13 | aws-eventstream (1.0.3) 14 | aws-partitions (1.161.0) 15 | aws-sdk-core (3.51.0) 16 | aws-eventstream (~> 1.0, >= 1.0.2) 17 | aws-partitions (~> 1.0) 18 | aws-sigv4 (~> 1.1) 19 | jmespath (~> 1.0) 20 | aws-sdk-ec2 (1.82.0) 21 | aws-sdk-core (~> 3, >= 3.48.2) 22 | aws-sigv4 (~> 1.1) 23 | aws-sigv4 (1.1.0) 24 | aws-eventstream (~> 1.0, >= 1.0.2) 25 | axiom-types (0.1.1) 26 | descendants_tracker (~> 0.0.4) 27 | ice_nine (~> 0.11.0) 28 | thread_safe (~> 0.3, >= 0.3.1) 29 | backports (3.14.0) 30 | berkshelf (7.0.8) 31 | chef (>= 13.6.52) 32 | chef-config 33 | cleanroom (~> 1.0) 34 | concurrent-ruby (~> 1.0) 35 | minitar (>= 0.6) 36 | mixlib-archive (>= 0.4, < 2.0) 37 | mixlib-config (>= 2.2.5) 38 | mixlib-shellout (>= 2.0, < 4.0) 39 | octokit (~> 4.0) 40 | retryable (>= 2.0, < 4.0) 41 | solve (~> 4.0) 42 | thor (>= 0.20) 43 | builder (3.2.3) 44 | chef (13.12.14) 45 | addressable 46 | bundler (>= 1.10) 47 | chef-config (= 13.12.14) 48 | chef-zero (~> 13.0) 49 | diff-lcs (~> 1.2, >= 1.2.4) 50 | erubis (~> 2.7) 51 | ffi-yajl (~> 2.2) 52 | highline (~> 1.6, >= 1.6.9) 53 | iniparse (~> 1.4) 54 | iso8601 (~> 0.12.1) 55 | mixlib-archive (~> 0.4) 56 | mixlib-authentication (~> 1.4) 57 | mixlib-cli (~> 1.7) 58 | mixlib-log (~> 1.3) 59 | mixlib-shellout (~> 2.4) 60 | net-sftp (~> 2.1, >= 2.1.2) 61 | net-ssh (>= 2.9, < 5.0) 62 | net-ssh-multi (~> 1.2, >= 1.2.1) 63 | ohai (~> 13.0) 64 | plist (~> 3.2) 65 | proxifier (~> 1.0) 66 | rspec-core (~> 3.5, < 3.8) 67 | rspec-expectations (~> 3.5, < 3.8) 68 | rspec-mocks (~> 3.5, < 3.8) 69 | rspec_junit_formatter (~> 0.2.0) 70 | serverspec (~> 2.7) 71 | specinfra (~> 2.10) 72 | syslog-logger (~> 1.6) 73 | uuidtools (~> 2.1.5) 74 | chef-config (13.12.14) 75 | addressable 76 | fuzzyurl 77 | mixlib-config (>= 2.2.12, < 3.0) 78 | mixlib-shellout (~> 2.0) 79 | tomlrb (~> 1.2) 80 | chef-zero (13.1.0) 81 | ffi-yajl (~> 2.2) 82 | hashie (>= 2.0, < 4.0) 83 | mixlib-log (~> 1.3) 84 | rack (~> 2.0) 85 | uuidtools (~> 2.1) 86 | chefspec (7.3.4) 87 | chef (>= 12.16.42) 88 | fauxhai (>= 4) 89 | rspec (~> 3.0) 90 | cleanroom (1.0.0) 91 | coderay (1.1.2) 92 | coercible (1.0.0) 93 | descendants_tracker (~> 0.0.1) 94 | concurrent-ruby (1.1.5) 95 | cookstyle (4.0.0) 96 | rubocop (= 0.62.0) 97 | cucumber-core (3.2.1) 98 | backports (>= 3.8.0) 99 | cucumber-tag_expressions (~> 1.1.0) 100 | gherkin (~> 5.0) 101 | cucumber-tag_expressions (1.1.1) 102 | descendants_tracker (0.0.4) 103 | thread_safe (~> 0.3, >= 0.3.1) 104 | diff-lcs (1.3) 105 | droplet_kit (2.9.0) 106 | activesupport (> 3.0, < 6) 107 | faraday (~> 0.15) 108 | kartograph (~> 0.2.3) 109 | resource_kit (~> 0.1.5) 110 | virtus (~> 1.0.3) 111 | equalizer (0.0.11) 112 | erubis (2.7.0) 113 | excon (0.64.0) 114 | faraday (0.15.4) 115 | multipart-post (>= 1.2, < 3) 116 | fauxhai (7.2.0) 117 | net-ssh 118 | ffi (1.10.0) 119 | ffi-yajl (2.3.1) 120 | libyajl2 (~> 1.2) 121 | foodcritic (15.1.0) 122 | cucumber-core (>= 1.3, < 4.0) 123 | erubis 124 | ffi-yajl (~> 2.0) 125 | nokogiri (>= 1.5, < 2.0) 126 | rake 127 | rufus-lru (~> 1.0) 128 | treetop (~> 1.4) 129 | formatador (0.2.5) 130 | fuzzyurl (0.9.0) 131 | gherkin (5.1.0) 132 | gssapi (1.3.0) 133 | ffi (>= 1.0.1) 134 | guard (2.15.0) 135 | formatador (>= 0.2.4) 136 | listen (>= 2.7, < 4.0) 137 | lumberjack (>= 1.0.12, < 2.0) 138 | nenv (~> 0.1) 139 | notiffany (~> 0.0) 140 | pry (>= 0.9.12) 141 | shellany (~> 0.0) 142 | thor (>= 0.18.1) 143 | guard-compat (1.2.1) 144 | guard-foodcritic (3.0.0) 145 | foodcritic (>= 8) 146 | guard (~> 2.12) 147 | guard-compat (~> 1.2) 148 | guard-rspec (4.7.3) 149 | guard (~> 2.1) 150 | guard-compat (~> 1.1) 151 | rspec (>= 2.99.0, < 4.0) 152 | guard-rubocop (1.3.0) 153 | guard (~> 2.0) 154 | rubocop (~> 0.20) 155 | gyoku (1.3.1) 156 | builder (>= 2.1.2) 157 | hashie (3.6.0) 158 | highline (1.7.10) 159 | httpclient (2.8.3) 160 | i18n (1.6.0) 161 | concurrent-ruby (~> 1.0) 162 | ice_nine (0.11.2) 163 | iniparse (1.4.4) 164 | ipaddress (0.8.3) 165 | iso8601 (0.12.1) 166 | jaro_winkler (1.5.2) 167 | jmespath (1.4.0) 168 | kartograph (0.2.7) 169 | kitchen-digitalocean (0.9.6) 170 | droplet_kit (~> 2.0) 171 | test-kitchen (~> 1.2) 172 | kitchen-docker (2.9.0) 173 | test-kitchen (>= 1.0.0) 174 | kitchen-ec2 (3.0.1) 175 | aws-sdk-ec2 (~> 1.0) 176 | excon 177 | multi_json 178 | retryable (~> 2.0) 179 | test-kitchen (>= 1.4.1, < 3) 180 | kitchen-vagrant (1.5.2) 181 | test-kitchen (>= 1.4, < 3) 182 | libyajl2 (1.2.0) 183 | listen (3.1.5) 184 | rb-fsevent (~> 0.9, >= 0.9.4) 185 | rb-inotify (~> 0.9, >= 0.9.7) 186 | ruby_dep (~> 1.2) 187 | little-plugger (1.1.4) 188 | logging (2.2.2) 189 | little-plugger (~> 1.1) 190 | multi_json (~> 1.10) 191 | lumberjack (1.0.13) 192 | method_source (0.9.2) 193 | mini_portile2 (2.4.0) 194 | minitar (0.8) 195 | minitest (5.11.3) 196 | mixlib-archive (0.4.20) 197 | mixlib-log 198 | mixlib-authentication (1.4.2) 199 | mixlib-cli (1.7.0) 200 | mixlib-config (2.2.18) 201 | tomlrb 202 | mixlib-install (2.1.12) 203 | artifactory 204 | mixlib-shellout 205 | mixlib-versioning 206 | thor 207 | mixlib-log (1.7.1) 208 | mixlib-shellout (2.4.4) 209 | mixlib-versioning (1.2.7) 210 | molinillo (0.6.6) 211 | multi_json (1.13.1) 212 | multipart-post (2.1.0) 213 | nenv (0.3.0) 214 | net-scp (1.2.1) 215 | net-ssh (>= 2.6.5) 216 | net-sftp (2.1.2) 217 | net-ssh (>= 2.6.5) 218 | net-ssh (4.2.0) 219 | net-ssh-gateway (1.3.0) 220 | net-ssh (>= 2.6.5) 221 | net-ssh-multi (1.2.1) 222 | net-ssh (>= 2.6.5) 223 | net-ssh-gateway (>= 1.2.0) 224 | net-telnet (0.1.1) 225 | nokogiri (1.10.3) 226 | mini_portile2 (~> 2.4.0) 227 | nori (2.6.0) 228 | notiffany (0.1.1) 229 | nenv (~> 0.1) 230 | shellany (~> 0.0) 231 | octokit (4.14.0) 232 | sawyer (~> 0.8.0, >= 0.5.3) 233 | ohai (13.12.6) 234 | chef-config (>= 12.5.0.alpha.1, < 14) 235 | ffi (~> 1.9) 236 | ffi-yajl (~> 2.2) 237 | ipaddress 238 | mixlib-cli (< 2.0) 239 | mixlib-config (~> 2.0) 240 | mixlib-log (>= 1.7.1, < 2.0) 241 | mixlib-shellout (~> 2.0) 242 | plist (~> 3.1) 243 | systemu (~> 2.6.4) 244 | wmi-lite (~> 1.0) 245 | parallel (1.17.0) 246 | parser (2.6.3.0) 247 | ast (~> 2.4.0) 248 | plist (3.5.0) 249 | polyglot (0.3.5) 250 | powerpack (0.1.2) 251 | proxifier (1.0.3) 252 | pry (0.12.2) 253 | coderay (~> 1.1.0) 254 | method_source (~> 0.9.0) 255 | public_suffix (3.0.3) 256 | rack (2.0.7) 257 | rainbow (3.0.0) 258 | rake (12.3.2) 259 | rb-fsevent (0.10.3) 260 | rb-inotify (0.10.0) 261 | ffi (~> 1.0) 262 | resource_kit (0.1.7) 263 | addressable (>= 2.3.6, < 3.0.0) 264 | retryable (2.0.4) 265 | rspec (3.7.0) 266 | rspec-core (~> 3.7.0) 267 | rspec-expectations (~> 3.7.0) 268 | rspec-mocks (~> 3.7.0) 269 | rspec-core (3.7.1) 270 | rspec-support (~> 3.7.0) 271 | rspec-expectations (3.7.0) 272 | diff-lcs (>= 1.2.0, < 2.0) 273 | rspec-support (~> 3.7.0) 274 | rspec-its (1.3.0) 275 | rspec-core (>= 3.0.0) 276 | rspec-expectations (>= 3.0.0) 277 | rspec-mocks (3.7.0) 278 | diff-lcs (>= 1.2.0, < 2.0) 279 | rspec-support (~> 3.7.0) 280 | rspec-support (3.7.1) 281 | rspec_junit_formatter (0.2.3) 282 | builder (< 4) 283 | rspec-core (>= 2, < 4, != 2.12.0) 284 | rubocop (0.62.0) 285 | jaro_winkler (~> 1.5.1) 286 | parallel (~> 1.10) 287 | parser (>= 2.5, != 2.5.1.1) 288 | powerpack (~> 0.1) 289 | rainbow (>= 2.2.2, < 4.0) 290 | ruby-progressbar (~> 1.7) 291 | unicode-display_width (~> 1.4.0) 292 | ruby-progressbar (1.10.0) 293 | ruby_dep (1.5.0) 294 | rubyntlm (0.6.2) 295 | rubyzip (1.2.2) 296 | rufus-lru (1.1.0) 297 | safe_yaml (1.0.5) 298 | sawyer (0.8.2) 299 | addressable (>= 2.3.5) 300 | faraday (> 0.8, < 2.0) 301 | semverse (3.0.0) 302 | serverspec (2.41.3) 303 | multi_json 304 | rspec (~> 3.0) 305 | rspec-its 306 | specinfra (~> 2.72) 307 | sfl (2.3) 308 | shellany (0.0.1) 309 | solve (4.0.2) 310 | molinillo (~> 0.6) 311 | semverse (>= 1.1, < 4.0) 312 | specinfra (2.77.1) 313 | net-scp 314 | net-ssh (>= 2.7) 315 | net-telnet (= 0.1.1) 316 | sfl 317 | syslog-logger (1.6.8) 318 | systemu (2.6.5) 319 | test-kitchen (1.15.0) 320 | mixlib-install (>= 1.2, < 3.0) 321 | mixlib-shellout (>= 1.2, < 3.0) 322 | net-scp (~> 1.1) 323 | net-ssh (>= 2.9, < 5.0) 324 | net-ssh-gateway (~> 1.2) 325 | safe_yaml (~> 1.0) 326 | thor (~> 0.18) 327 | thor (0.20.3) 328 | thread_safe (0.3.6) 329 | tomlrb (1.2.8) 330 | treetop (1.6.10) 331 | polyglot (~> 0.3) 332 | tzinfo (1.2.5) 333 | thread_safe (~> 0.1) 334 | unicode-display_width (1.4.1) 335 | uuidtools (2.1.5) 336 | virtus (1.0.5) 337 | axiom-types (~> 0.1) 338 | coercible (~> 1.0) 339 | descendants_tracker (~> 0.0, >= 0.0.3) 340 | equalizer (~> 0.0, >= 0.0.9) 341 | winrm (1.8.1) 342 | builder (>= 2.1.2) 343 | gssapi (~> 1.2) 344 | gyoku (~> 1.0) 345 | httpclient (~> 2.2, >= 2.2.0.2) 346 | logging (>= 1.6.1, < 3.0) 347 | nori (~> 2.0) 348 | rubyntlm (~> 0.6.0) 349 | winrm-transport (1.0.4) 350 | rubyzip (~> 1.1, >= 1.1.7) 351 | winrm (~> 1.3) 352 | wmi-lite (1.0.2) 353 | 354 | PLATFORMS 355 | ruby 356 | 357 | DEPENDENCIES 358 | berkshelf 359 | chef (~> 13) 360 | chefspec 361 | cookstyle 362 | foodcritic 363 | guard 364 | guard-foodcritic 365 | guard-rspec 366 | guard-rubocop 367 | kitchen-digitalocean 368 | kitchen-docker 369 | kitchen-ec2 370 | kitchen-vagrant 371 | test-kitchen 372 | winrm-transport 373 | 374 | BUNDLED WITH 375 | 1.17.3 376 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GoCD Cookbook 2 | 3 | # This cookbook is no longer maintained. Please log a GitHub issue if you're looking to maintain it. 4 | 5 | This cookbook is here to help you setup GoCD servers and agents in an automated way. 6 | 7 | ## Scope 8 | 9 | * This cookbook can be used for installing and configuring a GoCD server and multiple GoCD agents. 10 | * On linux machines, the recipes used for installing the GoCD server and agents use the yum and apt repositories to install from. Zip installations are not supported. 11 | 12 | ## Requirements 13 | 14 | * chef >= 12.6 15 | 16 | ### Certain resource properties are broken in Chef 13. Check the deprecations in the [changelog](https://github.com/gocd/go-cookbook/blob/master/CHANGELOG.md) for more details. 17 | 18 | ## Dependencies 19 | 20 | * apt 21 | * java 22 | * yum 23 | * windows (requires chef >= 12.6; for chef < 12.6 please use these additional dependency version constraints for compatibility with Chef 11: `cookbook 'windows', '< 2.0'`) 24 | 25 | ## Supported Platforms 26 | 27 | This cookbook has been tested on the following platforms: 28 | 29 | * Ubuntu >= 12.04 30 | * Debian 31 | * CentOS >= 6 32 | * RedHat >= 6 33 | * Windows - no support yet, but PRs welcome :) 34 | 35 | ## Usage 36 | 37 | 1. Add this cookbook to your Chef Server, either by installing with knife or by adding it to your Berksfile: `cookbook 'gocd', '~>1.3.2'` 38 | 39 | 2. Change the default configuration [attributes](# Go Server attributes) by overriding the node attributes: 40 | * via a role, or 41 | * by declaring it in another cookbook at a higher precedence levels 42 | 43 | 3. Run the recipes on the specific nodes as: 44 | * `chef-client --runlist 'recipe[gocd]'` - This will install the GoCD server and agent on the same machine 45 | * `chef-client --runlist 'recipe[gocd::server]'` - This will install the GoCD server with specified configuration 46 | * `chef-client --runlist 'recipe[gocd::agent]'` - This will install the GoCD agent with specified configuration. 47 | 48 | OR 49 | 50 | Associate the recipes with the desired roles. Here's an example role with default recipes: 51 | ``` 52 | name 'demo' 53 | description 'Sample role for using the go-cookbook' 54 | 55 | default_attributes( 56 | 'gocd' => { 57 | 'version' => '17.3.0-4669', 58 | 'use_experimental' => true 59 | } 60 | ) 61 | 62 | run_list %w( 63 | recipe[gocd] 64 | ) 65 | ``` 66 | 67 | ## 1.0 release notes 68 | 69 | This cookbook has undergone a major rewrite and has little to do with pre-`1.0` versions. 70 | If you have been using go-cookbook previously then please note that: 71 | 72 | * cookbook has been renamed to `gocd`, just like root namespace of attributes. 73 | * Windows support in on best-effort basis 74 | 75 | ### Java 76 | 77 | Please note that java 8 is recommended to run Go server and agents. This cookbook 78 | sets `node['java']['jdk_version']` at `force_default` level but it may not work properly 79 | when you include `java` in node run_list before `gocd` cookbook. The safest approach 80 | is to set java version in node attributes (in a role or environment). 81 | 82 | ## Install method 83 | 84 | ### Repository 85 | 86 | By default installation source is done from apt or yum repositories from official sources at https://www.gocd.org/download/. 87 | 88 | The **apt** repository can be overridden by changing any these attributes: 89 | 90 | * `node['gocd']['repository']['apt']['uri'] = 'https://download.gocd.org/'` 91 | * `node['gocd']['repository']['apt']['components'] = [ '/' ]` 92 | * `node['gocd']['repository']['apt']['distribution'] = ''` 93 | * `node['gocd']['repository']['apt']['keyserver'] = 'pgp.mit.edu'` 94 | * `node['gocd']['repository']['apt']['key'] = 'https://download.gocd.org/GOCD-GPG-KEY.asc'` 95 | 96 | The **yum** repository can be overridden by changing any these attributes: 97 | 98 | * `node['gocd']['repository']['yum']['baseurl'] = 'https://download.gocd.org'` 99 | * `node['gocd']['repository']['yum']['gpgcheck'] = true` 100 | * `node['gocd']['repository']['yum']['gpgkey'] = 'https://download.gocd.org/GOCD-GPG-KEY.asc'` 101 | 102 | #### Experimental channel 103 | 104 | By default the GoCD cookbook installs latest stable version. 105 | You can install gocd from the experimental channel by setting the `node['gocd']['use_experimental']` attribute to `true` 106 | 107 | ### From remote file 108 | 109 | The cookbook can skip adding a package repository and instead install a GoCD server or agent by downloading a remote file and installing it directly via `dpkg` or `rpm`. To use this method, set `node['gocd']['install_method']` to `'package_file'` and set `node['gocd']['package_file']['baseurl']` to point to the remote file (e.g. `'http://my/custom/url'`) 110 | 111 | The final download URL of file is built based on platform and `node['gocd']['version']` (e.g. using the example baseurl above, `http://my/custom/url/go-agent-15.2.0-2520.deb`) 112 | 113 | # GoCD Server 114 | 115 | `gocd::server` will install and start a GoCD server. 116 | 117 | ## Go Server attributes 118 | 119 | The cookbook provides the following attributes to configure the GoCD server: 120 | 121 | * `node['gocd']['server']['http_port']` - The server HTTP port. Defaults to `8153`. 122 | * `node['gocd']['server']['https_port']` - The server HTTPS port. Defaults to `8154`. 123 | * `node['gocd']['server']['max_mem']` - The server maximum JVM heap space. Defaults to `2048m`. 124 | * `node['gocd']['server']['min_mem']` - The server mimimum JVM heap space. Defaults to `1024m`. 125 | * `node['gocd']['server']['max_perm_gen']` - The server maximum JVM permgen space. Defaults to `400m`. 126 | * `node['gocd']['server']['work_dir']` - The server working directory. Defaults to `/var/lib/go-server` on linux, `C:\GoServer` on Windows. 127 | 128 | Chef cookbook waits for the server to become responsive after restarting 129 | the service. These attributes can be used to tune it: 130 | 131 | * `node['gocd']['server']['wait_up']['retry_delay']` - pause in seconds between failed attempts. 132 | * `node['gocd']['server']['wait_up']['retries']` - number of attempts before giving up. Set 0 to disable waiting at all. Defaults to 10 133 | 134 | # GoCD Agent 135 | 136 | `gocd::agent` will install and start a GoCD agent. You can change the number of agents in `node['gocd']['agent']['count']`. The first 137 | agent is called `go-agent`, next ones are `go-agent-#`. 138 | 139 | `gocd::agent` recipe uses the GoCD agent LWRP internally. 140 | 141 | ## Go Agent attributes 142 | 143 | The cookbook provides the following attributes to configure the GoCD agent: 144 | 145 | * `node['gocd']['agent']['go_server_url']` - URL of Go server that agent should connect to. It must start with `https://` and end with `/go`. For example `https://localhost:8154/go`. 146 | * `node['gocd']['agent']['daemon']` - Whether the agent should be daemonized. Defaults to `true`. 147 | * `node['gocd']['agent']['vnc']['enabled']` - Whether the agent should start with VNC. (Uses `DISPLAY=:3`). Defaults to `false`. 148 | * `node['gocd']['agent']['autoregister']['key']` - The [agent autoregister](https://docs.gocd.org/current/advanced_usage/agent_auto_register.html) key. If left alone, will be auto-detected. Defaults to `nil`. 149 | * `node['gocd']['agent']['autoregister']['environments']` - The environments for the agent. Defaults to `[]`. 150 | * `node['gocd']['agent']['autoregister']['resources']` - The resources for the agent. Defaults to `[]`. 151 | * `node['gocd']['agent']['autoregister']['hostname']` - The agent autoregister hostname. Defaults to `node['fqdn']`. 152 | * `node['gocd']['agent']['server_search_query']` - The chef search query to find a server node. Defaults to `chef_environment:#{node.chef_environment} AND recipes:gocd\\:\\:server`. 153 | 154 | ## Custom Resources 155 | 156 | 1. `gocd_agent` 157 | * Actions: 158 | - `:create` 159 | - `:delete` 160 | 161 | * Attributes: 162 | 163 | | Attribute Name | Default | Description | 164 | |:--------------------------|:-------------:|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| 165 | | agent_name | create | Name of the resource to be created or deleted. | 166 | | service_action | enable, start | The GoCD agent service supports `:status`, `:enable`, `:start`, `:restart`, `:stop` | 167 | | user | go | The user that can start and configure the GoCD agents. | 168 | | group | go | The group of users that can configure the GoCD agents. | 169 | | go_server_url | nil | The url of the GoCD server that the agent has to connect to. It should begin with `https`, should connect to the `GO_SERVER_SSL_PORT`, and end with `/go`. If this isn't set, then the go server ip is detected (provided go server is also installed using chef). The fallback option is `https://localhost:8154/go` | 170 | | daemon | true | Whether to start the GoCD agent as a daemon process. | 171 | | autoregister_key | nil | The autoregister key can be used to directly register the agent with the GoCD server without manual intervention. | 172 | | autoregister_hostname | nil | The name by which the agent will be known to the GoCD server | 173 | | autoregister_environments | nil | The GoCD environments to which the agent must belong to. | 174 | | environments | nil | The GoCD environments to which the agent must belong to. This is DEPRECATED. | 175 | | autoregister_resources | nil | The resources available on the gocd agent node which can be used with specific pipeline(s). | 176 | | resources | nil | The resources available on the gocd agent node which can be used with specific pipeline(s). This is DEPRECATED. | 177 | | elastic_agent_id | nil | The elastic agent id used to set the autoregister property `agent.auto.register.elasticAgent.agentId`. | 178 | | elastic_agent_plugin_id | nil | The elastic agent plugin id. This is used to set the autoregister property `agent.auto.register.elasticAgent.pluginId` | 179 | 180 | *Note:* All of the above attributes are optional. 181 | 182 | 2. `gocd_agent_autoregister_file` 183 | 184 | This resource will create a file called `autoregister.properties` in the gocd agent's config directory. This is done so that the agent can directly register with the gocd server without manual intervention. 185 | 186 | * Actions 187 | - `:create` 188 | - `:delete` 189 | 190 | * Attributes 191 | 192 | | Attribute Name | Default | Description | 193 | |:--------------------------|:-------:|:------------------------------------------------------------------------------------------------------------------------------------| 194 | | owner | go | owner of the autoregister.properties file | 195 | | group | go | group for the autoregister.properties file | 196 | | autoregister_key | nil | The autogregister key from the go server config that can be used to register the agent | 197 | | autoregister_hostname | nil | The name by which the agent will be known to the GoCD server | 198 | | autoregister_environments | nil | The GoCD environments to which the agent must belong to. | 199 | | environments | nil | The GoCD environments to which the agent must belong to. This is DEPRECATED. | 200 | | autoregister_resources | nil | The resources available on the gocd agent node which can be used with specific pipeline(s). | 201 | | resources | nil | The resources available on the gocd agent node which can be used with specific pipeline(s). This is DEPRECATED. | 202 | | elastic_agent_id | nil | The elastic agent id used to set the autoregister property `agent.auto.register.elasticAgent.agentId`. | 203 | | elastic_agent_plugin_id | nil | The elastic agent plugin id. This is used to set the autoregister property `agent.auto.register.elasticAgent.pluginId` | 204 | 205 | 3. `gocd_plugin` 206 | 207 | | Attribute Name | Default | Required | Description | 208 | |:----------------|:--------------------:|:--------:|:--------------------------------------------------------------------------------------| 209 | | plugin_name | nil | true | Name of the plugin | 210 | | plugin_uri | nil | true | Location of the plugin jar on the workstation. | 211 | | server_work_dir | `/var/lib/go-server` | false | The working directory of the go server to where the plguin jar needs to be copied to. | 212 | 213 | 214 | ### Beta 215 | 216 | Attributes for elastic agents: 217 | 218 | * `node['gocd']['agent']['elastic']['plugin_id']` - The elastic agent plugin id. This is used to set the autoregister property `agent.auto.register.elasticAgent.pluginId` 219 | * `node['gocd']['agent']['elastic']['agent_id']` - The elastic agent id used to set the autoregister property `agent.auto.register.elasticAgent.agentId`. 220 | 221 | ### Deprecated 222 | 223 | Please use `node['gocd']['agent']['go_server_url']` instead of the following deprecated attributes: 224 | 225 | * `node['gocd']['agent']['go_server_host']` - The hostname of the go server (if left alone, will be auto-detected). Defaults to `nil`. 226 | * `node['gocd']['agent']['go_server_port']` - The port of the go server. Defaults to `8153`. 227 | 228 | # GoCD Agent LWRP (currently only works on linux) 229 | 230 | If the agent recipe + attributes is not flexible enough or if you prefer chef resources 231 | then you can add go-agent services with the `gocd_agent` LWRP. 232 | 233 | ### Example agents 234 | 235 | All resource attributes fall back to node attributes so agent can be defined 236 | in just one line: 237 | 238 | ```ruby 239 | gocd_agent 'my-agent' 240 | ``` 241 | 242 | It would create `my-agent` service and if all node values are correct then it 243 | would also autoregister. 244 | 245 | A custom agent may look like this: 246 | ```ruby 247 | gocd_agent 'my-go-agent' do 248 | go_server_host 'go.example.com' 249 | go_server_port 80 250 | daemon true 251 | vnc true 252 | autoregister_key 'bla-key' 253 | autoregister_hostname 'my-lwrp-agent' 254 | autoregister_environments 'production' 255 | autoregister_resources ['java-8','ruby-2.2'] 256 | workspace '/mnt/big_drive' 257 | end 258 | ``` 259 | 260 | # GoCD autoregister file resource 261 | 262 | If you want to set up agents *your-way* then this resource is helpful to **only** 263 | generate a valid `autoregister.properties` file: 264 | 265 | Example use: 266 | ```ruby 267 | gocd_agent_autoregister_file '/var/mygo/autoregister.properties' do 268 | autoregister_key 'bla-key' 269 | autoregister_hostname 'mygo-agent' 270 | autoregister_environments 'stage' 271 | autoregister_resources ['java-8','ruby'] 272 | end 273 | ``` 274 | 275 | Can be used to prepare elastic agents too: 276 | ```ruby 277 | gocd_agent_autoregister_file '/var/elastic/autoregister.properties' do 278 | autoregister_key 'some-key' 279 | autoregister_hostname 'elastic-agent' 280 | autoregister_environments 'testing' 281 | autoregister_resources ['java-8'] 282 | elastic_agent_id 'agent-id' 283 | elastic_agent_plugin_id 'elastic-agent-plugin-id' 284 | end 285 | ``` 286 | 287 | # GoCD plugin LWRP 288 | 289 | You can install Go server plugins with the `gocd_plugin` LWRP like this 290 | 291 | ```ruby 292 | include_recipe 'gocd::server' 293 | 294 | gocd_plugin 'github-pr-status' do 295 | plugin_uri 'https://github.com/gocd-contrib/gocd-build-status-notifier/releases/download/1.1/github-pr-status-1.1.jar' 296 | end 297 | ``` 298 | 299 | # Server Specification 300 | 301 | When using the cookbook please refer to the [server specification section](https://docs.gocd.org/current/installation/system_requirements.html) of the GoCD documentation. 302 | 303 | # License 304 | 305 | Apache License, Version 2.0 306 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | ########################################################################## 2 | # Copyright 2017 ThoughtWorks, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ########################################################################## 16 | 17 | require 'foodcritic' 18 | require 'kitchen' 19 | require 'rspec/core/rake_task' 20 | require 'cookstyle' 21 | require 'rubocop/rake_task' 22 | 23 | # Style tests. Rubocop and Foodcritic 24 | namespace :style do 25 | desc 'Run Ruby style checks' 26 | RuboCop::RakeTask.new(:ruby) do |task| 27 | task.options << '--display-cop-names' 28 | # task.options << '--auto-correct' # use it for fixing linting errors locally 29 | end 30 | 31 | desc 'Run Chef style checks' 32 | FoodCritic::Rake::LintTask.new(:chef) do |t| 33 | t.options = { 34 | fail_tags: ['any'], 35 | tags: %w(~FC005), 36 | } 37 | end 38 | end 39 | 40 | desc 'Run all style checks' 41 | task style: ['style:ruby', 'style:chef'] 42 | 43 | task unit: ['unit:chefspec'] 44 | namespace 'unit' do 45 | desc 'Run Chefspec tests of this cookbook (spec/*_spec.rb)' 46 | RSpec::Core::RakeTask.new(:chefspec_internal) do |t| 47 | t.pattern = 'spec/**/*_spec.rb' 48 | t.rspec_opts = [].tap do |a| 49 | a.push('--color') 50 | a.push('--format documentation') 51 | a.push('--format h') 52 | a.push('--out ./chefspec.html') 53 | end.join(' ') 54 | end 55 | 56 | desc 'Run Chefspec tests of this cookbook (spec/*_spec.rb), updates deps' 57 | task chefspec: [:chefspec_internal] 58 | 59 | desc 'Remove all .html reports files' 60 | task :clean_reports do 61 | Dir['./**/*.html'].each do |file_path| 62 | rm file_path 63 | end 64 | end 65 | end 66 | 67 | # Integration tests. Kitchen.ci 68 | namespace :integration do 69 | desc 'Run Test Kitchen with Vagrant' 70 | task :vagrant do 71 | Kitchen.logger = Kitchen.default_file_logger 72 | Kitchen::Config.new.instances.each do |instance| 73 | instance.test(:always) 74 | end 75 | end 76 | 77 | desc 'Run Test Kitchen with cloud plugins' 78 | task :cloud, :pattern do 79 | Kitchen.logger = Kitchen.default_file_logger 80 | @loader = Kitchen::Loader::YAML.new(project_config: './.kitchen.cloud.yml') 81 | config = Kitchen::Config.new(loader: @loader) 82 | config.instances.each do |instance| 83 | instance.test(:always) 84 | end 85 | end 86 | 87 | desc 'Run Test Kitchen with openstack (private)' 88 | task :openstack do 89 | Kitchen.logger = Kitchen.default_file_logger 90 | @loader = Kitchen::Loader::YAML.new(project_config: './.kitchen.openstack.yml') 91 | config = Kitchen::Config.new(loader: @loader) 92 | config.instances.each do |instance| 93 | instance.test(:always) 94 | end 95 | end 96 | 97 | desc 'Run Test Kitchen with docker' 98 | task :docker do 99 | Kitchen.logger = Kitchen.default_file_logger 100 | @loader = Kitchen::Loader::YAML.new(project_config: './.kitchen.docker.yml') 101 | config = Kitchen::Config.new(loader: @loader) 102 | config.instances.each do |instance| 103 | instance.test(:always) 104 | end 105 | end 106 | end 107 | 108 | # Default 109 | task default: ['style', 'integration:vagrant'] 110 | -------------------------------------------------------------------------------- /TESTING.md: -------------------------------------------------------------------------------- 1 | Cookbook TESTING doc 2 | ==================== 3 | 4 | Bundler 5 | ------- 6 | A ruby environment with Bundler installed is a prerequisite for using 7 | the testing harness shipped with this cookbook. At the time of this 8 | writing, it works with Ruby 1.9.3 and Bundler 1.6.2. All programs 9 | involved, with the exception of Vagrant, can be installed by cd'ing 10 | into the parent directory of this cookbook and running "bundle install" 11 | 12 | Rakefile 13 | -------- 14 | The Rakefile ships with a number of tasks, each of which can be ran 15 | individually, or in groups. Typing "rake" by itself will perform style 16 | checks with Foodcritic and integration tests with Test Kitchen using 17 | the Vagrant driver by default. 18 | 19 | ``` 20 | $ rake -T 21 | rake integration:cloud # Run Test Kitchen cloud plugins 22 | rake integration:vagrant # Run Test Kitchen with Vagrant 23 | rake style # Run all style checks 24 | rake style:chef # Lint Chef cookbooks 25 | ``` 26 | 27 | Style Testing 28 | ------------- 29 | Chef style tests can be performed with Foodcritic by issuing either 30 | ``` 31 | bundle exec foodcritic 32 | ``` 33 | or 34 | ``` 35 | rake style:chef 36 | ``` 37 | 38 | Integration Testing 39 | ------------------- 40 | Integration testing is performed by Test Kitchen. After a 41 | successful converge, tests are uploaded and ran out of band of 42 | Chef. Tests should be designed to ensure that a recipe has 43 | accomplished its goal. 44 | 45 | Integration Testing using Vagrant 46 | --------------------------------- 47 | Integration tests using Vagrant can be performed with either 48 | ``` 49 | bundle exec kitchen test 50 | ``` 51 | or 52 | ``` 53 | rake integration:vagrant 54 | ``` 55 | 56 | Integration Testing using Cloud providers 57 | ----------------------------------------- 58 | Integration tests can be performed on cloud providers using Test Kitchen plugins. This cookbook ships a .kitchen.cloud.yml that references environmental variables present in the shell that kitchen test is ran from. These usually contain authentication tokens for driving IaaS APIs, as well as the paths to ssh private keys needed for Test Kitchen log into them after they've been created. 59 | 60 | Examples of environment variables being set in ~/.bash_profile: 61 | 62 | ``` 63 | # digitalocean (APIv1) 64 | export DIGITALOCEAN_API_KEY='your_bits_here' 65 | export DIGITALOCEAN_CLIENT_ID='your_bits_here' 66 | export DIGITALOCEAN_SSH_KEY_IDS='your_bits_here' #CSV String of IDs 67 | export DIGITALOCEAN_SSH_KEY_PATH='your_bits_here' 68 | 69 | #ec2 70 | export AWS_ACCESS_KEY='your_bits_here' 71 | export AWS_SECRET_KEY='your_bits_here' 72 | export AWS_SECURITY_GROUP='your_bits_here' 73 | export AWS_SSH_KEY_ID='your_bits_here' 74 | export AWS_SSH_KEY_PATH='your_bits_here' 75 | ``` 76 | 77 | **Note:** There is currently a bug in kitchen-digitalocean (0.8.2) which forces DIGITALOCEAN_SSH_KEY_IDS to require at least two entires. It is prefectly fine however to use the same key id twice. 78 | 79 | Integration tests using cloud drivers can be performed with either 80 | ``` 81 | export KITCHEN_YAML=.kitchen.cloud.yml 82 | bundle exec kitchen test 83 | ``` 84 | or 85 | ``` 86 | rake integration:cloud 87 | ``` 88 | -------------------------------------------------------------------------------- /attributes/agent.rb: -------------------------------------------------------------------------------- 1 | ########################################################################## 2 | # Copyright 2017 ThoughtWorks, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ########################################################################## 16 | 17 | default['gocd']['agent']['go_server_url'] = nil 18 | default['gocd']['agent']['daemon'] = true 19 | 20 | default['gocd']['agent']['vnc']['enabled'] = false 21 | 22 | default['gocd']['agent']['autoregister']['key'] = nil 23 | default['gocd']['agent']['autoregister']['environments'] = %w() 24 | default['gocd']['agent']['autoregister']['resources'] = %w() 25 | default['gocd']['agent']['autoregister']['hostname'] = node['fqdn'] 26 | 27 | default['gocd']['agent']['elastic']['plugin_id'] = nil 28 | default['gocd']['agent']['elastic']['agent_id'] = nil 29 | 30 | default['gocd']['agent']['server_search_query'] = "chef_environment:#{node.chef_environment} AND recipes:gocd\\:\\:server" 31 | default['gocd']['agent']['workspace'] = nil # '/var/lib/go-agent' on linux 32 | default['gocd']['agent']['count'] = 1 33 | default['gocd']['agent']['default_extras'] = {} 34 | -------------------------------------------------------------------------------- /attributes/repository.rb: -------------------------------------------------------------------------------- 1 | ########################################################################## 2 | # Copyright 2017 ThoughtWorks, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ########################################################################## 16 | 17 | default['gocd']['version'] = nil # can be `latest` or specify a version `X.Y.Z-ABCD` 18 | default['gocd']['use_experimental'] = false 19 | 20 | default['gocd']['install_method'] = if node['platform_family'] == 'windows' 21 | 'package_file' 22 | else 23 | 'repository' 24 | end 25 | 26 | default['gocd']['updates']['url'] = nil 27 | 28 | default['gocd']['repository']['apt']['components'] = ['/'] 29 | default['gocd']['repository']['apt']['distribution'] = '' 30 | default['gocd']['repository']['apt']['keyserver'] = 'pgp.mit.edu' 31 | default['gocd']['repository']['apt']['key'] = 'https://download.gocd.org/GOCD-GPG-KEY.asc' 32 | 33 | default['gocd']['repository']['yum']['gpgcheck'] = true 34 | default['gocd']['repository']['yum']['gpgkey'] = 'https://download.gocd.org/GOCD-GPG-KEY.asc' 35 | 36 | default['gocd']['package_file']['baseurl'] = nil # official - "https://download.gocd.org/binaries" 37 | default['gocd']['agent']['package_file']['url'] = nil # official 38 | default['gocd']['server']['package_file']['url'] = nil # official 39 | -------------------------------------------------------------------------------- /attributes/server.rb: -------------------------------------------------------------------------------- 1 | ########################################################################## 2 | # Copyright 2017 ThoughtWorks, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ########################################################################## 16 | 17 | default['gocd']['server']['http_port'] = 8153 18 | default['gocd']['server']['https_port'] = 8154 19 | default['gocd']['server']['max_mem'] = '2048m' 20 | default['gocd']['server']['min_mem'] = '1024m' 21 | default['gocd']['server']['max_perm_gen'] = '400m' 22 | default['gocd']['server']['work_dir'] = '/var/lib/go-server' 23 | 24 | default['gocd']['server']['work_dir'] = 'C:\GoServer' if platform?('windows') 25 | 26 | default['gocd']['server']['wait_up']['retry_delay'] = 10 27 | default['gocd']['server']['wait_up']['retries'] = 10 28 | default['gocd']['server']['default_extras'] = {} 29 | -------------------------------------------------------------------------------- /chefignore: -------------------------------------------------------------------------------- 1 | # Put files/directories that should be ignored in this file when uploading 2 | # or sharing to the community site. 3 | # Lines that start with '# ' are comments. 4 | 5 | # OS generated files # 6 | ###################### 7 | .DS_Store 8 | Icon? 9 | nohup.out 10 | ehthumbs.db 11 | Thumbs.db 12 | 13 | # SASS # 14 | ######## 15 | .sass-cache 16 | 17 | # EDITORS # 18 | ########### 19 | \#* 20 | .#* 21 | *~ 22 | *.sw[a-z] 23 | *.bak 24 | REVISION 25 | TAGS* 26 | tmtags 27 | *_flymake.* 28 | *_flymake 29 | *.tmproj 30 | .project 31 | .settings 32 | mkmf.log 33 | 34 | ## COMPILED ## 35 | ############## 36 | a.out 37 | *.o 38 | *.pyc 39 | *.so 40 | *.com 41 | *.class 42 | *.dll 43 | *.exe 44 | */rdoc/ 45 | 46 | # Testing # 47 | ########### 48 | .watchr 49 | .rspec 50 | spec/* 51 | spec/fixtures/* 52 | test/* 53 | features/* 54 | Guardfile 55 | Procfile 56 | 57 | # SCM # 58 | ####### 59 | .git 60 | */.git 61 | .gitignore 62 | .gitmodules 63 | .gitconfig 64 | .gitattributes 65 | .svn 66 | */.bzr/* 67 | */.hg/* 68 | */.svn/* 69 | 70 | # Berkshelf # 71 | ############# 72 | Berksfile 73 | Berksfile.lock 74 | cookbooks/* 75 | tmp 76 | 77 | # Cookbooks # 78 | ############# 79 | CONTRIBUTING 80 | CHANGELOG* 81 | 82 | # Strainer # 83 | ############ 84 | Colanderfile 85 | Strainerfile 86 | .colander 87 | .strainer 88 | 89 | # Vagrant # 90 | ########### 91 | .vagrant 92 | Vagrantfile 93 | 94 | # Travis # 95 | ########## 96 | .travis.yml 97 | -------------------------------------------------------------------------------- /ci-setup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | wget https://opscode-omnibus-packages.s3.amazonaws.com/ubuntu/12.04/x86_64/chefdk_0.10.0-1_amd64.deb -qc -O "${HOME}/.chefdk_0.10.0-1_amd64.deb" 4 | sudo dpkg -i "${HOME}/.chefdk_0.10.0-1_amd64.deb" 5 | eval "$(chef shell-init bash)" 6 | sudo $(which chef) gem install bundler 7 | sudo $(which chef) exec bundle install 8 | -------------------------------------------------------------------------------- /config/cookstyle.yml: -------------------------------------------------------------------------------- 1 | ########################################################################## 2 | # Copyright 2017 ThoughtWorks, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ########################################################################## 16 | 17 | AllCops: 18 | Exclude: 19 | - vendor/**/* 20 | - Guardfile 21 | 22 | Style/AccessModifierIndentation: 23 | Enabled: true 24 | Style/AccessorMethodName: 25 | Enabled: true 26 | Style/Alias: 27 | Enabled: true 28 | Style/AlignArray: 29 | Enabled: true 30 | Style/AlignHash: 31 | Enabled: true 32 | Style/AlignParameters: 33 | Enabled: true 34 | Style/AndOr: 35 | Enabled: true 36 | Style/ArrayJoin: 37 | Enabled: true 38 | Style/AsciiComments: 39 | Enabled: true 40 | Style/AsciiIdentifiers: 41 | Enabled: true 42 | Style/Attr: 43 | Enabled: true 44 | Style/BeginBlock: 45 | Enabled: true 46 | Style/BarePercentLiterals: 47 | Enabled: true 48 | Style/BlockComments: 49 | Enabled: true 50 | Style/BlockEndNewline: 51 | Enabled: true 52 | Style/BlockDelimiters: 53 | Enabled: true 54 | Style/BracesAroundHashParameters: 55 | Enabled: true 56 | Style/CaseEquality: 57 | Enabled: true 58 | Style/CaseIndentation: 59 | Enabled: true 60 | Style/CharacterLiteral: 61 | Enabled: true 62 | Style/ClassAndModuleCamelCase: 63 | Enabled: true 64 | Style/ClassAndModuleChildren: 65 | Enabled: true 66 | Style/ClassCheck: 67 | Enabled: true 68 | Style/ClassMethods: 69 | Enabled: true 70 | Style/ClassVars: 71 | Enabled: true 72 | Style/ClosingParenthesisIndentation: 73 | Enabled: true 74 | Style/ColonMethodCall: 75 | Enabled: true 76 | Style/CommandLiteral: 77 | Enabled: true 78 | Style/CommentAnnotation: 79 | Enabled: true 80 | Style/CommentIndentation: 81 | Enabled: true 82 | Style/ConditionalAssignment: 83 | Enabled: true 84 | Style/ConstantName: 85 | Enabled: true 86 | Style/DefWithParentheses: 87 | Enabled: true 88 | Style/PreferredHashMethods: 89 | Enabled: true 90 | Style/Documentation: 91 | Enabled: true 92 | Style/DotPosition: 93 | Enabled: true 94 | Style/DoubleNegation: 95 | Enabled: true 96 | Style/EachWithObject: 97 | Enabled: true 98 | Style/ElseAlignment: 99 | Enabled: true 100 | Style/EmptyElse: 101 | Enabled: true 102 | Style/EmptyLineBetweenDefs: 103 | Enabled: true 104 | Style/EmptyLines: 105 | Enabled: true 106 | Style/EmptyLinesAroundAccessModifier: 107 | Enabled: true 108 | Style/EmptyLinesAroundBlockBody: 109 | Enabled: true 110 | Style/EmptyLinesAroundClassBody: 111 | Enabled: true 112 | Style/EmptyLinesAroundModuleBody: 113 | Enabled: true 114 | Style/EmptyLinesAroundMethodBody: 115 | Enabled: true 116 | Style/EmptyLiteral: 117 | Enabled: true 118 | Style/EndBlock: 119 | Enabled: true 120 | Style/EndOfLine: 121 | Enabled: true 122 | Style/EvenOdd: 123 | Enabled: true 124 | Style/ExtraSpacing: 125 | Enabled: true 126 | Style/FileName: 127 | Enabled: true 128 | Style/FrozenStringLiteralComment: 129 | Enabled: true 130 | Style/InitialIndentation: 131 | Enabled: true 132 | Style/FirstParameterIndentation: 133 | Enabled: true 134 | Style/FlipFlop: 135 | Enabled: true 136 | Style/For: 137 | Enabled: true 138 | Style/FormatString: 139 | Enabled: true 140 | Style/GlobalVars: 141 | Enabled: true 142 | Style/GuardClause: 143 | Enabled: true 144 | Style/HashSyntax: 145 | Enabled: true 146 | Style/IfInsideElse: 147 | Enabled: true 148 | Style/IfUnlessModifier: 149 | Enabled: true 150 | Style/IfWithSemicolon: 151 | Enabled: true 152 | Style/IndentationConsistency: 153 | Enabled: true 154 | Style/IndentationWidth: 155 | Enabled: true 156 | Style/IdenticalConditionalBranches: 157 | Enabled: true 158 | Style/IndentArray: 159 | Enabled: true 160 | Style/IndentAssignment: 161 | Enabled: true 162 | Style/IndentHash: 163 | Enabled: true 164 | Style/InfiniteLoop: 165 | Enabled: true 166 | Style/Lambda: 167 | Enabled: true 168 | Style/LambdaCall: 169 | Enabled: true 170 | Style/LeadingCommentSpace: 171 | Enabled: true 172 | Style/LineEndConcatenation: 173 | Enabled: true 174 | Style/MethodCallParentheses: 175 | Enabled: true 176 | Style/MethodDefParentheses: 177 | Enabled: true 178 | Style/MethodName: 179 | Enabled: true 180 | Style/ModuleFunction: 181 | Enabled: true 182 | Style/MultilineBlockChain: 183 | Enabled: true 184 | Style/MultilineBlockLayout: 185 | Enabled: true 186 | Style/MultilineIfThen: 187 | Enabled: true 188 | Style/MultilineMethodCallIndentation: 189 | Enabled: true 190 | Style/MultilineOperationIndentation: 191 | Enabled: true 192 | Style/MultilineTernaryOperator: 193 | Enabled: true 194 | Style/MutableConstant: 195 | Enabled: true 196 | Style/NegatedIf: 197 | Enabled: true 198 | Style/NegatedWhile: 199 | Enabled: true 200 | Style/NestedModifier: 201 | Enabled: true 202 | Style/NestedParenthesizedCalls: 203 | Enabled: true 204 | Style/NestedTernaryOperator: 205 | Enabled: true 206 | Style/Next: 207 | Enabled: true 208 | Style/NilComparison: 209 | Enabled: true 210 | Style/NonNilCheck: 211 | Enabled: true 212 | Style/Not: 213 | Enabled: true 214 | Style/NumericLiterals: 215 | Enabled: true 216 | Style/OneLineConditional: 217 | Enabled: true 218 | Style/OpMethod: 219 | Enabled: true 220 | Style/OptionalArguments: 221 | Enabled: true 222 | Style/ParallelAssignment: 223 | Enabled: true 224 | Style/ParenthesesAroundCondition: 225 | Enabled: true 226 | Style/PercentLiteralDelimiters: 227 | Enabled: true 228 | Style/PercentQLiterals: 229 | Enabled: true 230 | Style/PerlBackrefs: 231 | Enabled: true 232 | Style/PredicateName: 233 | Enabled: true 234 | Style/Proc: 235 | Enabled: true 236 | Style/RaiseArgs: 237 | Enabled: true 238 | Style/RedundantBegin: 239 | Enabled: true 240 | Style/RedundantException: 241 | Enabled: true 242 | Style/RedundantFreeze: 243 | Enabled: true 244 | Style/RedundantParentheses: 245 | Enabled: true 246 | Style/RedundantReturn: 247 | Enabled: true 248 | Style/RedundantSelf: 249 | Enabled: true 250 | Style/RegexpLiteral: 251 | Enabled: true 252 | Style/RescueEnsureAlignment: 253 | Enabled: true 254 | Style/RescueModifier: 255 | Enabled: true 256 | Style/SelfAssignment: 257 | Enabled: true 258 | Style/Semicolon: 259 | Enabled: true 260 | Style/SignalException: 261 | Enabled: true 262 | Style/SingleLineBlockParams: 263 | Enabled: true 264 | Style/SingleLineMethods: 265 | Enabled: true 266 | Style/SpaceBeforeFirstArg: 267 | Enabled: true 268 | Style/SpaceAfterColon: 269 | Enabled: true 270 | Style/SpaceAfterComma: 271 | Enabled: true 272 | Style/SpaceAfterMethodName: 273 | Enabled: true 274 | Style/SpaceAfterNot: 275 | Enabled: true 276 | Style/SpaceAfterSemicolon: 277 | Enabled: true 278 | Style/SpaceBeforeBlockBraces: 279 | Enabled: true 280 | Style/SpaceBeforeComma: 281 | Enabled: true 282 | Style/SpaceBeforeComment: 283 | Enabled: true 284 | Style/SpaceBeforeSemicolon: 285 | Enabled: true 286 | Style/SpaceInsideBlockBraces: 287 | Enabled: true 288 | Style/SpaceAroundBlockParameters: 289 | Enabled: true 290 | Style/SpaceAroundEqualsInParameterDefault: 291 | Enabled: true 292 | Style/SpaceAroundKeyword: 293 | Enabled: true 294 | Style/SpaceAroundOperators: 295 | Enabled: true 296 | Style/SpaceInsideBrackets: 297 | Enabled: true 298 | Style/SpaceInsideHashLiteralBraces: 299 | Enabled: true 300 | Style/SpaceInsideParens: 301 | Enabled: true 302 | Style/SpaceInsideRangeLiteral: 303 | Enabled: true 304 | Style/SpaceInsideStringInterpolation: 305 | Enabled: true 306 | Style/SpecialGlobalVars: 307 | Enabled: true 308 | Style/StabbyLambdaParentheses: 309 | Enabled: true 310 | Style/StringLiterals: 311 | Enabled: false 312 | Style/StringLiteralsInInterpolation: 313 | Enabled: true 314 | Style/StructInheritance: 315 | Enabled: true 316 | Style/SymbolLiteral: 317 | Enabled: true 318 | Style/SymbolProc: 319 | Enabled: true 320 | Style/Tab: 321 | Enabled: true 322 | Style/TrailingBlankLines: 323 | Enabled: true 324 | Style/TrailingCommaInArguments: 325 | Enabled: true 326 | Style/TrailingCommaInLiteral: 327 | Enabled: true 328 | Style/TrailingWhitespace: 329 | Enabled: true 330 | Style/TrivialAccessors: 331 | Enabled: true 332 | Style/UnlessElse: 333 | Enabled: true 334 | Style/UnneededCapitalW: 335 | Enabled: true 336 | Style/UnneededInterpolation: 337 | Enabled: true 338 | Style/UnneededPercentQ: 339 | Enabled: true 340 | Style/TrailingUnderscoreVariable: 341 | Enabled: true 342 | Style/VariableInterpolation: 343 | Enabled: true 344 | Style/VariableName: 345 | Enabled: true 346 | Style/WhenThen: 347 | Enabled: true 348 | Style/WhileUntilDo: 349 | Enabled: true 350 | Style/WhileUntilModifier: 351 | Enabled: true 352 | Style/WordArray: 353 | Enabled: true 354 | Style/ZeroLengthPredicate: 355 | Enabled: true 356 | Metrics/AbcSize: 357 | Enabled: true 358 | Metrics/BlockNesting: 359 | Enabled: true 360 | Metrics/ClassLength: 361 | Enabled: true 362 | Metrics/ModuleLength: 363 | Enabled: true 364 | Metrics/CyclomaticComplexity: 365 | Enabled: true 366 | Metrics/LineLength: 367 | Enabled: true 368 | Metrics/MethodLength: 369 | Enabled: true 370 | Metrics/ParameterLists: 371 | Enabled: true 372 | Metrics/PerceivedComplexity: 373 | Enabled: true 374 | Lint/AmbiguousOperator: 375 | Enabled: true 376 | Lint/AmbiguousRegexpLiteral: 377 | Enabled: true 378 | Lint/AssignmentInCondition: 379 | Enabled: true 380 | Lint/BlockAlignment: 381 | Enabled: true 382 | Lint/CircularArgumentReference: 383 | Enabled: true 384 | Lint/ConditionPosition: 385 | Enabled: true 386 | Lint/Debugger: 387 | Enabled: true 388 | Lint/DefEndAlignment: 389 | Enabled: true 390 | Lint/DeprecatedClassMethods: 391 | Enabled: true 392 | Lint/DuplicateMethods: 393 | Enabled: true 394 | Lint/DuplicatedKey: 395 | Enabled: true 396 | Lint/EachWithObjectArgument: 397 | Enabled: true 398 | Lint/ElseLayout: 399 | Enabled: true 400 | Lint/EmptyEnsure: 401 | Enabled: true 402 | Lint/EmptyInterpolation: 403 | Enabled: true 404 | Lint/EndAlignment: 405 | Enabled: true 406 | Lint/EndInMethod: 407 | Enabled: true 408 | Lint/EnsureReturn: 409 | Enabled: true 410 | Lint/Eval: 411 | Enabled: true 412 | Lint/FloatOutOfRange: 413 | Enabled: true 414 | Lint/FormatParameterMismatch: 415 | Enabled: true 416 | Lint/HandleExceptions: 417 | Enabled: true 418 | Lint/ImplicitStringConcatenation: 419 | Enabled: true 420 | Lint/IneffectiveAccessModifier: 421 | Enabled: true 422 | Lint/InvalidCharacterLiteral: 423 | Enabled: true 424 | Lint/LiteralInCondition: 425 | Enabled: true 426 | Lint/LiteralInInterpolation: 427 | Enabled: true 428 | Lint/Loop: 429 | Enabled: true 430 | Lint/NestedMethodDefinition: 431 | Enabled: true 432 | Lint/NextWithoutAccumulator: 433 | Enabled: true 434 | Lint/NonLocalExitFromIterator: 435 | Enabled: true 436 | Lint/ParenthesesAsGroupedExpression: 437 | Enabled: true 438 | Lint/RandOne: 439 | Enabled: true 440 | Lint/RequireParentheses: 441 | Enabled: true 442 | Lint/RescueException: 443 | Enabled: true 444 | Lint/ShadowingOuterLocalVariable: 445 | Enabled: true 446 | Lint/StringConversionInInterpolation: 447 | Enabled: true 448 | Lint/UnderscorePrefixedVariableName: 449 | Enabled: true 450 | Lint/UnneededDisable: 451 | Enabled: true 452 | Lint/UnusedBlockArgument: 453 | Enabled: true 454 | Lint/UnusedMethodArgument: 455 | Enabled: true 456 | Lint/UnreachableCode: 457 | Enabled: true 458 | Lint/UselessAccessModifier: 459 | Enabled: true 460 | Lint/UselessAssignment: 461 | Enabled: true 462 | Lint/UselessComparison: 463 | Enabled: true 464 | Lint/UselessElseWithoutRescue: 465 | Enabled: true 466 | Lint/UselessSetterCall: 467 | Enabled: true 468 | Lint/Void: 469 | Enabled: true 470 | Performance/Casecmp: 471 | Enabled: true 472 | Performance/CaseWhenSplat: 473 | Enabled: true 474 | Performance/Count: 475 | Enabled: true 476 | Performance/Detect: 477 | Enabled: true 478 | Performance/DoubleStartEndWith: 479 | Enabled: true 480 | Performance/EndWith: 481 | Enabled: true 482 | Performance/FixedSize: 483 | Enabled: true 484 | Performance/FlatMap: 485 | Enabled: true 486 | EnabledForFlattenWithoutParams: false 487 | Performance/HashEachMethods: 488 | Enabled: true 489 | Performance/LstripRstrip: 490 | Enabled: true 491 | Performance/RangeInclude: 492 | Enabled: true 493 | Performance/RedundantBlockCall: 494 | Enabled: true 495 | Performance/RedundantMatch: 496 | Enabled: true 497 | Performance/RedundantMerge: 498 | Enabled: true 499 | Performance/RedundantSortBy: 500 | Enabled: true 501 | Performance/ReverseEach: 502 | Enabled: true 503 | Performance/Sample: 504 | Enabled: true 505 | Performance/Size: 506 | Enabled: true 507 | Performance/StartWith: 508 | Enabled: true 509 | Performance/StringReplacement: 510 | Enabled: true 511 | Performance/TimesMap: 512 | Enabled: true 513 | Rails/ActionFilter: 514 | Enabled: true 515 | Rails/Date: 516 | Enabled: true 517 | Rails/Delegate: 518 | Enabled: true 519 | Rails/FindBy: 520 | Enabled: true 521 | Rails/FindEach: 522 | Enabled: true 523 | Rails/HasAndBelongsToMany: 524 | Enabled: true 525 | Rails/Output: 526 | Enabled: true 527 | Rails/PluralizationGrammar: 528 | Enabled: true 529 | Rails/ReadWriteAttribute: 530 | Enabled: true 531 | Rails/ScopeArgs: 532 | Enabled: true 533 | Rails/TimeZone: 534 | Enabled: true 535 | Rails/Validation: 536 | Enabled: true 537 | -------------------------------------------------------------------------------- /libraries/helpers.rb: -------------------------------------------------------------------------------- 1 | ########################################################################## 2 | # Copyright 2017 ThoughtWorks, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ########################################################################## 16 | 17 | require 'open-uri' 18 | 19 | module Gocd 20 | module Helpers 21 | def fetch_content(url) 22 | open(url, 'r').read 23 | end 24 | 25 | def agent_properties 26 | values = {} 27 | values[:go_server_url] = node['gocd']['agent']['go_server_url'] 28 | if Chef::Config['solo'] || node['gocd']['agent']['go_server_url'] 29 | Chef::Log.info("Attempting to use node['gocd']['agent']['go_server_url'] attribute for server url") 30 | values[:go_server_url] = node['gocd']['agent']['go_server_url'] 31 | values[:key] = node['gocd']['agent']['autoregister']['key'] 32 | else 33 | server_search_query = node['gocd']['agent']['server_search_query'] 34 | Chef::Log.info("Search query: #{server_search_query}") 35 | go_servers = search(:node, server_search_query) 36 | if go_servers.count == 0 37 | Chef::Log.warn('No Go servers found on any of the nodes running chef client.') 38 | else 39 | go_server = go_servers.first 40 | values[:go_server_host] = go_server['ipaddress'] 41 | values[:go_server_ssl_port] = go_server['gocd']['server']['https_port'] 42 | if go_servers.count > 1 43 | Chef::Log.warn("Multiple Go servers found on Chef server. Using first returned server '#{values[:go_server_host]}' for server instance configuration.") 44 | end 45 | Chef::Log.info("Found Go server at ip address #{values[:go_server_host]} with automatic agent registration") 46 | if values[:key] == go_server['gocd']['server']['autoregister_key'] 47 | Chef::Log.warn('Agent auto-registration enabled. This agent will not require approval to become active.') 48 | end 49 | values[:go_server_url] = "https://#{values[:go_server_host]}:#{values[:go_server_ssl_port]}/go" 50 | end 51 | end 52 | values[:hostname] = node['gocd']['agent']['autoregister']['hostname'] 53 | values[:environments] = node['gocd']['agent']['autoregister']['environments'] 54 | values[:resources] = node['gocd']['agent']['autoregister']['resources'] 55 | values[:elastic_agent_plugin_id] = node['gocd']['agent']['elastic']['plugin_id'] 56 | values[:elastic_agent_id] = node['gocd']['agent']['elastic']['agent_id'] 57 | values[:daemon] = node['gocd']['agent']['daemon'] 58 | values[:vnc] = node['gocd']['agent']['vnc']['enabled'] 59 | values[:workspace] = node['gocd']['agent']['workspace'] 60 | values 61 | end 62 | 63 | def go_server_config_file 64 | if platform?('windows') 65 | "#{node['gocd']['server']['work_dir']}\\config\\cruise-config.xml" 66 | else 67 | '/etc/go/cruise-config.xml' 68 | end 69 | end 70 | 71 | def latest_version? 72 | user_requested_version == 'latest' 73 | end 74 | 75 | def experimental? 76 | node['gocd']['use_experimental'] 77 | end 78 | 79 | # version to pass into 'package' resource 80 | def user_requested_version 81 | # just return attribute value, when nil it will default to installing stable 82 | node['gocd']['version'] 83 | end 84 | 85 | # Only needed when downloading package from URL 86 | def remote_version 87 | if latest_version? || user_requested_version.nil? || user_requested_version.empty? 88 | fetch_go_version(experimental?) 89 | else 90 | user_requested_version 91 | end 92 | end 93 | 94 | def updates_base_feed 95 | node['gocd']['updates']['baseurl'] 96 | end 97 | 98 | def updates_url 99 | if node['gocd']['updates']['url'] 100 | # user provided updates url 101 | node['gocd']['updates']['url'] 102 | elsif node['gocd']['use_experimental'] 103 | 'https://update.gocd.org/channels/experimental/latest.json' 104 | else 105 | 'https://update.gocd.org/channels/supported/latest.json' 106 | end 107 | end 108 | 109 | def fetch_go_version(_is_experimental) 110 | url = updates_url 111 | 112 | begin 113 | fetch_go_version_from_url url 114 | rescue => e 115 | Chef::Log.error("Failed to get Go version from updates service - #{e}") 116 | # fallback to last known stable 117 | '16.9.0-4001' 118 | end 119 | end 120 | 121 | def fetch_go_version_from_url(url) 122 | text = fetch_content url 123 | raise 'text is empty' if text.empty? 124 | parsed = JSON.parse(text) 125 | raise 'Invalid format in version json file' unless parsed['message'] 126 | message = JSON.parse(parsed['message']) 127 | message['latest-version'] 128 | end 129 | 130 | def package_extension 131 | value_for_platform_family('debian' => '.deb', 132 | %w(rhel fedora) => '.noarch.rpm', 133 | 'windows' => '-setup.exe', 134 | 'default' => '.zip') 135 | end 136 | 137 | def os_dir 138 | value_for_platform_family('debian' => 'deb', 139 | %w(rhel fedora) => 'rpm', 140 | 'windows' => 'win', 141 | 'default' => 'generic') 142 | end 143 | 144 | def go_agent_remote_package_name 145 | if os_dir == 'deb' 146 | "go-agent_#{remote_version}_all#{package_extension}" 147 | elsif os_dir == 'win' 148 | case node['kernel']['os_info']['os_architecture'] 149 | when '32-bit' 150 | "go-agent-#{remote_version}-jre-32bit#{package_extension}" 151 | else 152 | "go-agent-#{remote_version}-jre-64bit#{package_extension}" 153 | end 154 | else 155 | "go-agent-#{remote_version}#{package_extension}" 156 | end 157 | end 158 | 159 | def go_server_remote_package_name 160 | if os_dir == 'deb' 161 | "go-server_#{remote_version}_all#{package_extension}" 162 | elsif os_dir == 'win' 163 | case node['kernel']['os_info']['os_architecture'] 164 | when '32-bit' 165 | "go-server-#{remote_version}-jre-32bit#{package_extension}" 166 | else 167 | "go-server-#{remote_version}-jre-64bit#{package_extension}" 168 | end 169 | else 170 | "go-server-#{remote_version}#{package_extension}" 171 | end 172 | end 173 | 174 | def user_friendly_version(component) 175 | if node['gocd']['version'] 176 | node['gocd']['version'] 177 | elsif node['gocd'][component]['package_file']['url'] 178 | 'custom' 179 | elsif experimental? 180 | 'experimental' 181 | else 182 | 'stable' 183 | end 184 | end 185 | 186 | # user-friendly file names to use when downloading remote file 187 | def go_agent_package_name 188 | "go-agent-#{user_friendly_version('agent')}#{package_extension}" 189 | end 190 | 191 | def go_server_package_name 192 | "go-server-#{user_friendly_version('server')}#{package_extension}" 193 | end 194 | 195 | def yum_uri 196 | if node['gocd']['repository']['yum']['baseurl'] 197 | # user provided yum URI 198 | node['gocd']['repository']['yum']['baseurl'] 199 | elsif node['gocd']['use_experimental'] 200 | 'https://download.gocd.org/experimental' 201 | else 202 | 'https://download.gocd.org' 203 | end 204 | end 205 | 206 | def apt_uri 207 | if node['gocd']['repository']['apt']['uri'] 208 | # user provided apt URI 209 | node['gocd']['repository']['apt']['uri'] 210 | elsif node['gocd']['use_experimental'] 211 | 'https://download.gocd.org/experimental' 212 | else 213 | 'https://download.gocd.org' 214 | end 215 | end 216 | 217 | def go_baseurl 218 | node['gocd']['package_file']['baseurl'] || 'https://download.gocd.org/binaries' 219 | end 220 | 221 | def go_agent_package_url 222 | node['gocd']['agent']['package_file']['url'] || "#{go_baseurl}/#{remote_version}/#{os_dir}/#{go_agent_remote_package_name}" 223 | end 224 | 225 | def go_server_package_url 226 | node['gocd']['server']['package_file']['url'] || "#{go_baseurl}/#{remote_version}/#{os_dir}/#{go_server_remote_package_name}" 227 | end 228 | 229 | def arch 230 | node['kernel']['machine'] =~ /x86_64/ ? 'amd64' : node['kernel']['machine'] 231 | end 232 | 233 | def os 234 | node['os'] 235 | end 236 | end 237 | end 238 | 239 | Chef::Recipe.send(:include, ::Gocd::Helpers) 240 | Chef::Resource.send(:include, ::Gocd::Helpers) 241 | Chef::Provider.send(:include, ::Gocd::Helpers) 242 | -------------------------------------------------------------------------------- /libraries/matchers.rb: -------------------------------------------------------------------------------- 1 | ########################################################################## 2 | # Copyright 2017 ThoughtWorks, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ########################################################################## 16 | 17 | if defined?(ChefSpec) 18 | def create_gocd_agent(resource_name) 19 | ChefSpec::Matchers::ResourceMatcher.new(:gocd_agent, :create, resource_name) 20 | end 21 | 22 | def delete_gocd_agent(resource_name) 23 | ChefSpec::Matchers::ResourceMatcher.new(:gocd_agent, :delete, resource_name) 24 | end 25 | 26 | def create_gocd_plugin(resource_name) 27 | ChefSpec::Matchers::ResourceMatcher.new(:gocd_plugin, :create, resource_name) 28 | end 29 | 30 | def create_gocd_agent_autoregister_file(resource_name) 31 | ChefSpec::Matchers::ResourceMatcher.new(:gocd_agent_autoregister_file, :create, resource_name) 32 | end 33 | 34 | def delete_gocd_agent_autoregister_file(resource_name) 35 | ChefSpec::Matchers::ResourceMatcher.new(:gocd_agent_autoregister_file, :delete, resource_name) 36 | end 37 | end 38 | -------------------------------------------------------------------------------- /metadata.rb: -------------------------------------------------------------------------------- 1 | ########################################################################## 2 | # Copyright 2017 ThoughtWorks, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ########################################################################## 16 | 17 | name 'gocd' 18 | description 'Installs/Configures Go servers and agents' 19 | maintainer 'GoCD Contributors' 20 | maintainer_email 'go-cd@googlegroups.com' 21 | version '4.0.0' 22 | source_url 'https://github.com/gocd/go-cookbook' if respond_to?(:source_url) 23 | issues_url 'https://github.com/gocd/go-cookbook/issues' if respond_to?(:issues_url) 24 | chef_version '>= 12' 25 | license 'Apache-2.0' 26 | 27 | supports 'ubuntu', '>= 16.04' 28 | supports 'centos', '>= 6' 29 | supports 'redhat', '>= 6' 30 | supports 'windows' 31 | 32 | recipe 'gocd::server', 'Installs and configures a Go server' 33 | recipe 'gocd::agent', 'Installs and configures a Go agent' 34 | recipe 'gocd::repository', 'Installs the go yum/apt repository' 35 | recipe 'gocd::agent_windows', 'Installs and configures Windows Go agent' 36 | recipe 'gocd::server_windows', 'Installs and configures Windows Go server' 37 | recipe 'gocd::agent_linux', 'Install and configures Linux Go agent' 38 | recipe 'gocd::server_linux', 'Install and configures Linux Go server' 39 | 40 | depends 'apt', '>= 3.0.0' 41 | depends 'java' 42 | depends 'yum' 43 | depends 'windows' 44 | -------------------------------------------------------------------------------- /recipes/agent.rb: -------------------------------------------------------------------------------- 1 | ########################################################################## 2 | # Copyright 2017 ThoughtWorks, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ########################################################################## 16 | 17 | case node['platform'] 18 | when 'windows' 19 | include_recipe 'gocd::agent_windows' 20 | else 21 | include_recipe 'gocd::agent_linux' 22 | end 23 | -------------------------------------------------------------------------------- /recipes/agent_linux.rb: -------------------------------------------------------------------------------- 1 | ########################################################################## 2 | # Copyright 2017 ThoughtWorks, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ########################################################################## 16 | 17 | include_recipe 'gocd::agent_linux_install' 18 | 19 | node['gocd']['agent']['count'].times do |i| 20 | name = (i == 0) ? 'go-agent' : "go-agent-#{i}" 21 | gocd_agent name 22 | end 23 | -------------------------------------------------------------------------------- /recipes/agent_linux_install.rb: -------------------------------------------------------------------------------- 1 | ########################################################################## 2 | # Copyright 2017 ThoughtWorks, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ########################################################################## 16 | 17 | include_recipe 'gocd::ohai' 18 | 19 | include_recipe 'gocd::java' 20 | 21 | case node['gocd']['install_method'] 22 | when 'repository' 23 | include_recipe 'gocd::repository' 24 | package 'go-agent' do 25 | notifies :reload, 'ohai[reload_passwd_for_go_user]', :immediately 26 | if latest_version? 27 | action :upgrade 28 | else 29 | version user_requested_version 30 | end 31 | end 32 | when 'package_file' 33 | package_path = File.join(Chef::Config[:file_cache_path], go_agent_package_name) 34 | remote_file go_agent_package_name do 35 | path package_path 36 | source go_agent_package_url 37 | end 38 | case node['platform_family'] 39 | when 'debian' 40 | dpkg_package 'go-agent' do 41 | source package_path 42 | notifies :reload, 'ohai[reload_passwd_for_go_user]', :immediately 43 | end 44 | when 'rhel', 'fedora' 45 | rpm_package 'go-agent' do 46 | source package_path 47 | notifies :reload, 'ohai[reload_passwd_for_go_user]', :immediately 48 | end 49 | end 50 | else 51 | raise "Unknown install method - '#{node['gocd']['install_method']}'" 52 | end 53 | -------------------------------------------------------------------------------- /recipes/agent_windows.rb: -------------------------------------------------------------------------------- 1 | ########################################################################## 2 | # Copyright 2017 ThoughtWorks, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ########################################################################## 16 | 17 | include_recipe 'gocd::agent_windows_install' 18 | 19 | service 'Go Agent' do 20 | supports status: true, restart: true, start: true, stop: true 21 | action [:enable, :start] 22 | end 23 | -------------------------------------------------------------------------------- /recipes/agent_windows_install.rb: -------------------------------------------------------------------------------- 1 | ########################################################################## 2 | # Copyright 2017 ThoughtWorks, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ########################################################################## 16 | 17 | package_path = File.join(Chef::Config[:file_cache_path], go_agent_package_name) 18 | 19 | remote_file go_agent_package_name do 20 | path package_path 21 | source go_agent_package_url 22 | end 23 | 24 | autoregister_values = agent_properties 25 | 26 | if autoregister_values[:go_server_url].nil? 27 | autoregister_values[:go_server_url] = 'https://localhost:8154/go' 28 | Chef::Log.warn("Go server not found on Chef server or not specifed via node['gocd']['agent']['go_server_url'] attribute, defaulting Go server to #{autoregister_values[:go_server_url]}") 29 | end 30 | 31 | opts = [] 32 | opts << "/SERVERURL='#{autoregister_values[:go_server_url]}'" 33 | opts << '/S' 34 | opts << '/D=C:\GoAgent' 35 | 36 | windows_package 'Go Agent' do 37 | installer_type :nsis 38 | source package_path 39 | options opts.join(' ') 40 | end 41 | -------------------------------------------------------------------------------- /recipes/default.rb: -------------------------------------------------------------------------------- 1 | ########################################################################## 2 | # Copyright 2017 ThoughtWorks, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ########################################################################## 16 | 17 | include_recipe 'gocd::server' 18 | include_recipe 'gocd::agent' 19 | -------------------------------------------------------------------------------- /recipes/java.rb: -------------------------------------------------------------------------------- 1 | ########################################################################## 2 | # Copyright 2017 ThoughtWorks, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ########################################################################## 16 | 17 | # must be early so that java home attrbute gets assigned soon enough 18 | node.default!['java']['jdk_version'] = '8' 19 | include_recipe 'java' 20 | -------------------------------------------------------------------------------- /recipes/ohai.rb: -------------------------------------------------------------------------------- 1 | ########################################################################## 2 | # Copyright 2017 ThoughtWorks, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ########################################################################## 16 | 17 | ohai 'reload_passwd_for_go_user' do 18 | action :nothing 19 | plugin 'etc' 20 | end 21 | -------------------------------------------------------------------------------- /recipes/repository.rb: -------------------------------------------------------------------------------- 1 | ########################################################################## 2 | # Copyright 2017 ThoughtWorks, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ########################################################################## 16 | 17 | case node['platform_family'] 18 | when 'debian' 19 | include_recipe 'apt' 20 | 21 | apt_repository 'gocd' do 22 | uri apt_uri 23 | components node['gocd']['repository']['apt']['components'] 24 | distribution node['gocd']['repository']['apt']['distribution'] 25 | keyserver node['gocd']['repository']['apt']['keyserver'] unless node['gocd']['repository']['apt']['keyserver'] == false 26 | key node['gocd']['repository']['apt']['key'] unless node['gocd']['repository']['apt']['key'] == false 27 | end 28 | 29 | when 'rhel', 'fedora' 30 | include_recipe 'yum' 31 | 32 | yum_repository 'gocd' do 33 | description 'GoCD YUM Repository' 34 | baseurl yum_uri 35 | gpgcheck node['gocd']['repository']['yum']['gpgcheck'] 36 | gpgkey node['gocd']['repository']['yum']['gpgkey'] 37 | end 38 | end 39 | -------------------------------------------------------------------------------- /recipes/server.rb: -------------------------------------------------------------------------------- 1 | ########################################################################## 2 | # Copyright 2017 ThoughtWorks, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ########################################################################## 16 | 17 | case node['platform'] 18 | when 'windows' 19 | include_recipe 'gocd::server_windows' 20 | else 21 | include_recipe 'gocd::server_linux' 22 | end 23 | 24 | service(platform?('windows') ? 'Go Server' : 'go-server') do 25 | supports status: true, restart: true, start: true, stop: true 26 | action [:enable, :start] 27 | if node['gocd']['server']['wait_up']['retries'] != 0 28 | notifies :get, 'http_request[verify_go-server_comes_up]', :immediately 29 | end 30 | end 31 | 32 | http_request 'verify_go-server_comes_up' do 33 | url "http://localhost:#{node['gocd']['server']['http_port']}/go/api/v1/health" 34 | retry_delay node['gocd']['server']['wait_up']['retry_delay'] 35 | retries node['gocd']['server']['wait_up']['retries'] 36 | action :nothing 37 | end 38 | 39 | ruby_block 'publish_autoregister_key' do 40 | block do 41 | s = ::File.readlines(go_server_config_file).grep(/agentAutoRegisterKey="(\S+)"/) 42 | server_autoregister_key = unless s.empty? 43 | s[0].to_s.match(/agentAutoRegisterKey="(\S+)"/)[1] 44 | end 45 | Chef::Log.warn('Enabling automatic agent registration. Any configured agent will be configured to build without authorization.') 46 | node.normal['gocd']['server']['autoregister_key'] = server_autoregister_key 47 | end 48 | action :run 49 | not_if { Chef::Config[:solo] } 50 | retries 4 51 | end 52 | -------------------------------------------------------------------------------- /recipes/server_linux.rb: -------------------------------------------------------------------------------- 1 | ########################################################################## 2 | # Copyright 2017 ThoughtWorks, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ########################################################################## 16 | 17 | include_recipe 'gocd::server_linux_install' 18 | 19 | template '/etc/default/go-server' do 20 | source 'go-server-default.erb' 21 | mode '0644' 22 | owner 'root' 23 | group 'root' 24 | notifies :restart, 'service[go-server]', :delayed 25 | end 26 | -------------------------------------------------------------------------------- /recipes/server_linux_install.rb: -------------------------------------------------------------------------------- 1 | ########################################################################## 2 | # Copyright 2017 ThoughtWorks, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ########################################################################## 16 | 17 | include_recipe 'gocd::java' 18 | include_recipe 'gocd::ohai' 19 | 20 | package 'unzip' 21 | 22 | case node['gocd']['install_method'] 23 | when 'repository' 24 | include_recipe 'gocd::repository' 25 | package 'go-server' do 26 | if latest_version? 27 | action :upgrade 28 | else 29 | version user_requested_version 30 | end 31 | notifies :reload, 'ohai[reload_passwd_for_go_user]', :immediately 32 | end 33 | when 'package_file' 34 | package_path = File.join(Chef::Config[:file_cache_path], go_server_package_name) 35 | remote_file go_server_package_name do 36 | path package_path 37 | source go_server_package_url 38 | mode 0644 39 | end 40 | case node['platform_family'] 41 | when 'debian' 42 | dpkg_package 'go-server' do 43 | source package_path 44 | notifies :reload, 'ohai[reload_passwd_for_go_user]', :immediately 45 | end 46 | when 'rhel', 'fedora' 47 | rpm_package 'go-server' do 48 | source package_path 49 | notifies :reload, 'ohai[reload_passwd_for_go_user]', :immediately 50 | end 51 | end 52 | else 53 | raise "Unknown install method - '#{node['gocd']['install_method']}'" 54 | end 55 | -------------------------------------------------------------------------------- /recipes/server_windows.rb: -------------------------------------------------------------------------------- 1 | ########################################################################## 2 | # Copyright 2017 ThoughtWorks, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ########################################################################## 16 | 17 | include_recipe 'gocd::server_windows_install' 18 | -------------------------------------------------------------------------------- /recipes/server_windows_install.rb: -------------------------------------------------------------------------------- 1 | ########################################################################## 2 | # Copyright 2017 ThoughtWorks, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ########################################################################## 16 | 17 | package_path = File.join(Chef::Config[:file_cache_path], go_server_package_name) 18 | server_directory_path = node['gocd']['server']['work_dir'].tr('/', '\\') 19 | remote_file go_server_package_name do 20 | path package_path 21 | source go_server_package_url 22 | end 23 | 24 | log "Installing server to: #{server_directory_path}" 25 | 26 | opts = [] 27 | opts << '/S' 28 | opts << "/D=#{server_directory_path}" 29 | 30 | windows_package 'Go Server' do 31 | installer_type :nsis 32 | source package_path 33 | options opts.join(' ') 34 | end 35 | -------------------------------------------------------------------------------- /resources/agent.rb: -------------------------------------------------------------------------------- 1 | ########################################################################## 2 | # Copyright 2017 ThoughtWorks, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ########################################################################## 16 | 17 | default_action :create if defined?(default_action) 18 | 19 | property :service_action, [Symbol, Array], required: false, default: [:enable, :start] 20 | 21 | property :agent_name, String, name_property: true, required: false 22 | 23 | property :user, String, required: false, default: 'go' 24 | property :group, String, required: false, default: 'go' 25 | property :go_server_url, String, required: false 26 | property :daemon, [TrueClass, FalseClass], required: false, default: node['gocd']['agent']['daemon'] 27 | property :vnc, [TrueClass, FalseClass], required: false, default: node['gocd']['agent']['vnc']['enabled'] 28 | property :autoregister_key, [String, nil], required: false, default: nil 29 | property :autoregister_hostname, [String, nil], required: false, default: nil 30 | property :autoregister_environments, required: false, default: nil 31 | property :autoregister_resources, required: false, default: nil 32 | property :workspace, [String, nil], required: false, default: nil 33 | property :elastic_agent_id, [String, nil], required: false, default: nil 34 | property :elastic_agent_plugin_id, [String, nil], required: false, default: nil 35 | 36 | action :create do 37 | log 'Warn obsolete attributes' do 38 | message "Please note that node['gocd']['agent']['go_server_host'] and node['gocd']['agent']['go_server_port'] have been replaced by node['gocd']['agent']['go_server_url']" 39 | level :warn 40 | only_if { !node['gocd']['agent']['go_server_host'].nil? || !node['gocd']['agent']['go_server_port'].nil? } 41 | end 42 | 43 | include_recipe 'gocd::agent_linux_install' 44 | 45 | agent_name = new_resource.agent_name 46 | workspace = new_resource.workspace || "/var/lib/#{agent_name}" 47 | log_directory = "/var/log/#{agent_name}" 48 | [workspace, log_directory].each do |d| 49 | directory d do 50 | mode 0755 51 | owner new_resource.user 52 | group new_resource.group 53 | end 54 | end 55 | directory "#{workspace}/config" do 56 | mode 0700 57 | owner new_resource.user 58 | group new_resource.group 59 | end 60 | 61 | autoregister_values = agent_properties 62 | autoregister_values[:key] = new_resource.autoregister_key || autoregister_values[:key] 63 | autoregister_values[:go_server_url] = new_resource.go_server_url || autoregister_values[:go_server_url] 64 | autoregister_values[:vnc] = new_resource.vnc || autoregister_values[:vnc] 65 | autoregister_values[:daemon] = new_resource.daemon || autoregister_values[:daemon] 66 | autoregister_values[:workspace] = workspace 67 | autoregister_values[:log_directory] = log_directory 68 | if autoregister_values[:go_server_url].nil? 69 | autoregister_values[:go_server_url] = 'https://localhost:8154/go' 70 | Chef::Log.warn("Go server not found on Chef server or not specifed via node['gocd']['agent']['go_server_url'] attribute, defaulting Go server to #{autoregister_values[:go_server_url]}") 71 | end 72 | 73 | proof_of_registration = "#{workspace}/config/guid.txt" 74 | autoregister_file_path = "#{workspace}/config/autoregister.properties" 75 | # package manages the init.d/go-agent script so cookbook should not. 76 | bash "setup init.d for #{agent_name}" do 77 | code <<-EOH 78 | cp /etc/init.d/go-agent /etc/init.d/#{agent_name} 79 | sed -i 's/# Provides: go-agent$/# Provides: #{agent_name}/g' /etc/init.d/#{agent_name} 80 | EOH 81 | not_if "grep -q '# Provides: #{agent_name}$' /etc/init.d/#{agent_name}" 82 | only_if { agent_name != 'go-agent' } 83 | end 84 | link "/usr/share/#{agent_name}" do 85 | to '/usr/share/go-agent' 86 | not_if { agent_name == 'go-agent' } 87 | end 88 | 89 | template "/etc/default/#{agent_name}" do 90 | source 'go-agent-default.erb' 91 | cookbook 'gocd' 92 | mode '0644' 93 | owner 'root' 94 | group 'root' 95 | notifies :restart, "service[#{agent_name}]" if autoregister_values[:daemon] 96 | variables autoregister_values 97 | end 98 | 99 | if autoregister_values[:key] 100 | gocd_agent_autoregister_file autoregister_file_path do 101 | owner new_resource.user 102 | group new_resource.group 103 | autoregister_key new_resource.autoregister_key 104 | autoregister_hostname new_resource.autoregister_hostname 105 | autoregister_environments new_resource.autoregister_environments 106 | autoregister_resources new_resource.autoregister_resources 107 | elastic_agent_id new_resource.elastic_agent_id 108 | elastic_agent_plugin_id new_resource.elastic_agent_plugin_id 109 | not_if { ::File.exist? proof_of_registration } 110 | notifies :restart, "service[#{agent_name}]" if autoregister_values[:daemon] 111 | end 112 | end 113 | 114 | service agent_name do 115 | provider Chef::Provider::Service::Systemd if platform?('ubuntu') && node['platform_version'].to_f >= 16.04 116 | supports status: true, restart: autoregister_values[:daemon], start: true, stop: true 117 | action new_resource.service_action 118 | end 119 | end 120 | -------------------------------------------------------------------------------- /resources/agent_autoregister_file.rb: -------------------------------------------------------------------------------- 1 | ########################################################################## 2 | # Copyright 2017 ThoughtWorks, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ########################################################################## 16 | 17 | default_action :create if defined?(default_action) 18 | 19 | property :path, String, name_property: true 20 | 21 | property :owner, String, required: false, default: 'go' 22 | property :group, String, required: false, default: 'go' 23 | property :autoregister_key, [String, nil], required: true, default: nil 24 | property :autoregister_hostname, [String, nil], required: false, default: nil 25 | property :autoregister_environments, required: false, default: nil 26 | property :autoregister_resources, required: false, default: nil 27 | property :elastic_agent_id, [String, nil], required: false, default: nil 28 | property :elastic_agent_plugin_id, [String, nil], required: false, default: nil 29 | 30 | action :create do 31 | autoregister_values = agent_properties 32 | autoregister_values[:key] = new_resource.autoregister_key || autoregister_values[:key] 33 | autoregister_values[:hostname] = new_resource.autoregister_hostname || autoregister_values[:hostname] 34 | autoregister_values[:autoregister_environments] = new_resource.autoregister_environments || autoregister_values[:environments] 35 | autoregister_values[:autoregister_resources] = new_resource.autoregister_resources || autoregister_values[:resources] 36 | autoregister_values[:elastic_agent_id] = new_resource.elastic_agent_id || autoregister_values[:elastic_agent_id] 37 | autoregister_values[:elastic_agent_plugin_id] = new_resource.elastic_agent_plugin_id || autoregister_values[:elastic_agent_plugin_id] 38 | 39 | if node['platform_family'].include?('windows') 40 | template new_resource.path do 41 | source 'autoregister.properties.erb' 42 | cookbook 'gocd' 43 | variables autoregister_values 44 | end 45 | else 46 | template new_resource.path do 47 | source 'autoregister.properties.erb' 48 | cookbook 'gocd' 49 | mode '0644' 50 | owner new_resource.owner 51 | group new_resource.group 52 | variables autoregister_values 53 | end 54 | end 55 | end 56 | 57 | action :delete do 58 | file new_resource.path do 59 | action :delete 60 | end 61 | end 62 | -------------------------------------------------------------------------------- /resources/plugin.rb: -------------------------------------------------------------------------------- 1 | ########################################################################## 2 | # Copyright 2017 ThoughtWorks, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ########################################################################## 16 | 17 | default_action :create if defined?(default_action) 18 | 19 | property :plugin_name, String, name_property: true 20 | property :plugin_uri, String, required: true 21 | property :server_work_dir, String, required: false, default: node['gocd']['server']['work_dir'] 22 | 23 | action :create do 24 | unless node['platform_family'].include?('windows') 25 | include_recipe 'gocd::server_linux_install' 26 | end 27 | 28 | plugin_name = new_resource.plugin_name 29 | server_work_dir = new_resource.server_work_dir 30 | plugin_uri = new_resource.plugin_uri 31 | 32 | if node['platform_family'].include?('windows') 33 | remote_file "#{server_work_dir}\\plugins\\external\\#{plugin_name}.jar" do 34 | source plugin_uri 35 | retries 5 36 | end 37 | else 38 | remote_file "#{server_work_dir}/plugins/external/#{plugin_name}.jar" do 39 | source plugin_uri 40 | owner 'go' 41 | group 'go' 42 | mode 0770 43 | retries 5 44 | end 45 | end 46 | end 47 | -------------------------------------------------------------------------------- /spec/go_agent_autoregister_lwrp_spec.rb: -------------------------------------------------------------------------------- 1 | ########################################################################## 2 | # Copyright 2017 ThoughtWorks, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ########################################################################## 16 | 17 | require 'spec_helper' 18 | 19 | describe 'gocd_test::agent_autoregister_file_lwrp' do 20 | context 'When all attributes are default' do 21 | let(:chef_run) do 22 | run = ChefSpec::SoloRunner.new(step_into: 'gocd_agent_autoregister_file') do |node| 23 | node.automatic['lsb']['id'] = 'Debian' 24 | node.automatic['platform_family'] = 'debian' 25 | node.automatic['platform'] = 'debian' 26 | node.automatic['os'] = 'linux' 27 | end 28 | run.converge(described_recipe) 29 | end 30 | 31 | it 'creates autoregister file chef resource' do 32 | expect(chef_run).to create_gocd_agent_autoregister_file('/var/mygo/autoregister.properties').with( 33 | autoregister_key: 'bla-key', 34 | autoregister_hostname: 'mygo-agent', 35 | autoregister_environments: 'stage', 36 | autoregister_resources: ['java-8', 'ruby'] 37 | ) 38 | end 39 | 40 | it 'creates autoregister properties file' do 41 | expect(chef_run).to render_file('/var/mygo/autoregister.properties').with_content { |content| 42 | expect(content).to include('bla-key') 43 | expect(content).to include('stage') 44 | expect(content).to include('mygo-agent') 45 | expect(content).to include('java-8, ruby') 46 | expect(content).to_not include('agent.auto.register.elasticAgent') 47 | } 48 | end 49 | 50 | it 'creates elastic autoregister file chef resource' do 51 | expect(chef_run).to create_gocd_agent_autoregister_file('/var/elastic/autoregister.properties').with( 52 | autoregister_key: 'some-key', 53 | autoregister_hostname: 'elastic-agent', 54 | autoregister_environments: 'testing', 55 | autoregister_resources: ['java-8'] 56 | ) 57 | end 58 | 59 | it 'creates elastic autoregister properties file' do 60 | expect(chef_run).to render_file('/var/elastic/autoregister.properties').with_content { |content| 61 | expect(content).to include('some-key') 62 | expect(content).to include('testing') 63 | expect(content).to include('agent-id') 64 | expect(content).to include('elastic-agent-plugin-id') 65 | expect(content).to include('agent.auto.register.elasticAgent.pluginId') 66 | expect(content).to include('agent.auto.register.elasticAgent.agentId') 67 | } 68 | end 69 | end 70 | 71 | context 'When autoregister values are specified in attributes' do 72 | let(:chef_run) do 73 | run = ChefSpec::SoloRunner.new(step_into: 'gocd_agent_autoregister_file') do |node| 74 | node.automatic['lsb']['id'] = 'Debian' 75 | node.automatic['platform_family'] = 'debian' 76 | node.automatic['platform'] = 'debian' 77 | node.automatic['os'] = 'linux' 78 | node.normal['gocd']['agent']['autoregister']['key'] = 'some-key' 79 | node.normal['gocd']['agent']['autoregister']['environments'] = 'testing' 80 | node.normal['gocd']['agent']['autoregister']['resources'] = ['java-8'] 81 | node.normal['gocd']['agent']['autoregister']['hostname'] = 'elastic-agent' 82 | node.normal['gocd']['agent']['elastic']['plugin_id'] = 'agent-id' 83 | node.normal['gocd']['agent']['elastic']['agent_id'] = 'elastic-agent-plugin-id' 84 | end 85 | run.converge(described_recipe) 86 | end 87 | it 'creates autoregister file' do 88 | expect(chef_run).to create_gocd_agent_autoregister_file('/var/attrs/autoregister.properties') 89 | end 90 | it 'renders autoregister file from attributes' do 91 | expect(chef_run).to render_file('/var/attrs/autoregister.properties').with_content { |content| 92 | expect(content).to include('some-key') 93 | expect(content).to include('elastic-agent') 94 | expect(content).to include('testing') 95 | expect(content).to include('java-8') 96 | expect(content).to include('agent-id') 97 | expect(content).to include('elastic-agent-plugin-id') 98 | } 99 | end 100 | end 101 | end 102 | -------------------------------------------------------------------------------- /spec/go_agent_lwrp_spec.rb: -------------------------------------------------------------------------------- 1 | ########################################################################## 2 | # Copyright 2017 ThoughtWorks, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ########################################################################## 16 | 17 | require 'spec_helper' 18 | 19 | describe 'gocd_test::single_agent_lwrp' do 20 | context 'When all attributes are default' do 21 | let(:chef_run) do 22 | run = ChefSpec::SoloRunner.new(step_into: 'gocd_agent') do |node| 23 | node.automatic['lsb']['id'] = 'Debian' 24 | node.automatic['platform_family'] = 'debian' 25 | node.automatic['platform'] = 'debian' 26 | node.automatic['os'] = 'linux' 27 | end 28 | run.converge(described_recipe) 29 | end 30 | before do 31 | stub_command("grep -q '# Provides: go-agent$' /etc/init.d/go-agent").and_return(false) 32 | stub_command("grep -q '# Provides: my-go-agent$' /etc/init.d/my-go-agent").and_return(false) 33 | end 34 | 35 | it_behaves_like :agent_linux_install 36 | 37 | it 'creates my-go-agent chef resource' do 38 | expect(chef_run).to create_gocd_agent('my-go-agent') 39 | end 40 | it 'does not create default go-agent chef resource' do 41 | expect(chef_run).to_not create_gocd_agent('go-agent') 42 | end 43 | 44 | it 'creates my-go-agent service' do 45 | expect(chef_run).to enable_service('my-go-agent') 46 | expect(chef_run).to start_service('my-go-agent') 47 | end 48 | 49 | it 'creates go agent configuration in /etc/default/my-go-agent' do 50 | expect(chef_run).to render_file('/etc/default/my-go-agent').with_content { |content| 51 | expect(content).to include('GO_SERVER_URL=https://go.example.com:443/go') 52 | expect(content).to_not include('GO_SERVER_PORT') 53 | expect(content).to include('AGENT_WORK_DIR=/mnt/big_drive') 54 | expect(content).to include('DAEMON=Y') 55 | expect(content).to include('VNC=Y') 56 | } 57 | end 58 | 59 | it 'creates autoregister properties file' do 60 | expect(chef_run).to create_gocd_agent_autoregister_file('/mnt/big_drive/config/autoregister.properties').with( 61 | autoregister_key: 'bla-key', 62 | autoregister_hostname: 'my-lwrp-agent', 63 | autoregister_environments: 'production', 64 | autoregister_resources: ['java-8', 'ruby-2.2'] 65 | ) 66 | end 67 | end 68 | end 69 | -------------------------------------------------------------------------------- /spec/go_agent_spec.rb: -------------------------------------------------------------------------------- 1 | ########################################################################## 2 | # Copyright 2017 ThoughtWorks, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ########################################################################## 16 | 17 | require 'spec_helper' 18 | 19 | describe 'gocd::agent' do 20 | shared_examples_for :agent_recipe_linux do 21 | it_behaves_like :agent_linux_install 22 | it 'creates go agent configuration in /etc/default/go-agent' do 23 | expect(chef_run).to render_file('/etc/default/go-agent').with_content { |content| 24 | expect(content).to include('GO_SERVER_URL=https://localhost:8154/go') 25 | expect(content).to_not include('GO_SERVER_PORT=8153') 26 | expect(content).to include('AGENT_WORK_DIR=/var/lib/go-agent') 27 | expect(content).to include('DAEMON=Y') 28 | expect(content).to include('VNC=N') 29 | } 30 | end 31 | it 'creates gocd_agent chef resource' do 32 | expect(chef_run).to create_gocd_agent('go-agent') 33 | end 34 | it 'configures go-agent service' do 35 | expect(chef_run).to enable_service('go-agent') 36 | expect(chef_run).to start_service('go-agent') 37 | end 38 | it 'creates go agent workspace directory' do 39 | expect(chef_run).to create_directory('/var/lib/go-agent').with( 40 | owner: 'go', 41 | group: 'go', 42 | mode: 0755 43 | ) 44 | end 45 | it 'creates go agent log directory' do 46 | expect(chef_run).to create_directory('/var/log/go-agent').with( 47 | owner: 'go', 48 | group: 'go', 49 | mode: 0755 50 | ) 51 | end 52 | it 'creates go agent config directory' do 53 | expect(chef_run).to create_directory('/var/lib/go-agent/config').with( 54 | owner: 'go', 55 | group: 'go', 56 | mode: 0700 57 | ) 58 | end 59 | end 60 | 61 | context 'When attributes use obsolete go server host and port and platform is debian' do 62 | let(:chef_run) do 63 | run = ChefSpec::SoloRunner.new(step_into: 'gocd_agent') do |node| 64 | node.automatic['lsb']['id'] = 'Debian' 65 | node.automatic['platform_family'] = 'debian' 66 | node.automatic['platform'] = 'debian' 67 | node.automatic['os'] = 'linux' 68 | node.normal['gocd']['agent']['go_server_host'] = 'localhost' 69 | end 70 | run.converge(described_recipe) 71 | end 72 | before do 73 | stub_command("grep -q '# Provides: go-agent$' /etc/init.d/go-agent").and_return(false) 74 | end 75 | it_behaves_like :agent_recipe_linux 76 | it_behaves_like :apt_repository_recipe 77 | it 'warns about obsolete attributes use' do 78 | expect(chef_run).to write_log('Warn obsolete attributes') 79 | end 80 | it 'installs go-agent package' do 81 | expect(chef_run).to install_package('go-agent') 82 | end 83 | 84 | it 'upgrades go-agent package if version is set to `latest`' do 85 | chef_run.node.normal['gocd']['version'] = 'latest' 86 | chef_run.converge(described_recipe) 87 | expect(chef_run).to upgrade_package('go-agent') 88 | end 89 | end 90 | 91 | context 'When all attributes are default and platform is debian' do 92 | let(:chef_run) do 93 | run = ChefSpec::SoloRunner.new(step_into: 'gocd_agent') do |node| 94 | node.automatic['lsb']['id'] = 'Debian' 95 | node.automatic['platform_family'] = 'debian' 96 | node.automatic['platform'] = 'debian' 97 | node.automatic['os'] = 'linux' 98 | node.normal['gocd']['agent']['go_server_url'] = 'https://localhost:8154/go' 99 | end 100 | run.converge(described_recipe) 101 | end 102 | before do 103 | stub_command("grep -q '# Provides: go-agent$' /etc/init.d/go-agent").and_return(false) 104 | end 105 | it_behaves_like :agent_recipe_linux 106 | it_behaves_like :apt_repository_recipe 107 | it 'installs go-agent package' do 108 | expect(chef_run).to install_package('go-agent') 109 | end 110 | 111 | it 'upgrades go-agent package if version is set to `latest`' do 112 | chef_run.node.normal['gocd']['version'] = 'latest' 113 | chef_run.converge(described_recipe) 114 | expect(chef_run).to upgrade_package('go-agent') 115 | end 116 | end 117 | context 'When all attributes are default and platform is centos' do 118 | let(:chef_run) do 119 | run = ChefSpec::SoloRunner.new(step_into: 'gocd_agent') do |node| 120 | node.automatic['platform_family'] = 'rhel' 121 | node.automatic['platform'] = 'centos' 122 | node.automatic['os'] = 'linux' 123 | node.normal['gocd']['agent']['go_server_url'] = 'https://localhost:8154/go' 124 | end 125 | run.converge(described_recipe) 126 | end 127 | before do 128 | stub_command("grep -q '# Provides: go-agent$' /etc/init.d/go-agent").and_return(false) 129 | end 130 | it_behaves_like :agent_recipe_linux 131 | it_behaves_like :yum_repository_recipe 132 | it 'installs go-agent package' do 133 | expect(chef_run).to install_package('go-agent') 134 | end 135 | 136 | it 'upgrades go-agent package if version is set to `latest`' do 137 | chef_run.node.normal['gocd']['version'] = 'latest' 138 | chef_run.converge(described_recipe) 139 | expect(chef_run).to upgrade_package('go-agent') 140 | end 141 | end 142 | 143 | context 'When many agents and all attributes are default and platform is debian' do 144 | let(:chef_run) do 145 | run = ChefSpec::SoloRunner.new(step_into: 'gocd_agent') do |node| 146 | node.automatic['lsb']['id'] = 'Debian' 147 | node.automatic['platform_family'] = 'debian' 148 | node.automatic['platform'] = 'debian' 149 | node.automatic['os'] = 'linux' 150 | node.normal['gocd']['agent']['go_server_url'] = 'https://localhost:8154/go' 151 | node.normal['gocd']['agent']['count'] = 2 152 | end 153 | run.converge(described_recipe) 154 | end 155 | before do 156 | stub_command("grep -q '# Provides: go-agent$' /etc/init.d/go-agent").and_return(false) 157 | stub_command("grep -q '# Provides: go-agent-1$' /etc/init.d/go-agent-1").and_return(false) 158 | end 159 | it_behaves_like :agent_recipe_linux 160 | it_behaves_like :apt_repository_recipe 161 | it 'installs go-agent package' do 162 | expect(chef_run).to install_package('go-agent') 163 | end 164 | 165 | it 'upgrades go-agent package if version is set to `latest`' do 166 | chef_run.node.normal['gocd']['version'] = 'latest' 167 | chef_run.converge(described_recipe) 168 | expect(chef_run).to upgrade_package('go-agent') 169 | end 170 | 171 | # https://github.com/gocd/gocd/blob/master/installers/agent/release/README.md 172 | it 'creates additional gocd_agent chef resource' do 173 | expect(chef_run).to create_gocd_agent('go-agent-1') 174 | end 175 | it 'creates init.d script to start additional agent' do 176 | expect(chef_run).to run_bash('setup init.d for go-agent-1') 177 | end 178 | it 'links /usr/share/go-agent script' do 179 | expect(chef_run).to create_link('/usr/share/go-agent-1').with( 180 | to: '/usr/share/go-agent' 181 | ) 182 | end 183 | it 'creates go-agent-1 configuration' do 184 | expect(chef_run).to render_file('/etc/default/go-agent-1') 185 | # TODO: check content 186 | end 187 | it 'creates additional go agent workspace directory' do 188 | expect(chef_run).to create_directory('/var/lib/go-agent-1').with( 189 | owner: 'go', 190 | group: 'go', 191 | mode: 0755 192 | ) 193 | end 194 | it 'creates additional go agent log directory' do 195 | expect(chef_run).to create_directory('/var/log/go-agent-1').with( 196 | owner: 'go', 197 | group: 'go', 198 | mode: 0755 199 | ) 200 | end 201 | it 'creates additional go agent config directory' do 202 | expect(chef_run).to create_directory('/var/lib/go-agent-1/config').with( 203 | owner: 'go', 204 | group: 'go', 205 | mode: 0700 206 | ) 207 | end 208 | it 'configures additional go-agent service' do 209 | expect(chef_run).to enable_service('go-agent-1') 210 | expect(chef_run).to start_service('go-agent-1') 211 | end 212 | end 213 | 214 | context 'When installing from package_file and platform is debian' do 215 | let(:chef_run) do 216 | run = ChefSpec::SoloRunner.new(step_into: 'gocd_agent') do |node| 217 | node.automatic['lsb']['id'] = 'Debian' 218 | node.automatic['platform_family'] = 'debian' 219 | node.automatic['platform'] = 'debian' 220 | node.automatic['os'] = 'linux' 221 | node.normal['gocd']['agent']['go_server_url'] = 'https://localhost:8154/go' 222 | node.normal['gocd']['install_method'] = 'package_file' 223 | end 224 | allow_any_instance_of(Chef::Resource::RemoteFile).to receive(:fetch_content) 225 | .with('https://update.gocd.org/channels/supported/latest.json') 226 | .and_return('{"message": "{\"latest-version\": \"16.2.1-3027\"}"}') 227 | run.converge(described_recipe) 228 | end 229 | before do 230 | stub_command("grep -q '# Provides: go-agent$' /etc/init.d/go-agent").and_return(false) 231 | end 232 | it_behaves_like :agent_recipe_linux 233 | it 'downloads go-agent .deb from remote URL' do 234 | expect(chef_run).to create_remote_file('go-agent-stable.deb').with( 235 | source: 'https://download.gocd.org/binaries/16.2.1-3027/deb/go-agent_16.2.1-3027_all.deb') 236 | end 237 | it 'installs go-agent package from file' do 238 | expect(chef_run).to install_dpkg_package('go-agent') 239 | end 240 | end 241 | context 'When installing from package file and platform is centos' do 242 | let(:chef_run) do 243 | run = ChefSpec::SoloRunner.new(step_into: 'gocd_agent') do |node| 244 | node.automatic['platform_family'] = 'rhel' 245 | node.automatic['platform'] = 'centos' 246 | node.automatic['os'] = 'linux' 247 | node.normal['gocd']['agent']['go_server_url'] = 'https://localhost:8154/go' 248 | node.normal['gocd']['install_method'] = 'package_file' 249 | end 250 | allow_any_instance_of(Chef::Resource::RemoteFile).to receive(:fetch_content) 251 | .and_return('{"message": "{\"latest-version\": \"16.2.1-3027\"}"}') 252 | run.converge(described_recipe) 253 | end 254 | before do 255 | stub_command("grep -q '# Provides: go-agent$' /etc/init.d/go-agent").and_return(false) 256 | end 257 | it_behaves_like :agent_recipe_linux 258 | it 'downloads go-agent .rpm from remote URL' do 259 | expect(chef_run).to create_remote_file('go-agent-stable.noarch.rpm').with( 260 | source: 'https://download.gocd.org/binaries/16.2.1-3027/rpm/go-agent-16.2.1-3027.noarch.rpm') 261 | end 262 | it 'installs go-agent package from file' do 263 | expect(chef_run).to install_rpm_package('go-agent') 264 | end 265 | end 266 | 267 | context 'When installing from custom repository and platform is debian' do 268 | let(:chef_run) do 269 | run = ChefSpec::SoloRunner.new(step_into: 'gocd_agent') do |node| 270 | node.automatic['lsb']['id'] = 'Debian' 271 | node.automatic['platform_family'] = 'debian' 272 | node.automatic['platform'] = 'debian' 273 | node.automatic['os'] = 'linux' 274 | node.normal['gocd']['agent']['go_server_url'] = 'https://localhost:8154/go' 275 | node.normal['gocd']['install_method'] = 'repository' 276 | node.normal['gocd']['repository']['apt']['uri'] = 'http://mydeb/repo' 277 | node.normal['gocd']['repository']['apt']['components'] = ['/'] 278 | node.normal['gocd']['repository']['apt']['key'] = false 279 | end 280 | run.converge(described_recipe) 281 | end 282 | before do 283 | stub_command("grep -q '# Provides: go-agent$' /etc/init.d/go-agent").and_return(false) 284 | end 285 | it_behaves_like :agent_recipe_linux 286 | it 'includes apt recipe' do 287 | expect(chef_run).to include_recipe('apt') 288 | end 289 | it 'adds my custom gocd apt repository' do 290 | expect(chef_run).to add_apt_repository('gocd').with( 291 | uri: 'http://mydeb/repo', 292 | key: [], 293 | components: ['/']) 294 | end 295 | it 'installs go-agent package' do 296 | expect(chef_run).to install_package('go-agent') 297 | end 298 | 299 | it 'upgrades go-agent package if version is set to `latest`' do 300 | chef_run.node.normal['gocd']['version'] = 'latest' 301 | chef_run.converge(described_recipe) 302 | expect(chef_run).to upgrade_package('go-agent') 303 | end 304 | end 305 | context 'When installing from custom repository and platform is centos' do 306 | let(:chef_run) do 307 | run = ChefSpec::SoloRunner.new(step_into: 'gocd_agent') do |node| 308 | node.automatic['platform_family'] = 'rhel' 309 | node.automatic['platform'] = 'centos' 310 | node.automatic['os'] = 'linux' 311 | node.normal['gocd']['agent']['go_server_url'] = 'https://localhost:8154/go' 312 | node.normal['gocd']['install_method'] = 'repository' 313 | node.normal['gocd']['repository']['yum']['baseurl'] = 'http://mycustom/gocd-rpm' 314 | end 315 | run.converge(described_recipe) 316 | end 317 | before do 318 | stub_command("grep -q '# Provides: go-agent$' /etc/init.d/go-agent").and_return(false) 319 | end 320 | it_behaves_like :agent_recipe_linux 321 | it 'includes yum recipe' do 322 | expect(chef_run).to include_recipe('yum') 323 | end 324 | it 'adds my custom gocd yum repository' do 325 | expect(chef_run).to create_yum_repository('gocd').with( 326 | baseurl: 'http://mycustom/gocd-rpm', 327 | gpgcheck: true 328 | ) 329 | end 330 | 331 | it 'installs go-agent package' do 332 | expect(chef_run).to install_package('go-agent') 333 | end 334 | 335 | it 'upgrades go-agent package if version is set to `latest`' do 336 | chef_run.node.normal['gocd']['version'] = 'latest' 337 | chef_run.converge(described_recipe) 338 | expect(chef_run).to upgrade_package('go-agent') 339 | end 340 | end 341 | end 342 | -------------------------------------------------------------------------------- /spec/go_agent_windows_spec.rb: -------------------------------------------------------------------------------- 1 | ########################################################################## 2 | # Copyright 2017 ThoughtWorks, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ########################################################################## 16 | 17 | require 'spec_helper' 18 | 19 | describe 'gocd::agent' do 20 | shared_examples_for :agent_recipe_windows do 21 | it 'configures go-agent service' do 22 | expect(chef_run).to enable_service('Go Agent') 23 | expect(chef_run).to start_service('Go Agent') 24 | end 25 | end 26 | 27 | context 'When all attributes are default and platform is windows' do 28 | it_behaves_like :agent_recipe_windows 29 | let(:chef_run) do 30 | run = ChefSpec::SoloRunner.new(step_into: 'gocd_agent') do |node| 31 | node.automatic['platform_family'] = 'windows' 32 | node.automatic['platform'] = 'windows' 33 | node.automatic['os'] = 'windows' 34 | node.automatic['kernel']['os_info']['os_architecture'] = '64-bit' 35 | node.normal['gocd']['agent']['go_server_url'] = 'https://localhost:8154/go' 36 | end 37 | allow_any_instance_of(Chef::Resource::RemoteFile).to receive(:fetch_content) 38 | .and_return('{"message": "{\"latest-version\": \"16.2.1-3027\"}"}') 39 | run.converge(described_recipe) 40 | end 41 | 42 | it 'downloads official installer' do 43 | expect(chef_run).to create_remote_file('go-agent-stable-setup.exe').with( 44 | source: 'https://download.gocd.org/binaries/16.2.1-3027/win/go-agent-16.2.1-3027-jre-64bit-setup.exe') 45 | end 46 | it 'installs go-agent package' do 47 | expect(chef_run).to install_windows_package('Go Agent') 48 | end 49 | end 50 | 51 | context 'When installing from custom url and platform is windows' do 52 | it_behaves_like :agent_recipe_windows 53 | let(:chef_run) do 54 | run = ChefSpec::SoloRunner.new(step_into: 'gocd_agent') do |node| 55 | node.automatic['platform_family'] = 'windows' 56 | node.automatic['platform'] = 'windows' 57 | node.automatic['os'] = 'windows' 58 | node.normal['gocd']['agent']['go_server_url'] = 'https://localhost:8154/go' 59 | node.normal['gocd']['agent']['package_file']['url'] = 'https://example.com/go-agent.exe' 60 | end 61 | run.converge(described_recipe) 62 | end 63 | it 'downloads specified installer' do 64 | expect(chef_run).to create_remote_file('go-agent-custom-setup.exe').with( 65 | source: 'https://example.com/go-agent.exe') 66 | end 67 | it 'installs go-agent package' do 68 | expect(chef_run).to install_windows_package('Go Agent') 69 | end 70 | end 71 | end 72 | -------------------------------------------------------------------------------- /spec/go_server_spec.rb: -------------------------------------------------------------------------------- 1 | ########################################################################## 2 | # Copyright 2017 ThoughtWorks, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ########################################################################## 16 | 17 | require 'spec_helper' 18 | 19 | describe 'gocd::server' do 20 | shared_examples_for :server_recipe do 21 | it 'includes java recipe' do 22 | expect(chef_run).to include_recipe('java::default') 23 | end 24 | it 'includes the gocd::ohai recipe' do 25 | expect(chef_run).to include_recipe('gocd::ohai') 26 | end 27 | it 'creates go server configuration in /etc/default/go-server' do 28 | expect(chef_run).to render_file('/etc/default/go-server') 29 | end 30 | it 'configures go-server service' do 31 | expect(chef_run).to enable_service('go-server') 32 | expect(chef_run).to start_service('go-server') 33 | end 34 | end 35 | 36 | context 'When all attributes are default and platform is debian' do 37 | let(:chef_run) do 38 | run = ChefSpec::SoloRunner.new do |node| 39 | node.automatic['lsb']['id'] = 'Debian' 40 | node.automatic['platform_family'] = 'debian' 41 | node.automatic['platform'] = 'debian' 42 | node.automatic['os'] = 'linux' 43 | end 44 | run.converge(described_recipe) 45 | end 46 | it_behaves_like :server_recipe 47 | it_behaves_like :apt_repository_recipe 48 | 49 | it 'installs go-server package' do 50 | expect(chef_run).to install_package('go-server') 51 | end 52 | 53 | it 'upgrades go-server package if version is set to `latest`' do 54 | chef_run.node.normal['gocd']['version'] = 'latest' 55 | chef_run.converge(described_recipe) 56 | expect(chef_run).to upgrade_package('go-server') 57 | end 58 | end 59 | context 'When all attributes are default and platform is centos' do 60 | let(:chef_run) do 61 | run = ChefSpec::SoloRunner.new do |node| 62 | node.automatic['platform_family'] = 'rhel' 63 | node.automatic['platform'] = 'centos' 64 | node.automatic['os'] = 'linux' 65 | end 66 | run.converge(described_recipe) 67 | end 68 | it_behaves_like :server_recipe 69 | it_behaves_like :yum_repository_recipe 70 | it 'installs go-server package' do 71 | expect(chef_run).to install_package('go-server') 72 | end 73 | it 'upgrades go-server package if version is set to `latest`' do 74 | chef_run.node.normal['gocd']['version'] = 'latest' 75 | chef_run.converge(described_recipe) 76 | expect(chef_run).to upgrade_package('go-server') 77 | end 78 | end 79 | # TODO: server on windows 80 | 81 | context 'When installing from package_file and platform is debian' do 82 | let(:chef_run) do 83 | run = ChefSpec::SoloRunner.new do |node| 84 | node.automatic['lsb']['id'] = 'Debian' 85 | node.automatic['platform_family'] = 'debian' 86 | node.automatic['platform'] = 'debian' 87 | node.automatic['os'] = 'linux' 88 | node.normal['gocd']['install_method'] = 'package_file' 89 | end 90 | allow_any_instance_of(Chef::Resource::RemoteFile).to receive(:fetch_content) 91 | .and_return('{"message": "{\"latest-version\": \"16.2.1-3027\"}"}') 92 | run.converge(described_recipe) 93 | end 94 | it_behaves_like :server_recipe 95 | it 'downloads go-server .deb from remote URL' do 96 | expect(chef_run).to create_remote_file('go-server-stable.deb').with( 97 | source: 'https://download.gocd.org/binaries/16.2.1-3027/deb/go-server_16.2.1-3027_all.deb') 98 | end 99 | it 'installs go-server package from file' do 100 | expect(chef_run).to install_dpkg_package('go-server') 101 | end 102 | end 103 | context 'When installing from package file and platform is centos' do 104 | let(:chef_run) do 105 | run = ChefSpec::SoloRunner.new do |node| 106 | node.automatic['platform_family'] = 'rhel' 107 | node.automatic['platform'] = 'centos' 108 | node.automatic['os'] = 'linux' 109 | node.normal['gocd']['install_method'] = 'package_file' 110 | end 111 | allow_any_instance_of(Chef::Resource::RemoteFile).to receive(:fetch_content) 112 | .and_return('{"message": "{\"latest-version\": \"16.2.1-3027\"}"}') 113 | run.converge(described_recipe) 114 | end 115 | it_behaves_like :server_recipe 116 | it 'downloads go-server .rpm from remote URL' do 117 | expect(chef_run).to create_remote_file('go-server-stable.noarch.rpm').with( 118 | source: 'https://download.gocd.org/binaries/16.2.1-3027/rpm/go-server-16.2.1-3027.noarch.rpm') 119 | end 120 | it 'installs go-server package from file' do 121 | expect(chef_run).to install_rpm_package('go-server') 122 | end 123 | end 124 | 125 | context 'When installing from custom repository and platform is debian' do 126 | let(:chef_run) do 127 | run = ChefSpec::SoloRunner.new do |node| 128 | node.automatic['lsb']['id'] = 'Debian' 129 | node.automatic['platform_family'] = 'debian' 130 | node.automatic['platform'] = 'debian' 131 | node.automatic['os'] = 'linux' 132 | node.normal['gocd']['install_method'] = 'repository' 133 | node.normal['gocd']['repository']['apt']['uri'] = 'http://mydeb/repo' 134 | node.normal['gocd']['repository']['apt']['components'] = ['/'] 135 | node.normal['gocd']['repository']['apt']['key'] = false 136 | end 137 | run.converge(described_recipe) 138 | end 139 | it_behaves_like :server_recipe 140 | it 'includes apt recipe' do 141 | expect(chef_run).to include_recipe('apt') 142 | end 143 | it 'adds my custom gocd apt repository' do 144 | expect(chef_run).to add_apt_repository('gocd').with( 145 | uri: 'http://mydeb/repo', 146 | key: [], 147 | components: ['/']) 148 | end 149 | 150 | it 'installs go-server package' do 151 | expect(chef_run).to install_package('go-server') 152 | end 153 | 154 | it 'upgrades go-server package if version is set to `latest`' do 155 | chef_run.node.normal['gocd']['version'] = 'latest' 156 | chef_run.converge(described_recipe) 157 | expect(chef_run).to upgrade_package('go-server') 158 | end 159 | end 160 | context 'When installing from custom repository and platform is centos' do 161 | let(:chef_run) do 162 | run = ChefSpec::SoloRunner.new do |node| 163 | node.automatic['platform_family'] = 'rhel' 164 | node.automatic['platform'] = 'centos' 165 | node.automatic['os'] = 'linux' 166 | node.normal['gocd']['install_method'] = 'repository' 167 | node.normal['gocd']['repository']['yum']['baseurl'] = 'http://mycustom/gocd-rpm' 168 | end 169 | run.converge(described_recipe) 170 | end 171 | it_behaves_like :server_recipe 172 | it 'includes yum recipe' do 173 | expect(chef_run).to include_recipe('yum') 174 | end 175 | it 'adds my custom gocd yum repository' do 176 | expect(chef_run).to create_yum_repository('gocd').with( 177 | baseurl: 'http://mycustom/gocd-rpm', 178 | gpgcheck: true 179 | ) 180 | end 181 | 182 | it 'installs go-server package' do 183 | expect(chef_run).to install_package('go-server') 184 | end 185 | 186 | it 'upgrades go-server package if version is set to `latest`' do 187 | chef_run.node.normal['gocd']['version'] = 'latest' 188 | chef_run.converge(described_recipe) 189 | expect(chef_run).to upgrade_package('go-server') 190 | end 191 | end 192 | end 193 | -------------------------------------------------------------------------------- /spec/go_server_windows_spec.rb: -------------------------------------------------------------------------------- 1 | ########################################################################## 2 | # Copyright 2017 ThoughtWorks, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ########################################################################## 16 | 17 | require 'spec_helper' 18 | 19 | describe 'gocd::server' do 20 | shared_examples_for :service_recipe_windows do 21 | it 'configures go-server service' do 22 | expect(chef_run).to enable_service('Go Server') 23 | expect(chef_run).to start_service('Go Server') 24 | end 25 | end 26 | 27 | context 'When all attributes are default and platform is windows' do 28 | it_behaves_like :service_recipe_windows 29 | let(:chef_run) do 30 | run = ChefSpec::SoloRunner.new(step_into: 'gocd_server') do |node| 31 | node.automatic['platform_family'] = 'windows' 32 | node.automatic['platform'] = 'windows' 33 | node.automatic['os'] = 'windows' 34 | node.automatic['kernel']['os_info']['os_architecture'] = '64-bit' 35 | end 36 | allow_any_instance_of(Chef::Resource::RemoteFile).to receive(:fetch_content) 37 | .and_return('{"message": "{\"latest-version\": \"16.2.1-3027\"}"}') 38 | run.converge(described_recipe) 39 | end 40 | 41 | it 'downloads official installer' do 42 | expect(chef_run).to create_remote_file('go-server-stable-setup.exe').with( 43 | source: 'https://download.gocd.org/binaries/16.2.1-3027/win/go-server-16.2.1-3027-jre-64bit-setup.exe') 44 | end 45 | 46 | it 'installs go-server package' do 47 | expect(chef_run).to install_windows_package('Go Server') 48 | end 49 | end 50 | 51 | context 'When experimental flag is set and platform is windows' do 52 | it_behaves_like :service_recipe_windows 53 | let(:chef_run) do 54 | run = ChefSpec::SoloRunner.new(step_into: 'gocd_server') do |node| 55 | node.automatic['platform_family'] = 'windows' 56 | node.automatic['platform'] = 'windows' 57 | node.automatic['os'] = 'windows' 58 | node.automatic['kernel']['os_info']['os_architecture'] = '64-bit' 59 | node.normal['gocd']['use_experimental'] = true 60 | end 61 | allow_any_instance_of(Chef::Resource::RemoteFile).to receive(:fetch_content) 62 | .with('https://update.gocd.org/channels/experimental/latest.json') 63 | .and_return('{"message": "{\"latest-version\": \"20.1.2-12345\"}"}') 64 | run.converge(described_recipe) 65 | end 66 | 67 | it 'downloads official experimental installer' do 68 | expect(chef_run).to create_remote_file('go-server-experimental-setup.exe').with( 69 | source: 'https://download.gocd.org/binaries/20.1.2-12345/win/go-server-20.1.2-12345-jre-64bit-setup.exe') 70 | end 71 | end 72 | 73 | context 'When installing from custom url and platform is windows' do 74 | it_behaves_like :service_recipe_windows 75 | let(:chef_run) do 76 | run = ChefSpec::SoloRunner.new(step_into: 'gocd_server') do |node| 77 | node.automatic['platform_family'] = 'windows' 78 | node.automatic['platform'] = 'windows' 79 | node.automatic['os'] = 'windows' 80 | node.normal['gocd']['server']['package_file']['url'] = 'https://example.com/go-server.exe' 81 | end 82 | run.converge(described_recipe) 83 | end 84 | 85 | it 'downloads specified installer' do 86 | expect(chef_run).to create_remote_file('go-server-custom-setup.exe').with( 87 | source: 'https://example.com/go-server.exe') 88 | end 89 | 90 | it 'installs go-server package' do 91 | expect(chef_run).to install_windows_package('Go Server') 92 | end 93 | end 94 | end 95 | -------------------------------------------------------------------------------- /spec/libraries/helpers_spec.rb: -------------------------------------------------------------------------------- 1 | ########################################################################## 2 | # Copyright 2017 ThoughtWorks, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ########################################################################## 16 | 17 | require_relative '../spec_helper' 18 | require_relative '../../libraries/helpers' 19 | 20 | RSpec.describe Gocd::Helpers do 21 | let(:my_recipe) { Class.new { extend Gocd::Helpers } } 22 | 23 | it 'parses go version from json message in channel' do 24 | allow(my_recipe).to receive(:fetch_content).with('url').and_return('{"message": "{\"latest-version\": \"16.2.1-3027\"}"}') 25 | expect(my_recipe.fetch_go_version_from_url('url')).to eq '16.2.1-3027' 26 | end 27 | end 28 | -------------------------------------------------------------------------------- /spec/plugin_lwrp_spec.rb: -------------------------------------------------------------------------------- 1 | ########################################################################## 2 | # Copyright 2017 ThoughtWorks, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ########################################################################## 16 | 17 | require 'spec_helper' 18 | 19 | describe 'gocd_test::plugin_lwrp' do 20 | let(:chef_run) do 21 | run = ChefSpec::SoloRunner.new(step_into: 'gocd_plugin') do |node| 22 | node.automatic['lsb']['id'] = 'Debian' 23 | node.automatic['platform_family'] = 'debian' 24 | node.automatic['platform'] = 'debian' 25 | node.automatic['os'] = 'linux' 26 | end 27 | run.converge(described_recipe) 28 | end 29 | 30 | it 'creates gocd_plugin chef resource' do 31 | expect(chef_run).to create_gocd_plugin('github-pr-status') 32 | end 33 | it 'downloads github-pr-status plugin as a remote_file' do 34 | expect(chef_run).to create_remote_file('/var/lib/go-server/plugins/external/github-pr-status.jar') 35 | .with( 36 | source: 'https://github.com/gocd-contrib/gocd-build-status-notifier/releases/download/1.1/github-pr-status-1.1.jar', 37 | owner: 'go' 38 | ) 39 | end 40 | end 41 | -------------------------------------------------------------------------------- /spec/shared_examples.rb: -------------------------------------------------------------------------------- 1 | ########################################################################## 2 | # Copyright 2017 ThoughtWorks, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ########################################################################## 16 | 17 | shared_examples_for :apt_repository_recipe do 18 | before do 19 | stub_command("grep -q '# Provides: go-agent$' /etc/init.d/go-agent").and_return(false) 20 | end 21 | it 'includes apt recipe' do 22 | expect(chef_run).to include_recipe('apt') 23 | end 24 | it 'adds gocd apt repository' do 25 | expect(chef_run).to add_apt_repository('gocd').with( 26 | uri: 'https://download.gocd.org', 27 | keyserver: 'pgp.mit.edu', 28 | key: ['https://download.gocd.org/GOCD-GPG-KEY.asc'], 29 | components: ['/']) 30 | end 31 | it 'adds gocd experimental apt repository if experimental flag is turned on' do 32 | chef_run.node.normal['gocd']['use_experimental'] = true 33 | chef_run.converge(described_recipe) 34 | expect(chef_run).to add_apt_repository('gocd').with( 35 | uri: 'https://download.gocd.org/experimental', 36 | keyserver: 'pgp.mit.edu', 37 | key: ['https://download.gocd.org/GOCD-GPG-KEY.asc'], 38 | components: ['/']) 39 | end 40 | end 41 | 42 | shared_examples_for :yum_repository_recipe do 43 | before do 44 | stub_command("grep -q '# Provides: go-agent$' /etc/init.d/go-agent").and_return(false) 45 | end 46 | it 'includes yum recipe' do 47 | expect(chef_run).to include_recipe('yum') 48 | end 49 | it 'adds gocd yum repository' do 50 | expect(chef_run).to create_yum_repository('gocd').with( 51 | baseurl: 'https://download.gocd.org', 52 | description: 'GoCD YUM Repository', 53 | gpgcheck: true, 54 | gpgkey: 'https://download.gocd.org/GOCD-GPG-KEY.asc' 55 | ) 56 | end 57 | it 'adds gocd experimental yum repository if experimental flag is turned on' do 58 | chef_run.node.normal['gocd']['use_experimental'] = true 59 | chef_run.converge(described_recipe) 60 | expect(chef_run).to create_yum_repository('gocd').with( 61 | baseurl: 'https://download.gocd.org/experimental', 62 | description: 'GoCD YUM Repository', 63 | gpgcheck: true, 64 | gpgkey: 'https://download.gocd.org/GOCD-GPG-KEY.asc' 65 | ) 66 | end 67 | end 68 | 69 | shared_examples_for :agent_linux_install do 70 | before do 71 | stub_command("grep -q '# Provides: go-agent$' /etc/init.d/go-agent").and_return(false) 72 | end 73 | 74 | it 'includes java recipe' do 75 | expect(chef_run).to include_recipe('java::default') 76 | end 77 | 78 | it 'includes the gocd::ohai recipe' do 79 | expect(chef_run).to include_recipe('gocd::ohai') 80 | end 81 | 82 | it 'includes gocd::agent_linux_install recipe' do 83 | expect(chef_run).to include_recipe('gocd::agent_linux_install') 84 | end 85 | end 86 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | ########################################################################## 2 | # Copyright 2017 ThoughtWorks, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ########################################################################## 16 | 17 | require 'chefspec' 18 | require 'chefspec/berkshelf' 19 | require_relative 'shared_examples' 20 | ChefSpec::Coverage.start! 21 | -------------------------------------------------------------------------------- /templates/default/autoregister.properties.erb: -------------------------------------------------------------------------------- 1 | # 2 | # File autogenerated by chef. All changes will be lost 3 | # 4 | 5 | agent.auto.register.key = <%= @key %> 6 | agent.auto.register.hostname = <%= @hostname %> 7 | 8 | <% if @autoregister_environments %> 9 | agent.auto.register.environments = <%= [@autoregister_environments].flatten.join(', ') %> 10 | <% end %> 11 | 12 | <% if @autoregister_resources %> 13 | agent.auto.register.resources = <%= [@autoregister_resources].flatten.join(', ') %> 14 | <% end %> 15 | 16 | <% if @elastic_agent_plugin_id %> 17 | agent.auto.register.elasticAgent.pluginId = <%= @elastic_agent_plugin_id %> 18 | <% end %> 19 | <% if @elastic_agent_id %> 20 | agent.auto.register.elasticAgent.agentId = <%= @elastic_agent_id %> 21 | <% end %> 22 | 23 | -------------------------------------------------------------------------------- /templates/default/go-agent-default.erb: -------------------------------------------------------------------------------- 1 | # 2 | # File autogenerated by chef. All changes will be lost 3 | # 4 | 5 | export GO_SERVER_URL=<%= @go_server_url %> 6 | export JAVA_HOME=<%= node['java']['java_home'] %> 7 | export AGENT_WORK_DIR=<%= @workspace %> 8 | DAEMON=<%= @daemon ? 'Y' : 'N' %> 9 | VNC=<%= @vnc ? 'Y' : 'N' %> 10 | 11 | <% node['gocd']['agent']['default_extras'].each do |k, v| %> 12 | export <%= k %>="<%= v %>" 13 | <% end %> 14 | -------------------------------------------------------------------------------- /templates/default/go-server-default.erb: -------------------------------------------------------------------------------- 1 | # 2 | # File autogenerated by chef. All changes will be lost 3 | # 4 | 5 | 6 | export GO_SERVER_PORT=<%= node['gocd']['server']['http_port'] %> 7 | export GO_SERVER_SSL_PORT=<%= node['gocd']['server']['https_port'] %> 8 | 9 | export SERVER_MEM=<%= node['gocd']['server']['min_mem'] %> 10 | export SERVER_MAX_MEM=<%= node['gocd']['server']['max_mem'] %> 11 | export SERVER_MAX_PERM_GEN=<%= node['gocd']['server']['max_perm_gen'] %> 12 | export SERVER_WORK_DIR=<%= node['gocd']['server']['work_dir']%> 13 | 14 | export JAVA_HOME=<%= node['java']['java_home'] %> 15 | 16 | DAEMON=Y 17 | ENABLE_PLUGINS=Y 18 | <% node['gocd']['server']['default_extras'].each do |k, v| %> 19 | <%= k %>="<%= v %>" 20 | <% end %> -------------------------------------------------------------------------------- /test/integration/default/serverspec/go_agent_daemon_spec.rb: -------------------------------------------------------------------------------- 1 | ########################################################################## 2 | # Copyright 2017 ThoughtWorks, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ########################################################################## 16 | 17 | require 'serverspec' 18 | 19 | # Required by serverspec 20 | set :backend, :exec 21 | 22 | describe 'go agent package' do 23 | it 'should be installed' do 24 | expect(package('go-agent')).to be_installed 25 | end 26 | end 27 | 28 | describe 'go agent service' do 29 | it 'should be running' do 30 | expect(service('go-agent')).to be_running 31 | expect(service('go-agent')).to be_enabled 32 | end 33 | end 34 | 35 | describe '/etc/default/go-agent' do 36 | it 'should have the correct ownership and mode' do 37 | expect(file('/etc/default/go-agent')).to exist 38 | expect(file('/etc/default/go-agent')).to be_readable 39 | expect(file('/etc/default/go-agent')).to be_mode(644) 40 | expect(file('/etc/default/go-agent')).to be_owned_by('root') 41 | expect(file('/etc/default/go-agent')).to be_grouped_into('root') 42 | end 43 | end 44 | -------------------------------------------------------------------------------- /test/integration/default/serverspec/go_autoregister_spec.rb: -------------------------------------------------------------------------------- 1 | ########################################################################## 2 | # Copyright 2017 ThoughtWorks, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ########################################################################## 16 | 17 | require 'serverspec' 18 | 19 | # Required by serverspec 20 | set :backend, :exec 21 | 22 | describe 'go server agents tab' do 23 | describe command('curl -H \'Accept: application/vnd.go.cd.v5+json\' localhost:8153/go/api/agents') do 24 | its(:stdout) { should contain('/var/lib/go-agent') } 25 | its(:stdout) { should contain('Idle') } 26 | end 27 | end 28 | -------------------------------------------------------------------------------- /test/integration/default/serverspec/go_server_daemon_spec.rb: -------------------------------------------------------------------------------- 1 | ########################################################################## 2 | # Copyright 2017 ThoughtWorks, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ########################################################################## 16 | 17 | require 'serverspec' 18 | 19 | # Required by serverspec 20 | set :backend, :exec 21 | 22 | describe 'go server package' do 23 | it 'should be installed' do 24 | expect(package('go-server')).to be_installed 25 | end 26 | end 27 | 28 | describe 'go server service' do 29 | it 'should be running' do 30 | expect(service('go-server')).to be_running 31 | expect(service('go-server')).to be_enabled 32 | end 33 | 34 | it 'should be listening on port 8153' do 35 | expect(port(8153)).to be_listening 36 | end 37 | 38 | it 'should be listening on port 8154' do 39 | expect(port(8154)).to be_listening 40 | end 41 | end 42 | 43 | describe '/etc/default/go-server' do 44 | it 'should have the correct ownership and mode' do 45 | expect(file('/etc/default/go-server')).to exist 46 | expect(file('/etc/default/go-server')).to be_readable 47 | expect(file('/etc/default/go-server')).to be_mode(644) 48 | expect(file('/etc/default/go-server')).to be_owned_by('root') 49 | expect(file('/etc/default/go-server')).to be_grouped_into('root') 50 | end 51 | end 52 | -------------------------------------------------------------------------------- /test/integration/golangagent/serverspec/go_agent_daemon_spec.rb: -------------------------------------------------------------------------------- 1 | ########################################################################## 2 | # Copyright 2017 ThoughtWorks, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ########################################################################## 16 | 17 | require 'serverspec' 18 | 19 | # Required by serverspec 20 | set :backend, :exec 21 | 22 | describe '/etc/default/go-agent' do 23 | it 'should have the correct ownership and mode' do 24 | expect(file('/etc/default/go-agent')).to exist 25 | expect(file('/etc/default/go-agent')).to be_readable 26 | expect(file('/etc/default/go-agent')).to be_mode(644) 27 | expect(file('/etc/default/go-agent')).to be_owned_by('root') 28 | expect(file('/etc/default/go-agent')).to be_grouped_into('root') 29 | end 30 | end 31 | -------------------------------------------------------------------------------- /test/integration/golangagent/serverspec/go_autoregister_spec.rb: -------------------------------------------------------------------------------- 1 | ########################################################################## 2 | # Copyright 2017 ThoughtWorks, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ########################################################################## 16 | 17 | require 'serverspec' 18 | 19 | # Required by serverspec 20 | set :backend, :exec 21 | 22 | describe 'go server agents tab' do 23 | describe command('curl -L http://localhost:8153/go/api/v1/health') do 24 | its(:stdout) { should contain('"health": "OK"') } 25 | end 26 | 27 | describe command('curl -H \'Accept: application/vnd.go.cd.v5+json\' http://localhost:8153/go/api/agents') do 28 | its(:stdout) { should contain('/var/lib/go-agent') } 29 | its(:stdout) { should contain('Idle') } 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /test/integration/golangagent/serverspec/go_server_daemon_spec.rb: -------------------------------------------------------------------------------- 1 | ########################################################################## 2 | # Copyright 2017 ThoughtWorks, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ########################################################################## 16 | 17 | require 'serverspec' 18 | 19 | # Required by serverspec 20 | set :backend, :exec 21 | 22 | describe 'go server package' do 23 | it 'should be installed' do 24 | expect(package('go-server')).to be_installed 25 | end 26 | end 27 | 28 | describe 'go server service' do 29 | it 'should be running' do 30 | expect(service('go-server')).to be_running 31 | expect(service('go-server')).to be_enabled 32 | end 33 | 34 | it 'should be listening on port 8153' do 35 | expect(port(8153)).to be_listening 36 | end 37 | 38 | it 'should be listening on port 8154' do 39 | expect(port(8154)).to be_listening 40 | end 41 | end 42 | 43 | describe '/etc/default/go-server' do 44 | it 'should have the correct ownership and mode' do 45 | expect(file('/etc/default/go-server')).to exist 46 | expect(file('/etc/default/go-server')).to be_readable 47 | expect(file('/etc/default/go-server')).to be_mode(644) 48 | expect(file('/etc/default/go-server')).to be_owned_by('root') 49 | expect(file('/etc/default/go-server')).to be_grouped_into('root') 50 | end 51 | end 52 | -------------------------------------------------------------------------------- /test/test_cookbook/metadata.rb: -------------------------------------------------------------------------------- 1 | name 'gocd_test' 2 | version '0.0.1' 3 | 4 | depends 'gocd' 5 | -------------------------------------------------------------------------------- /test/test_cookbook/recipes/agent_autoregister_file_lwrp.rb: -------------------------------------------------------------------------------- 1 | ########################################################################## 2 | # Copyright 2017 ThoughtWorks, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ########################################################################## 16 | 17 | gocd_agent_autoregister_file '/var/mygo/autoregister.properties' do 18 | autoregister_key 'bla-key' 19 | autoregister_hostname 'mygo-agent' 20 | autoregister_environments 'stage' 21 | autoregister_resources ['java-8', 'ruby'] 22 | end 23 | 24 | gocd_agent_autoregister_file '/var/elastic/autoregister.properties' do 25 | autoregister_key 'some-key' 26 | autoregister_hostname 'elastic-agent' 27 | autoregister_environments 'testing' 28 | autoregister_resources ['java-8'] 29 | elastic_agent_id 'agent-id' 30 | elastic_agent_plugin_id 'elastic-agent-plugin-id' 31 | end 32 | 33 | gocd_agent_autoregister_file '/var/attrs/autoregister.properties' do 34 | autoregister_key 'some-key' 35 | end 36 | -------------------------------------------------------------------------------- /test/test_cookbook/recipes/default_agent_lwrp.rb: -------------------------------------------------------------------------------- 1 | ########################################################################## 2 | # Copyright 2017 ThoughtWorks, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ########################################################################## 16 | 17 | gocd_agent 'my-go-agent' do 18 | workspace '/mnt/big_drive' 19 | end 20 | -------------------------------------------------------------------------------- /test/test_cookbook/recipes/plugin_lwrp.rb: -------------------------------------------------------------------------------- 1 | ########################################################################## 2 | # Copyright 2017 ThoughtWorks, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ########################################################################## 16 | 17 | include_recipe 'gocd::server' 18 | 19 | gocd_plugin 'github-pr-status' do 20 | plugin_uri 'https://github.com/gocd-contrib/gocd-build-status-notifier/releases/download/1.1/github-pr-status-1.1.jar' 21 | end 22 | -------------------------------------------------------------------------------- /test/test_cookbook/recipes/single_agent_lwrp.rb: -------------------------------------------------------------------------------- 1 | ########################################################################## 2 | # Copyright 2017 ThoughtWorks, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ########################################################################## 16 | 17 | gocd_agent 'my-go-agent' do 18 | go_server_url 'https://go.example.com:443/go' 19 | daemon true 20 | vnc true 21 | autoregister_key 'bla-key' 22 | autoregister_hostname 'my-lwrp-agent' 23 | autoregister_environments 'production' 24 | autoregister_resources ['java-8', 'ruby-2.2'] 25 | workspace '/mnt/big_drive' 26 | end 27 | --------------------------------------------------------------------------------