Skip to content
This repository was archived by the owner on Jan 10, 2023. It is now read-only.

Bitbucket 5 support #186

Merged
merged 9 commits into from
Aug 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ tmp/
*.sublime-project
*.sublime-workspace
*.un~
*.idea

# OS files
.DS_Store
Expand Down
10 changes: 5 additions & 5 deletions .kitchen.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
driver:
name: vagrant
require_chef_omnibus: 11.16.2
require_chef_omnibus: 12.19.36
network:
- ["private_network", {ip: "192.168.50.10"}]

Expand All @@ -20,14 +20,14 @@ platforms:
box: bento/centos-7.1
run_list:
- recipe[yum]
- name: ubuntu-12.04
- name: ubuntu-14.04
driver_config:
box: bento/ubuntu-12.04
box: bento/ubuntu-14.04
run_list:
- recipe[apt]
- name: ubuntu-14.04
- name: ubuntu-1604
driver_config:
box: bento/ubuntu-14.04
box: bento/ubuntu-16.04
run_list:
- recipe[apt]

Expand Down
13 changes: 12 additions & 1 deletion attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set['build-essential']['compile_time'] = true

default['stash']['version'] = '4.14.5'
default['stash']['version'] = '5.1.3'
default['stash']['product'] = Chef::Version.new(node['stash']['version']) >= Chef::Version.new('4.0.0') ? 'bitbucket' : 'stash'

default['stash']['home_path'] = if Dir.exist?('/var/atlassian/application-data/stash')
Expand All @@ -19,6 +19,9 @@

default['stash']['url'] = nil
default['stash']['checksum'] = nil
# sets the IP version which will be used for internal routing. IPv4 will be used if this attribute
# is set to 4, in ANY other cases IPv6 will be used instead
default['stash']['ipversion'] = 4

# Data bag where credentials and other sensitive data could be stored (optional)
default['stash']['data_bag_name'] = 'stash'
Expand Down Expand Up @@ -152,3 +155,11 @@

default['stash']['tomcat']['port'] = '7990'
default['stash']['tomcat']['session-timeout'] = '30'

default['stash']['setup']['admin']['username'] = ''
default['stash']['setup']['admin']['password'] = ''
default['stash']['setup']['admin']['email'] = ''
default['stash']['setup']['admin']['displayname'] = ''

default['stash']['setup']['license'] = ''
default['stash']['setup']['displayname'] = 'Bitbucket'
5 changes: 5 additions & 0 deletions libraries/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,11 @@ def stash_artifact_checksum
when '4.14.3' then '2d54b9424dbfe3a8a65dd8d908cfe670ace7cf2bfb597753c2048e1cf321f259'
when '4.14.4' then 'ba58a5be4064515613cbb3825f2dafd8ceaa9749fd1905a7b5a65f30247be337'
when '4.14.5' then 'f366fc5f4a1b1a41c3daa123d1f18fa166092dc479604694ef3e221b6d4e1f81'
when '5.0.0' then 'a1505e06dc126279c710ce6c289fc41b078bab5de0beff44fc27bd17339ebdf9'
when '5.1.0' then '8bfefd43dae2aaab7193f569e6a15ac3c9bc9aeb8922f4bf299c0984c66f7907'
when '5.1.1' then '198276846c21cbff655f7b2939b2694740454ab36cfd57b89113052e46e0a427'
when '5.1.3' then '9cfdee9935c16d84934e0f61538706e1db92ecab82f951e6036d30f4da29ea39'
when '5.2.0' then '5038465b5a0be6cbca2d8706b4320be28bbb23bfd9486a8a1518caae1772133e'
else raise "Stash version #{node['stash']['version']} is not supported by this cookbook"
end
end
Expand Down
8 changes: 8 additions & 0 deletions recipes/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@
config_path = '/stash-config.properties'
end

