Skip to content
This repository was archived by the owner on Feb 18, 2020. It is now read-only.

Support installation from other sources #50

Open
tomzo opened this issue Aug 15, 2015 · 6 comments
Open

Support installation from other sources #50

tomzo opened this issue Aug 15, 2015 · 6 comments

Comments

@tomzo
Copy link
Member

tomzo commented Aug 15, 2015

Currently source of Go installation is hard-coded to official thoughtworks repository.

It could be possible to install from alternative repository (e.g. mirror) or from raw package files.

tomzo added a commit to tomzo/go-cookbook that referenced this issue Aug 15, 2015
Refactored adding apt or rpm repository to separate recipe intead of
repeating code in agent and server recipe

Added possible installation from remote_file.

Default install method is still thoughtworks repository

Updated and fixed readme
tomzo added a commit to ketan/go-cookbook that referenced this issue Oct 10, 2015
Refactored adding apt or rpm repository to separate recipe intead of
repeating code in agent and server recipe

Added possible installation from remote_file.

Default install method is still thoughtworks repository

Updated and fixed readme
tomzo added a commit to ketan/go-cookbook that referenced this issue Oct 10, 2015
Refactored adding apt or rpm repository to separate recipe intead of
repeating code in agent and server recipe

Added possible installation from remote_file.

Default install method is still thoughtworks repository

Updated and fixed readme
@ketan
Copy link
Member

ketan commented Oct 15, 2015

I'm going to add the recipes here instead of on #52 since this feels more appropriate.

Recipe to install go agent via zip file.

install_path = 'C:\go-agent-15.2.0'

directory install_path do
  rights :full_control, 'gocd', :applies_to_children => true
end

server_search_query = "chef_environment:#{node.chef_environment} AND recipes:go-server\\:\\:default"
Chef::Log.info("Search query: #{server_search_query}")
go_servers = search(:node, server_search_query)
if go_servers.count == 0
  Chef::Log.warn("No Go servers found on any of the nodes running chef client.")
else
  go_server = go_servers.first
  go_server_host = go_server['ipaddress']
  if go_servers.count > 1
    Chef::Log.warn("Multiple Go servers found on Chef server. Using first returned server '#{go_server_host}' for server instance configuration.")
  end
  Chef::Log.info("Found Go server at ip address #{go_server_host} with automatic agent registration")
  if autoregister_key = go_server['gocd']['server']['autoregister_key']
    Chef::Log.warn("Agent auto-registration enabled. This agent will not require approval to become active.")
  end
end

if go_server_host.nil?
  go_server_host = '127.0.0.1'
  Chef::Log.warn("Go server not found on Chef server. Defaulting Go server to #{go_server_host}")
end

if autoregister_key
  directory "#{install_path}/config" do
    recursive true
  end

  template "#{install_path}/config/autoregister.properties" do
    not_if { File.exists? ("#{install_path}/config/agent.jks") }
    variables({
                key:            autoregister_key,
                hostname:       node['gocd']['agent']['autoregister']['hostname'],
                environments:   node['gocd']['agent']['autoregister']['environments'],
                resources:      node['gocd']['agent']['autoregister']['resources'],
    })
  end
end

env 'GO_SERVER' do
  value go_server_host
end

include_recipe '7-zip'

zipfile = "#{Chef::Config[:file_cache_path]}\\go-agent-15.2.0-2248.zip"

remote_file zipfile do
  source    'https://download.go.cd/gocd/go-agent-15.2.0-2248.zip'
  checksum  '72fb2ed793401b46d73236d9c7a92e7e991f8b8b5f832c545a99eeff1fb0c8d9'
  not_if    {::File.exist?('C:\go-agent-15.2.0\agent.cmd') }
end

windows_batch 'Unzip Go Agent' do
  code <<-EOH
  "C:\\Program Files (x86)\\Git\\bin\\unzip.exe" -qo #{zipfile} -d C:\\
  EOH
  creates    'C:\go-agent-15.2.0\agent.cmd'
end

java_home = win_friendly_path(node['java']['java_home'])
env 'GO_AGENT_JAVA_HOME' do
  value java_home
  notifies :reboot_now, 'reboot[reboot-on-provision]', :immediately
