Skip to content

Commit

Permalink
Update the server resource to use the new style in resources (#96)
Browse files Browse the repository at this point in the history
Adds an uninstall step like the tentacle resource

Includes a breaking change:
 - The remove step now deletes the instance and doesnt uninstall like it
previously did.
  • Loading branch information
brentm5 authored May 18, 2017
1 parent 580d83b commit 25d74fe
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 177 deletions.
4 changes: 4 additions & 0 deletions libraries/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@
# limitations under the License.
#

require_relative 'shared'

module OctopusDeploy
# A container to hold the server values instead of attributes
module Server
include OctopusDeploy::Shared

def display_name
'Octopus Deploy Server'
end
Expand Down
2 changes: 2 additions & 0 deletions libraries/tentacle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
# limitations under the License.
#

require_relative 'shared'

module OctopusDeploy
# A container to hold the tentacle values instead of attributes
module Tentacle
Expand Down
156 changes: 0 additions & 156 deletions providers/server.rb

This file was deleted.

140 changes: 127 additions & 13 deletions resources/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,132 @@
# limitations under the License.
#

actions :install, :configure, :remove
include OctopusDeploy::Server

resource_name 'octopus_deploy_server'

property :instance, String, default: 'OctopusServer'
property :version, String, required: true
property :checksum, String
property :home_path, String, default: 'C:\Octopus'
property :config_path, String, default: 'C:\Octopus\OctopusServer.config'
property :connection_string, String
property :master_key, String
property :node_name, String
property :create_database, [true, false], default: false
property :admin_user, String
property :license, String
property :start_service, [true, false], default: true

default_action :install

attribute :instance, kind_of: String, default: 'OctopusServer'
attribute :version, kind_of: String, required: true
attribute :checksum, kind_of: String
attribute :home_path, kind_of: String, default: 'C:\Octopus'
attribute :config_path, kind_of: String, default: 'C:\Octopus\OctopusServer.config'
attribute :connection_string, kind_of: String
attribute :master_key, kind_of: String
attribute :node_name, kind_of: String
attribute :create_database, kind_of: [TrueClass, FalseClass], default: false
attribute :admin_user, kind_of: String
attribute :license, kind_of: String
attribute :start_service, kind_of: [TrueClass, FalseClass], default: true
action :install do
verify_version(version)
verify_checksum(checksum)

server_installer = ::File.join(Chef::Config[:file_cache_path], 'octopus-server.msi')
install_url = installer_url(new_resource.version)

remote_file server_installer do
action :create
source install_url
checksum new_resource.checksum if new_resource.checksum
end

windows_package display_name do
action :install
source server_installer
version new_resource.version
installer_type :msi
options '/passive /norestart'
end
end

action :configure do
action_install

powershell_script "create-instance-#{instance}" do
action :run
cwd server_install_location
code <<-EOH
.\\Octopus.Server.exe create-instance --instance "#{instance}" --config "#{config_path}" --console
#{catch_powershell_error('Creating instance')}
EOH
not_if { ::File.exist?(config_path) }
end

powershell_script "configure-server-#{instance}" do # ~FC009
action :run
cwd server_install_location
sensitive new_resource.sensitive
code <<-EOH
.\\Octopus.Server.exe configure --instance "#{instance}" --home "#{home_path}" --console
#{catch_powershell_error('Configuring Home Dir')}
.\\Octopus.Server.exe configure --instance "#{instance}" --storageConnectionString "#{connection_string}" --console
#{catch_powershell_error('Configuring Database Connection')}
.\\Octopus.Server.exe configure --instance "#{instance}" --upgradeCheck "True" --upgradeCheckWithStatistics "True" --console
#{catch_powershell_error('Configuring Upgrade Checks')}
.\\Octopus.Server.exe configure --instance "#{instance}" --webAuthenticationMode "Domain" --console
#{catch_powershell_error('Configuring authentication')}
.\\Octopus.Server.exe configure --instance "#{instance}" --serverNodeName "#{node_name}" --console
#{catch_powershell_error('Configuring Cluster Node Name')}
.\\Octopus.Server.exe configure --instance "#{instance}" --webForceSSL "False" --webListenPrefixes "http://localhost:80/" --commsListenPort "10943" --console
#{catch_powershell_error('Configuring Listen Ports')}
#{".\\Octopus.Server.exe configure --instance \"#{instance}\" --masterkey \"#{master_key}\" --console; #{catch_powershell_error('Configuring Master Key')}" if master_key}
#{".\\Octopus.Server.exe database --instance \"#{instance}\" --create --console; #{catch_powershell_error('Create Database')}" if create_database}
.\\Octopus.Server.exe service --instance "#{instance}" --stop --console
#{catch_powershell_error('Stop Service')}
#{".\\Octopus.Server.exe admin --instance \"#{instance}\" --username \"#{admin_user}\" --console; #{catch_powershell_error('Set administrator')}" if admin_user}
#{".\\Octopus.Server.exe license --instance \"#{instance}\" --licenseBase64 \"#{Base64.encode64(license)}\" --console; #{catch_powershell_error('Configuring License')}" if license}
.\\Octopus.Server.exe service --instance "#{instance}" --install --reconfigure --console
#{catch_powershell_error('Create Service')}
EOH
not_if { ::Win32::Service.exists?(service_name) }
end

# Make sure enabled and started
windows_service service_name do
if start_service
action [:enable, :start]
else
action [:stop, :disable]
end
end
end

action :remove do
powershell_script "remove-server-instance-#{instance}" do
action :run
cwd server_install_location
code <<-EOH
.\\Octopus.Server.exe service --instance "#{instance}" --stop --uninstall --console
#{catch_powershell_error('Uninstalling Octopus Server service')}
.\\Octopus.Server.exe delete-instance --instance "#{instance}" --console
#{catch_powershell_error('Deleting instance from the node')}
EOH
only_if { ::Win32::Service.exists?(service_name) && ::File.exist?(server_install_location) }
end

file config_path do
action :delete
end
end

action :uninstall do
windows_package display_name do
action :remove
source 'nothing'
end

file ::File.join(Chef::Config[:file_cache_path], 'octopus-server.msi') do
action :delete
end
end

def verify_version(version)
raise 'A version is required in order to install Octopus Deploy Server' unless version
end

def verify_checksum(checksum)
Chef::Log.warn 'You should include a checksum in the octopus_deploy_server resource for security and performance reasons' unless checksum
end
10 changes: 2 additions & 8 deletions test/cookbooks/octopus-deploy-test/recipes/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,13 @@
# limitations under the License.
#

# Just make sure its not installed already
# We remove and then configure everything everytime
octopus_deploy_server 'OctopusServer' do
action :remove
version node['octopus-deploy-test']['server']['version']
end

octopus_deploy_server 'OctopusServer' do
action :configure
action [:uninstall, :install, :remove, :configure]
version node['octopus-deploy-test']['server']['version']
checksum node['octopus-deploy-test']['server']['checksum']
node_name 'octo-web-01'
connection_string node['octopus-deploy-test']['server']['connection-string']
master_key node['octopus-deploy-test']['server']['master-key']
start_service false
sensitive true
end

0 comments on commit 25d74fe

Please sign in to comment.