[ci skip] Remove reposman functionality.

This commit removes the functionality provided by reposman.rb,
and replaces that script with an empty placeholder printing only
a deprecation warning (as to not throw errors in existing cronjobs).

In detail, this commit does:

* replace reposman.rb with an script printing a deprecation only.
* Remove repositories creation API in SysController and corresponding
specs
* Update documentation guides concerning the deprecation of reposman
* Remove packager scripts for creating a reposman.rb cronjob.
* Adds a rake task to migrate repositories to managed type with a common
* URL prefix.
pull/3380/head
Oliver Günther 10 years ago
parent 3f8d17fbf6
commit c5a33fc4fa
  1. 1
      .pkgr.yml
  2. 17
      app/controllers/sys_controller.rb
  3. 1
      config/routes.rb
  4. 43
      doc/subversion_and_git_integration.md
  5. 281
      extra/svn/reposman.rb
  6. 28
      lib/tasks/scm.rake
  7. 2
      packaging/cron/openproject-create-svn-repositories
  8. 24
      packaging/scripts/create-svn-repositories
  9. 14
      spec_legacy/functional/sys_controller_spec.rb

@ -24,7 +24,6 @@ targets:
before_precompile: "packaging/setup"
crons:
- packaging/cron/openproject-clear-old-sessions
- packaging/cron/openproject-create-svn-repositories
services:
- postgres
installer: https://github.com/pkgr/installer.git

@ -50,23 +50,6 @@ class SysController < ActionController::Base
end
end
def create_project_repository
project = Project.find(params[:id])
if project.repository
render nothing: true, status: 409
else
logger.info "Repository for #{project.name} was reported to be created by #{request.remote_ip}."
service = Scm::RepositoryFactoryService.new(project, params)
if service.build_and_save
project.repository = service.repository
render xml: project.repository, status: 201
else
render nothing: true, status: 422
end
end
end
def update_required_storage
result = update_storage_information(@repository, params[:force] == '1')
render text: "Updated: #{result}", status: 200

@ -525,7 +525,6 @@ OpenProject::Application.routes.draw do
match '/sys/repo_auth', action: 'repo_auth', via: [:get, :post]
match '/sys/projects.:format', action: 'projects', via: :get
match '/sys/projects/:id/repository/update_storage', action: 'update_required_storage', via: :get
match '/sys/projects/:id/repository.:format', action: 'create_project_repository', via: :post
end
# alternate routes for the current user

@ -114,25 +114,34 @@ We provide an example apache configuration. Some details are explained inline as
ProxyPassReverse / http://127.0.0.1:3000/
</VirtualHost>
## Automatically create repositories with reposman.rb
## Automatically create repositories
The reposman.rb script can create repositories for your newly created OpenProject projects.
It is useful when run from a cron job (so that repositories appear 'magically' some time after you created
a project in the OpenProject administration view).
You can create repositories explicitly on the filesystem using managed repositories.
Enable managed repositories for each SCM vendor individually using the templates
defined in configuration.yml.
<pre>
ruby extra/svn/reposman.rb \
--openproject-host "http://127.0.0.1:3000" \
--owner "www-data" \
--group "openproject" \
--public-mode '2750' \
--private-mode '2750' \
--svn-dir "/srv/openproject/svn" \
--url "file:///srv/openproject/svn" \
--key "REPLACE WITH REPOSITORY API KEY" \
--scm Subversion \
--verbose
</pre>
### reposman.rb
This functionality was previously provided in an asynchronous manner using reposman.rb.
This script has been integrated into OpenProject.
Please remove any existing cronjobs that still use this script.
If you want to convert existing repositories previously created (by reposman.rb or manually)
into managed repositories, use the following command:
$ bundle exec rake scm:migrate:managed[URL prefix (, URL prefix, ...)]
Where URL prefix denotes a common prefix of repositories whose status should be upgraded to `:managed`.
Example:
If you have executed reposman.rb with the following parameters:
$ reposman.rb [...] --svn-dir "/opt/svn" --url "file:///opt/svn"
Then you can pass the task a URL prefix `file:///opt/svn` and the rake task will migrate all repositories
matching this prefix to `:managed`.
You may pass more than one URL prefix to the task.
the downside (if you want to call it a downside) is that you have to choose which kind (svn or git) of repository you want to create.