end

@ketan
Copy link
Member

ketan commented Oct 15, 2015

Recipe to install go agent via installer

install_path = 'C:\GoAgent'

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")
  go_server_host   = node['gocd']['agent']['go_server_host']
  autoregister_key = node['gocd']['agent']['autoregister']['key']
else
  server_search_query = node['gocd']['agent']['server_search_query']
  Chef::Log.info("Search query: #{server_search_query}")
  go_servers = search(:node, server_search_query)
  if go_servers.count == 0
    Chef::Log.warn("No Go servers found on any of the nodes running chef client.")
  else
    go_server = go_servers.first
    go_server_host = go_server['ipaddress']
    if go_servers.count > 1
      Chef::Log.warn("Multiple Go servers found on Chef server. Using first returned server '#{go_server_host}' for server instance configuration.")
    end
    Chef::Log.info("Found Go server at ip address #{go_server_host} with automatic agent registration")
    if autoregister_key = go_server['gocd']['server']['autoregister_key']
      Chef::Log.warn("Agent auto-registration enabled. This agent will not require approval to become active.")
    end
  end
end

if go_server_host.nil?
  go_server_host = '127.0.0.1'
  Chef::Log.warn("Go server not found on Chef server or not specifed via node['gocd']['agent']['go_server_host'] attribute, defaulting Go server to #{go_server_host}")
end


if autoregister_key
  directory "#{install_path}/config" do
    recursive true
  end

  template "#{install_path}/config/autoregister.properties" do
    not_if { File.exists? ("#{install_path}/config/agent.jks") }
    if node['gocd']['agent']['windows']['enable_service']
      notifies :restart,      "windows_service[Go Agent]"
    end
    variables({
                key:            autoregister_key,
                hostname:       node['gocd']['agent']['autoregister']['hostname'],
                environments:   node['gocd']['agent']['autoregister']['environments'],
                resources:      node['gocd']['agent']['autoregister']['resources'],
    })
  end
end

opts = []
opts << "/SERVERIP=#{go_server_host}"
opts << "/D=#{install_path}"

windows_package 'Go Agent' do
  source "https://download.go.cd/gocd/go-agent-#{node['gocd']['agent']['version']}-setup.exe"
  options opts.join(' ')
  action :install
end

windows_service 'Go Agent' do
  if node['gocd']['agent']['windows']['enable_service']
    action       :configure_startup
    startup_type :automatic
  else
    action :stop
    startup_type :disabled
  end
end

@ketan
Copy link
Member

ketan commented Oct 15, 2015

Clearly there's a lot of copy paste that has happened, and it should be possible to DRY up and improve the recipes.

@tomzo
Copy link
Member Author

tomzo commented Oct 15, 2015

@ketan I'll pick this up. Thanks for these recipes. They are definitely something to start with.

If you had some issues when deploying windows recently then I would appreciate if you mentioned them.
Did you do deployments from your develop branch + some wrapper?

@ketan
Copy link
Member

ketan commented Oct 15, 2015

there was no wrapper, just a frankenstein recipe based on merging the linux agent recipe(for the autoregistration) and the existing agent windows recipe.

What I've provided is an exact copy of what's running on our servers. We tried the install via installer method but instead wrote the install via zip recipe for various reasons (run as service, desktop interaction, selenium IE driver).

Both of them "work" in that they install and configure the agent as expected.

tomzo added a commit to tomzo/go-cookbook that referenced this issue Oct 25, 2015
tomzo added a commit to tomzo/go-cookbook that referenced this issue Oct 25, 2015
tomzo added a commit to tomzo/go-cookbook that referenced this issue Oct 25, 2015
tomzo added a commit to tomzo/go-cookbook that referenced this issue Oct 25, 2015
@tomzo
Copy link
Member Author

tomzo commented Oct 25, 2015

I have dealt with linux cases already.

Installations are supported from

  • official repository
  • private repository
  • from remote package file

It makes sense to zip, especially in windows. I will work on it soon.

tomzo added a commit to tomzo/go-cookbook that referenced this issue Oct 26, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants