Skip to content

Commit

Permalink
improve version handling and installing on windows gocd#63 gocd#67
Browse files Browse the repository at this point in the history
installing of packages with versions and channels —

* setting `node['gocd']['use_experimental']` will use experimental
  repositories
* setting `node['gocd']['version']` to `latest` will `action :upgrade`
  on the package

fix attributes to be wrapper-cookbooks friendly

don't use if node['gocd']... statements in attributes/default.rb

ensure apt https support

added windows setup for kitchen
  • Loading branch information
tomzo committed Apr 20, 2016
1 parent adba83d commit ced2a72
Show file tree
Hide file tree
Showing 17 changed files with 436 additions and 103 deletions.
13 changes: 13 additions & 0 deletions .kitchen.openstack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@ platforms:
flavor: 'v.c1.m2048.d5.e0'
server_create_timeout: 540
server_active_timeout: 540
- name: windows
provisioner:
name: chef_solo
require_chef_omnibus: 12.4.2
driver:
name: vagrant
driver_config:
box: 'windows-7-net45-2.0-chef-12.4.2'
customize:
flavor: 'v.c1.m2048.d20.e0'
server_create_timeout: 1200
server_active_timeout: 1200
server_name: 'kt-go-win'

suites:
- name: default
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ gem 'kitchen-vagrant'
gem 'kitchen-ec2', '~> 0.8.0'
gem 'kitchen-digitalocean', '~> 0.7.3'
gem 'kitchen-docker'
gem 'winrm-transport', '= 1.0.2'
24 changes: 24 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ GEM
formatador (0.2.5)
gherkin (2.12.2)
multi_json (~> 1.3)
gssapi (1.2.0)
ffi (>= 1.0.1)
gyoku (1.3.1)
builder (>= 2.1.2)
hashie (3.4.3)
highline (1.7.8)
hitimes (1.2.3)
Expand All @@ -220,6 +224,10 @@ GEM
kitchen-vagrant (0.19.0)
test-kitchen (~> 1.4)
libyajl2 (1.2.0)
little-plugger (1.1.4)
logging (1.8.2)
little-plugger (>= 1.1.3)
multi_json (>= 1.8.4)
method_source (0.8.2)
mime-types (2.6.2)
mini_portile (0.6.2)
Expand All @@ -244,6 +252,7 @@ GEM
nio4r (1.1.1)
nokogiri (1.6.6.2)
mini_portile (~> 0.6.0)
nori (2.6.0)
octokit (3.8.0)
sawyer (~> 0.6.0, >= 0.5.3)
ohai (8.7.0)
Expand Down Expand Up @@ -304,6 +313,8 @@ GEM
rspec_junit_formatter (0.2.3)
builder (< 4)
rspec-core (>= 2, < 4, != 2.12.0)
rubyntlm (0.4.0)
rubyzip (1.1.7)
rufus-lru (1.0.5)
safe_yaml (1.0.4)
sawyer (0.6.0)
Expand Down Expand Up @@ -342,6 +353,18 @@ GEM
varia_model (0.4.1)
buff-extensions (~> 1.0)
hashie (>= 2.0.2, < 4.0.0)
winrm (1.3.4)
builder (>= 2.1.2)
gssapi (~> 1.2)
gyoku (~> 1.0)
httpclient (~> 2.2, >= 2.2.0.2)
logging (~> 1.6, >= 1.6.1)
nori (~> 2.0)
rubyntlm (~> 0.4.0)
uuidtools (~> 2.1.2)
winrm-transport (1.0.2)
rubyzip (~> 1.1, >= 1.1.7)
winrm (~> 1.3)
wmi-lite (1.0.0)
yajl-ruby (1.2.1)

Expand All @@ -358,6 +381,7 @@ DEPENDENCIES
kitchen-ec2 (~> 0.8.0)
kitchen-vagrant
test-kitchen
winrm-transport (= 1.0.2)

BUNDLED WITH
1.10.5
32 changes: 19 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,26 @@ By default installation source is done from apt or yum repositories from officia

The **apt** repository can be overriden by changing any these attributes:

```ruby
default['gocd']['repository']['apt']['uri'] = 'https://download.go.cd/'
default['gocd']['repository']['apt']['components'] = [ '/' ]
default['gocd']['repository']['apt']['distribution'] = ''
default['gocd']['repository']['apt']['package_options'] = ''
default['gocd']['repository']['apt']['keyserver'] = 'pgp.mit.edu'
default['gocd']['repository']['apt']['key'] = '0xd8843f288816c449'
```
* `node['gocd']['repository']['apt']['uri'] = 'https://download.go.cd/'`
* `node['gocd']['repository']['apt']['components'] = [ '/' ]`
* `node['gocd']['repository']['apt']['distribution'] = ''`
* `node['gocd']['repository']['apt']['package_options'] = ''`
* `node['gocd']['repository']['apt']['keyserver'] = 'pgp.mit.edu'`
* `node['gocd']['repository']['apt']['key'] = '0xd8843f288816c449'`