@ -28,273 +28,26 @@
# See doc/COPYRIGHT.rdoc for more details.
#++
require 'optparse'
require 'find'
require 'etc'
require 'json'
require 'net/http'
require 'uri'
warn <<-EOS
[DEPRECATION] The functionality provided by reposman.rb has been integrated into OpenProject.
Please remove any existing cronjobs that still use this script.
Version = "1.4"
SUPPORTED_SCM = %w( Subversion Git )
You can create repositories explicitly on the filesystem using managed repositories.
Enable managed repositories for each SCM vendor individually using the templates
defined in configuration.yml.
$verbose = 0
$quiet = false
$openproject_host = ''
$repos_base = ''
$svn_owner = 'root'
$svn_group = 'root'
$public_mode = '0775'
$private_mode = '0770'
$use_groupid = true
$svn_url = false
$test = false
$force = false
$scm = 'Subversion'
If you want to convert existing repositories previously created (by reposman.rb or manually)
into managed repositories, use the following command:
def log(text, options={})
level = options[:level] || 0
puts text unless $quiet or level > $verbose
exit 1 if options[:exit]
end
$ bundle exec rake scm:migrate:managed[URL prefix (, URL prefix, ...)]
Where URL prefix denotes a common prefix of repositories whose status should be upgraded to :managed.
Example:
def system_or_raise(command)
raise "\"#{command}\" failed" unless system command
end
If you have executed reposman.rb with the following parameters:
module SCM
$ reposman.rb [...] --svn-dir "/opt/svn" --url "file:///opt/svn"
module Subversion
def self.create(path)
system_or_raise "svnadmin create #{path}"
end
end
module Git
def self.create(path)
Dir.mkdir path
Dir.chdir(path) do
system_or_raise "git --bare init --shared"
system_or_raise "git update-server-info"
end
end
end
end
OptionParser.new do |opts|
opts.banner = "Usage: reposman.rb [OPTIONS...] -s [DIR] -r [HOST]"
opts.separator("")
opts.separator("Manages your repositories with OpenProject.")
opts.separator("")
opts.separator("Required arguments:")
opts.on("-s", "--svn-dir DIR", "use DIR as base directory for svn repositories") {|v| $repos_base = v}
opts.on("-r", "--openproject-host HOST", "assume OpenProject is hosted on HOST. Examples:",
" -r openproject.example.net",
" -r http://openproject.example.net",
" -r https://openproject.example.net") {|v| $openproject_host = v}
opts.on('', "--redmine-host HOST", "DEPRECATED: please use --openproject-host instead") {|v| $openproject_host = v}
opts.on("-k", "--key KEY", "use KEY as the OpenProject API key") {|v| $api_key = v}
opts.separator("")
opts.separator("Options:")
opts.on("-o", "--owner OWNER", "owner of the repository. using the rails login",
"allows users to browse the repository within",
"OpenProject even for private projects. If you want to",
"share repositories through OpenProject.pm, you need",
"to use the apache owner.") {|v| $svn_owner = v; $use_groupid = false}
opts.on("-g", "--group GROUP", "group of the repository (default: root)") {|v| $svn_group = v; $use_groupid = false}
opts.on( "--public-mode MODE", "file mode for new public repositories (default: 0775)") {|v| $public_mode = v}
opts.on( "--private-mode MODE", "file mode for new private repositories (default: 0770)") {|v| $private_mode = v}
opts.on( "--scm SCM", "the kind of SCM repository you want to create",
"(and register) in OpenProject (default: Subversion).",
"reposman is able to create Git and Subversion",
"repositories.",
"For all other kind, you must specify a --command",
"option") {|v| v.capitalize; log("Invalid SCM: #{v}", :exit => true) unless SUPPORTED_SCM.include?(v)}
opts.on("-u", "--url URL", "the base url OpenProject will use to access your",
"repositories. This option is used to automatically",
"register the repositories in OpenProject. The project ",
"identifier will be appended to this url.",
"Examples:",
" -u https://example.net/svn",
" -u file:///var/svn/",
"if this option isn't set, reposman won't register",
"the repositories in OpenProject") {|v| $svn_url = v}
opts.on("-c", "--command COMMAND", "use this command instead of 'svnadmin create' to",
"create a repository. This option can be used to",
"create repositories other than subversion and git",
"kind.",
"This command override the default creation for git",
"and subversion.") {|v| $command = v}
opts.on("-f", "--force", "force repository creation even if the project",
"repository is already declared in OpenProject") {$force = true}
opts.on("-t", "--test", "only show what should be done") {$test = true}
opts.on("-h", "--help", "show help and exit") {puts opts; exit 1}
opts.on("-v", "--verbose", "verbose") {$verbose += 1}
opts.on("-V", "--version", "print version and exit") {puts Version; exit}
opts.on("-q", "--quiet", "no log") {$quiet = true}
opts.separator("")
opts.separator("Examples:")
opts.separator(" reposman.rb --svn-dir=/var/svn --openproject-host=openproject.example.net --scm Subversion")
opts.separator(" reposman.rb -s /var/git -r openproject.example.net -u http://svn.example.net --scm Git")
opts.separator("")
opts.separator("You might find more information on the OpenProject's help site:\nhttps://www.openproject.org/help")
end.parse!
if $test
log("running in test mode")
end
# Make sure command is overridden if SCM vendor is not handled internally (for the moment Subversion and Git)
if $command.nil?
begin
scm_module = SCM.const_get($scm)
rescue
log("Please use --command option to specify how to create a #{$scm} repository.", :exit => true)
end
end
$svn_url += "/" if $svn_url and not $svn_url.match(/\/$/)
if ($openproject_host.empty? or $repos_base.empty?)
puts "Required argument missing. Type 'reposman.rb --help' for usage."
exit 1
end
unless File.directory?($repos_base)
log("directory '#{$repos_base}' doesn't exists", :exit => true)
end
log("querying OpenProject for projects...", :level => 1);
$openproject_host.gsub!(/^/, "http://") unless $openproject_host.match("^https?://")
$openproject_host.gsub!(/\/$/, '')
api_uri = URI.parse("#{$openproject_host}/sys")
http = Net::HTTP.new(api_uri.host, api_uri.port)
http.use_ssl = (api_uri.scheme == 'https')
http_headers = {'User-Agent' => "OpenProject-Repository-Manager/#{Version}"}
begin
# Get all active projects that have the Repository module enabled
response = http.get("#{api_uri.path}/projects.json?key=#{$api_key}", http_headers)
projects = JSON.parse(response.body)
rescue => e
log("Unable to connect to #{$openproject_host}: #{e}", :exit => true)
end
if projects.nil?
log('no project found, perhaps you forgot to "Enable WS for repository management"', :exit => true)
end
log("retrieved #{projects.size} projects", :level => 1)
def set_owner_and_rights(project, repos_path, &block)
if mswin?
yield if block_given?
else
uid, gid = Etc.getpwnam($svn_owner).uid, ($use_groupid ? Etc.getgrnam(project['identifier']).gid : Etc.getgrnam($svn_group).gid)
right = project['is_public'] ? $public_mode : $private_mode
right = right.to_i(8) & 007777
yield if block_given?
Find.find(repos_path) do |f|
File.chmod right, f
File.chown uid, gid, f
end
end
end
def other_read_right?(file)
!(File.stat(file).mode & 0007).zero?
end
def owner_name(file)
mswin? ?
$svn_owner :
Etc.getpwuid( File.stat(file).uid ).name
end
def mswin?
(RUBY_PLATFORM =~ /(:?mswin|mingw)/) || (RUBY_PLATFORM == 'java' && (ENV['OS'] || ENV['os']) =~ /windows/i)
end
projects.each do |project|
log("treating project #{project['name']}", :level => 1)
if project['identifier'].empty?
log("\tno identifier for project #{project['name']}")
next
elsif not project['identifier'].match(/^[a-z0-9\-_]+$/)
log("\tinvalid identifier for project #{project['name']} : #{project['identifier']}");
next;
end
repos_path = File.join($repos_base, project['identifier']).gsub(File::SEPARATOR, File::ALT_SEPARATOR || File::SEPARATOR)
if File.directory?(repos_path)
# we must verify that repository has the good owner and the good
# rights before leaving
other_read = other_read_right?(repos_path)
owner = owner_name(repos_path)
next if project['is_public'] == other_read and owner == $svn_owner
if $test
log("\tchange mode on #{repos_path}")
next
end
begin
set_owner_and_rights(project, repos_path)
rescue Errno::EPERM => e
log("\tunable to change mode on #{repos_path} : #{e}\n")
next
end
log("\tmode change on #{repos_path}");
else
# if repository is already declared in openproject, we don't create
# unless user use -f with reposman
if $force == false and project.has_key?('repository')
log("\trepository for project #{project['identifier']} already exists in OpenProject", :level => 1)
next
end
project['is_public'] ? File.umask(0002) : File.umask(0007)
if $test
log("\tcreate repository #{repos_path}")
log("\trepository #{repos_path} registered in OpenProject with url #{$svn_url}#{project['identifier']}") if $svn_url;
next
end
begin
set_owner_and_rights(project, repos_path) do
if scm_module.nil?
system_or_raise "#{$command} #{repos_path}"
else
scm_module.create(repos_path)
end
end
rescue => e
log("\tunable to create #{repos_path} : #{e}\n")
next
end
if $svn_url
begin
http.post("#{api_uri.path}/projects/#{project['identifier']}/repository.json?" +
"vendor=#{$scm}&repository[url]=#{$svn_url}#{project['identifier']}&key=#{$api_key}",
"", # empty data
http_headers)
log("\trepository #{repos_path} registered in OpenProject with url #{$svn_url}#{project['identifier']}");
rescue => e
log("\trepository #{repos_path} not registered in OpenProject: #{e.message}");
end
end
log("\trepository #{repos_path} created");
end
end
Then you can pass a URL prefix of 'file:///opt/svn' and the rake task will migrate all repositories
matching this prefix to :managed.
You may pass more than one URL prefix to the task.
EOS