if stash_version >= Chef::Version.new('5.0.0')
template "#{node['stash']['install_path']}/bitbucket/bin/set-jre-home.sh" do
source 'bitbucket5/set-jre-home.sh.erb'
owner node['stash']['user']
mode '0755'
end
end

template "#{node['stash']['home_path']}/#{config_path}" do
source 'stash-config.properties.erb'
owner node['stash']['user']
Expand Down
8 changes: 8 additions & 0 deletions recipes/linux_standalone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@
recursive true
end

# needed only for upgrading from 4.x.x to 5.x.x
# if removed, the old bitbucket instance won't be terminated via service[#{node['stash]['product']}]
if Chef::Version.new(node['stash']['version']) >= Chef::Version.new('5.0.0') && Dir.glob("#{node['stash']['install_path']}/#{node['stash']['product']}-5.*").empty?
service node['stash']['product'] do
action :stop
end
end

ark node['stash']['product'] do
url stash_artifact_url
prefix_root node['stash']['install_path']
Expand Down
20 changes: 13 additions & 7 deletions recipes/service_init.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
# frozen_string_literal: true

template "/etc/init.d/#{node['stash']['product']}" do
if node['stash']['product'] == 'stash'
source 'stash.init.erb'
else
source 'bitbucket/bitbucket.init.erb'
if (node['platform'] == 'ubuntu' && node['platform_version'].to_f >= 15.04) || (node['platform'] == 'centos' && node['platform_version'].to_f >= 7.0)
template "/etc/systemd/system/#{node['stash']['product']}.service" do
source 'bitbucket/bitbucket.service.systemd.erb'
end
else
template "/etc/init.d/#{node['stash']['product']}" do
if node['stash']['product'] == 'stash'
source 'stash.init.erb'
else
source 'bitbucket/bitbucket.init.erb'
end
mode '0755'
notifies :restart, "service[#{node['stash']['product']}]", :delayed
end
mode '0755'
notifies :restart, "service[#{node['stash']['product']}]", :delayed
end

# disable stash service after upgrade to bitbucket 4.0
Expand Down
86 changes: 48 additions & 38 deletions recipes/tomcat_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,49 +7,59 @@
server_xml_path = "#{node['stash']['home_path']}/shared/server.xml"
end

template "#{node['stash']['install_path']}/#{node['stash']['product']}/bin/setenv.sh" do
if stash_version < Chef::Version.new('3.8.0')
source 'setenv.sh.erb'
elsif node['stash']['product'] == 'stash'
source '3.8+/setenv.sh.erb'
else
source 'bitbucket/setenv.sh.erb'
if stash_version < Chef::Version.new('5.0.0')

template "#{node['stash']['install_path']}/#{node['stash']['product']}/bin/setenv.sh" do
if stash_version < Chef::Version.new('3.8.0')
source 'setenv.sh.erb'
elsif node['stash']['product'] == 'stash'
source '3.8+/setenv.sh.erb'
else
source 'bitbucket/setenv.sh.erb'
end
owner node['stash']['user']
mode '0755'
notifies :restart, "service[#{node['stash']['product']}]", :delayed
end
owner node['stash']['user']
mode '0755'
notifies :restart, "service[#{node['stash']['product']}]", :delayed
end

template server_xml_path do
if stash_version.major == 1
source 'server.xml.erb'
elsif stash_version < Chef::Version.new('3.3.0')
source 'server-tomcat7.xml.erb'
elsif stash_version < Chef::Version.new('3.8.0')
source 'server-tomcat8.xml.erb'
elsif node['stash']['product'] == 'stash'
source '3.8+/server.xml.erb'
else
source 'bitbucket/server.xml.erb'
template server_xml_path do
if stash_version.major == 1
source 'server.xml.erb'
elsif stash_version < Chef::Version.new('3.3.0')
source 'server-tomcat7.xml.erb'
elsif stash_version < Chef::Version.new('3.8.0')
source 'server-tomcat8.xml.erb'
elsif node['stash']['product'] == 'stash'
source '3.8+/server.xml.erb'
else
source 'bitbucket/server.xml.erb'
end
owner node['stash']['user']
mode '0640'
notifies :restart, "service[#{node['stash']['product']}]", :delayed
end
owner node['stash']['user']
mode '0640'
notifies :restart, "service[#{node['stash']['product']}]", :delayed
end