The **yum** repository can be overriden by changing any these attributes:

```ruby
default['gocd']['repository']['yum']['baseurl'] = 'https://download.go.cd'
default['gocd']['repository']['yum']['gpgcheck'] = true
default['gocd']['repository']['yum']['gpgkey'] = 'https://download.go.cd/GOCD-GPG-KEY.asc'
* `node['gocd']['repository']['yum']['baseurl'] = 'https://download.go.cd'`
* `node['gocd']['repository']['yum']['gpgcheck'] = true`
* `node['gocd']['repository']['yum']['gpgkey'] = 'https://download.go.cd/GOCD-GPG-KEY.asc'`

#### Experimental channel

By default Go cookbook installs latest stable version.
You can install gocd from experimental channel by setting

```
node['gocd']['use_experimental'] = true
```

### From remote file
Expand All @@ -69,7 +74,8 @@ And assign base url where packages are available for download
node['gocd']['package_file']['baseurl'] = 'http://my/custom/url'
```

The final download URL of file is built based on platform and `node['gocd']['version']`. E.g. `http://my/custom/url/go-agent-15.2.0-2520.deb`
The final download URL of file is built based on platform and `node['gocd']['version']`.
E.g. `http://my/custom/url/go-agent-15.2.0-2520.deb`

# GoCD Server

Expand Down
56 changes: 14 additions & 42 deletions attributes/repository.rb
Original file line number Diff line number Diff line change
@@ -1,50 +1,22 @@
default['gocd']['install_method'] = 'repository'
default['gocd']['download']['baseurl'] = 'https://download.go.cd'
default['gocd']['version'] = nil # can be `latest` or specify a version `X.Y.Z-ABCD`
default['gocd']['use_experimental'] = false

default['gocd']['repository']['apt']['uri'] = node['gocd']['download']['baseurl']
default['gocd']['repository']['apt']['components'] = [ '/' ]
if node['platform_family'] == 'windows'
default['gocd']['install_method'] = 'package_file'
else
default['gocd']['install_method'] = 'repository'
end

default['gocd']['updates']['url'] = nil

default['gocd']['repository']['apt']['components'] = ['/']
default['gocd']['repository']['apt']['distribution'] = ''
default['gocd']['repository']['apt']['package_options'] = ''
default['gocd']['repository']['apt']['keyserver'] = 'pgp.mit.edu'
default['gocd']['repository']['apt']['key'] = '0xd8843f288816c449'

default['gocd']['repository']['yum']['baseurl'] = node['gocd']['download']['baseurl']
default['gocd']['repository']['yum']['gpgcheck'] = true
default['gocd']['repository']['yum']['gpgkey'] = 'https://download.go.cd/GOCD-GPG-KEY.asc'

case node['gocd']['install_method']
when 'repository'
# version = nil so just pick latest available
else
default['gocd']['version'] = '16.2.1-3027'
end

version = node['gocd']['version']
os_dir = nil

case node['platform_family']
when 'debian'
default['gocd']['server']['package_file']['filename'] = "go-server-#{version}.deb"
default['gocd']['agent']['package_file']['filename'] = "go-agent-#{version}.deb"
default['gocd']['package_file']['baseurl'] = node['gocd']['download']['baseurl']
os_dir = 'deb'
when 'rhel', 'fedora'
default['gocd']['server']['package_file']['filename'] = "go-server-#{version}.noarch.rpm"
default['gocd']['agent']['package_file']['filename'] = "go-agent-#{version}.noarch.rpm"
default['gocd']['package_file']['baseurl'] = node['gocd']['download']['baseurl']
os_dir = 'rpm'
when 'windows'
default['gocd']['server']['package_file']['filename'] = "go-server-#{version}-setup.exe"
default['gocd']['agent']['package_file']['filename'] = "go-agent-#{version}-setup.exe"
default['gocd']['package_file']['baseurl'] = node['gocd']['download']['baseurl']
os_dir = 'win'
end

default['gocd']['server']['package_file']['path'] =
File.join(Chef::Config[:file_cache_path], node['gocd']['server']['package_file']['filename'])
default['gocd']['server']['package_file']['url'] =
"#{node['gocd']['package_file']['baseurl']}/binaries/#{version}/#{os_dir}/#{node['gocd']['server']['package_file']['filename']}"
default['gocd']['agent']['package_file']['path'] =
File.join(Chef::Config[:file_cache_path], node['gocd']['agent']['package_file']['filename'])
default['gocd']['agent']['package_file']['url'] =
"#{node['gocd']['package_file']['baseurl']}/binaries/#{version}/#{os_dir}/#{node['gocd']['agent']['package_file']['filename']}"
default['gocd']['package_file']['baseurl'] = nil # official - "https://download.go.cd/binaries"
default['gocd']['agent']['package_file']['url'] = nil # official
default['gocd']['server']['package_file']['url'] = nil # official
163 changes: 161 additions & 2 deletions libraries/helpers.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
require 'open-uri'