@ -55,25 +55,24 @@ namespace :scm do
vendor = vendor.to_s.classify
managed = config['manages']
puts "-- #{vendor} --"
if managed.nil?
puts 'This vendor does not use managed repositories. Skipping.'
puts 'SCM vendor #{vendor} does not use managed repositories. Skipping.'
next
end
unless Dir.exists?(managed)
$stderr.puts "WARNING: Managed repository path '#{managed}' does not exist!"
$stderr.puts "WARNING: Managed repository path set to '#{managed}'," \
" but does not exist for SCM vendor #{vendor}!"
next
end
missing = scan_repositories(managed)
if missing.empty?
puts 'Found no unassociated repositories. ✓'
else
unless missing.empty?
puts <<-WARNING
-- SCM vendor #{vendor} --
Found #{missing.length} repositories in #{managed}
without an associated project.
@ -84,7 +83,7 @@ repositories whose associated project identifier is contained in the list above.
To resolve these cases, you can either:
1. Remove the affected repositories if they are only remains of earlier projects
1. Remove the affected repositories if they are only remnants of earlier projects
2. Move them out of the OpenProject managed directory '#{managed}'
@ -95,4 +94,17 @@ To resolve these cases, you can either:
end
end
end
namespace :migrate do
desc 'Migrate existing repositories to managed for a given URL prefix'
task managed: :environment do |task, args|
urls = args.extras
abort "Requires at least one URL prefix to identify existing repositories" if urls.length < 1
urls.each do |url|
Repository.where('url LIKE ?', "#{url}%").update_all(scm_type: :managed)
end
end
end
end