template "#{node['stash']['install_path']}/#{node['stash']['product']}/conf/web.xml" do
if stash_version.major == 1
source 'web.xml.erb'
elsif stash_version < Chef::Version.new('3.8.0')
source 'web-tomcat7.xml.erb'
elsif node['stash']['product'] == 'stash'
source '3.8+/web.xml'
else
source 'bitbucket/web.xml'
template "#{node['stash']['install_path']}/#{node['stash']['product']}/conf/web.xml" do
if stash_version.major == 1
source 'web.xml.erb'
elsif stash_version < Chef::Version.new('3.8.0')
source 'web-tomcat7.xml.erb'
elsif node['stash']['product'] == 'stash'
source '3.8+/web.xml'
else
source 'bitbucket/web.xml'
end
owner node['stash']['user']
mode '0644'
notifies :restart, "service[#{node['stash']['product']}]", :delayed
end
else
template "#{node['stash']['install_path']}/bitbucket/bin/_start-webapp.sh" do
source 'bitbucket5/_start-webapp.sh.erb'
owner node['stash']['user']
mode '0755'
notifies :restart, "service[#{node['stash']['product']}]", :delayed
end
owner node['stash']['user']
mode '0644'
notifies :restart, "service[#{node['stash']['product']}]", :delayed
end

directory "/var/run/#{node['stash']['product']}" do
Expand Down
25 changes: 22 additions & 3 deletions spec/default_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
end

it 'renders server.xml' do
chef_run.node.set['stash']['version'] = '4.14.5'
chef_run.converge(described_recipe)
path = '/var/atlassian/application-data/bitbucket/shared/server.xml'
resource = chef_run.template(path)

Expand All @@ -28,6 +30,8 @@
end

it 'renders web.xml' do
chef_run.node.set['stash']['version'] = '4.14.5'
chef_run.converge(described_recipe)
path = '/opt/atlassian/bitbucket/conf/web.xml'
resource = chef_run.template(path)

Expand All @@ -36,9 +40,24 @@
end

it 'renders setenv.sh' do
chef_run.node.set['stash']['version'] = '4.14.5'
chef_run.converge(described_recipe)
expect(chef_run).to render_file('/opt/atlassian/bitbucket/bin/setenv.sh')
.with_content { |content|
expect(content).to include('export BITBUCKET_HOME="/var/atlassian/application-data/bitbucket"')
}
.with_content { |content|
expect(content).to include('export BITBUCKET_HOME="/var/atlassian/application-data/bitbucket"')
}
end

it 'renders start-webapp' do
chef_run.node.set['stash']['version'] = '5.0.0'
chef_run.converge(described_recipe)
expect(chef_run).to render_file('/opt/atlassian/bitbucket/bin/_start-webapp.sh')
end

it 'renders set-jre-home' do
chef_run.node.set['stash']['version'] = '5.0.0'
chef_run.converge(described_recipe)
expect(chef_run).to render_file('/opt/atlassian/bitbucket/bin/set-jre-home.sh')
end

end
12 changes: 12 additions & 0 deletions templates/default/bitbucket/bitbucket.service.systemd.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[Unit]
Description=Atlassian Bitbucket Server Service
After=syslog.target network.target postgresql.service

[Service]
Type=forking
User=<%= node['stash']['user'] %>
ExecStart=<%= node['stash']['install_path'] %>/bitbucket/bin/start-bitbucket.sh
ExecStop=<%= node['stash']['install_path'] %>/bitbucket/bin/stop-bitbucket.sh

[Install]
WantedBy=multi-user.target
Loading