module Gocd
module Helpers
def fetch_content url
open(url, 'r').read
end

def get_agent_properties
values = {}
values[:go_server_port] = node['gocd']['agent']['go_server_port']
values[:go_server_port] = node['gocd']['agent']['go_server_port']
if Chef::Config['solo'] || node['gocd']['agent']['go_server_host']
Chef::Log.info("Attempting to use node['gocd']['agent']['go_server_host'] attribute for server host")
values[:go_server_host] = node['gocd']['agent']['go_server_host']
values[:go_server_host] = node['gocd']['agent']['go_server_host']
values[:key] = node['gocd']['agent']['autoregister']['key']
else
server_search_query = node['gocd']['agent']['server_search_query']
Expand Down Expand Up @@ -41,6 +47,159 @@ def go_server_config_file
'/etc/go/cruise-config.xml'
end
end

def latest_version?
user_requested_version == 'latest'
end

def experimental?
node['gocd']['use_experimental']
end

# version to pass into 'package' resource
def user_requested_version
# just return attribute value, when nil it will default to installing stable
node['gocd']['version']
end

# Only needed when downloading package from URL
def remote_version
if latest_version? || user_requested_version.nil? || user_requested_version.empty?
fetch_go_version(experimental?)
else
user_requested_version
end
end

def updates_base_feed
node['gocd']['updates']['baseurl']
end

def updates_url
if node['gocd']['updates']['url']
# user provided updates url
node['gocd']['updates']['url']
elsif node['gocd']['use_experimental']
'https://update.go.cd/channels/experimental/latest.json'
else
'https://update.go.cd/channels/supported/latest.json'
end
end

def fetch_go_version(_is_experimental)
url = updates_url

begin
fetch_go_version_from_url url
rescue => e
Chef::Log.error("Failed to get Go version from updates service - #{e}")
# fallback to last known stable
'16.3.0-3183'
end
end

def fetch_go_version_from_url url
text = fetch_content url
if text.empty?
fail 'text is empty'
end
parsed = JSON.parse(text)
fail 'Invalid format in version json file' unless parsed['message']
message = JSON.parse(parsed['message'])
return message['latest-version']
end

def package_extension
value_for_platform_family('debian' => '.deb',
%w(rhel fedora) => '.noarch.rpm',
'windows' => '-setup.exe',
'default' => '.zip')
end

def os_dir
value_for_platform_family('debian' => 'deb',
%w(rhel fedora) => 'rpm',
'windows' => 'win',
'default' => 'generic')
end

def go_agent_remote_package_name
"go-agent-#{remote_version}#{package_extension}"
end

def go_server_remote_package_name
"go-server-#{remote_version}#{package_extension}"
end

def user_friendly_version(component)
if node['gocd']['version']
return node['gocd']['version']
elsif node['gocd'][component]['package_file']['url']
return 'custom'
elsif experimental?
return 'experimental'
else
return 'stable'
end
end

# user-friendly file names to use when downloading remote file
def go_agent_package_name
"go-agent-#{user_friendly_version('agent')}#{package_extension}"
end

def go_server_package_name
"go-server-#{user_friendly_version('server')}#{package_extension}"
end

def yum_uri
if node['gocd']['repository']['yum']['baseurl']
# user provided yum URI
node['gocd']['repository']['yum']['baseurl']
elsif node['gocd']['use_experimental']
'https://download.go.cd/experimental'
else
'https://download.go.cd'
end
end

def apt_uri
if node['gocd']['repository']['apt']['uri']
# user provided apt URI
node['gocd']['repository']['apt']['uri']
elsif node['gocd']['use_experimental']
'https://download.go.cd/experimental'
else
'https://download.go.cd'
end
end

def go_baseurl
if node['gocd']['package_file']['baseurl']
# user specifed url to download packages from
node['gocd']['package_file']['baseurl']
else
# use official source
"https://download.go.cd/binaries"
end
end

def go_agent_package_url
if node['gocd']['agent']['package_file']['url']
# user specifed explictly the URL to download from
node['gocd']['agent']['package_file']['url']
else
"#{go_baseurl}/#{remote_version}/#{os_dir}/#{go_agent_remote_package_name}"
end
end
def go_server_package_url
if node['gocd']['server']['package_file']['url']
# user specifed explictly the URL to download from
node['gocd']['server']['package_file']['url']
else
"#{go_baseurl}/#{remote_version}/#{os_dir}/#{go_server_remote_package_name}"
end
end
end
end

Expand Down
Loading

0 comments on commit ced2a72

Please sign in to comment.