@ -1,2 +0,0 @@
APP_NAME="_APP_NAME_"
*/10 * * * * root /opt/${APP_NAME}/packaging/scripts/create-svn-repositories >> /var/log/${APP_NAME}/cron-create-svn-repositories.log 2>&1

@ -1,24 +0,0 @@
#!/bin/bash
APP_NAME="_APP_NAME_"
CLI="${APP_NAME}"
APP_HOME="$(${CLI} config:get APP_HOME)"
SVN_REPOSITORIES="$(${CLI} config:get SVN_REPOSITORIES)"
PORT=$(${CLI} config:get PORT)
SYS_API_KEY="$(${CLI} config:get SYS_API_KEY)"
APP_GROUP="$(${CLI} config:get APP_GROUP)"
SERVER_USER="$(${CLI} config:get SERVER_USER)"
SERVER_HOSTNAME="$(${CLI} config:get SERVER_HOSTNAME)"
SERVER_PROTOCOL="$(${CLI} config:get SERVER_PROTOCOL)"
${APP_HOME}/bin/ruby ${APP_HOME}/extra/svn/reposman.rb \
--openproject-host "http://127.0.0.1:${PORT}" \
--owner "${SERVER_USER}" \
--group "${APP_GROUP}" \
--public-mode '2750' \
--private-mode '2750' \
--svn-dir "${SVN_REPOSITORIES}" \
--url "file://${SVN_REPOSITORIES}" \
--key "${SYS_API_KEY}" \
--scm Subversion \
--verbose

@ -45,20 +45,6 @@ describe SysController, type: :controller do
assert_select 'projects', children: { count: Project.active.has_module(:repository).count }
end
it 'should create project repository' do
assert_nil Project.find(4).repository
post :create_project_repository, id: 4,
scm_vendor: 'subversion',
scm_type: 'existing',
repository: { url: 'file:///create/project/repository/subproject2' }
assert_response :created
r = Project.find(4).repository
assert r.is_a?(Repository::Subversion)
assert_equal 'file:///create/project/repository/subproject2', r.url
end
it 'should fetch changesets' do
expect_any_instance_of(Repository::Subversion).to receive(:fetch_changesets).and_return(true)
get :fetch_changesets

Loading…
Cancel
Save