diff options
author | Z.J. van de Weg <git@zjvandeweg.nl> | 2017-08-01 12:38:10 +0200 |
---|---|---|
committer | Z.J. van de Weg <git@zjvandeweg.nl> | 2017-08-01 13:00:51 +0200 |
commit | 09974de3e3d6409e24786c116fc084c6d834fed8 (patch) | |
tree | 6078d00a08229946182fe9ad415dea36c4df0997 /lib/tasks | |
parent | 74b58131d49ac1379cc8071b1df3867bdbf54eae (diff) | |
download | gitlab-ce-09974de3e3d6409e24786c116fc084c6d834fed8.tar.gz |
Create rake task to create project templates
First iteration, and some stuff is missing. But basically this rake task
does a clone of a project we've pointed it to. Than creates a project on
the GDK, which should be running in the background. This project is
exported, after which we move that archive to the location we need it.
We clean up by removing the generated project.
The first idea was to export the project on .com too, however than we
might run into ImportExport versions mismatch. This could've been
circumvented by checkout out an older commit locally. This however is
not needed yet, so we opted to not go this route yet, instead we will
iterate on what we got.
Diffstat (limited to 'lib/tasks')
-rw-r--r-- | lib/tasks/gitlab/update_templates.rake | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/lib/tasks/gitlab/update_templates.rake b/lib/tasks/gitlab/update_templates.rake index 59c32bbe7a4..26f6276e84b 100644 --- a/lib/tasks/gitlab/update_templates.rake +++ b/lib/tasks/gitlab/update_templates.rake @@ -4,6 +4,53 @@ namespace :gitlab do TEMPLATE_DATA.each { |template| update(template) } end + desc "GitLab | Update project templates" + task :update_project_templates do + if Rails.env.production? + puts "This rake task is not meant fo production instances".red + exit(1) + end + admin = User.find_by(admin: true) + + unless admin + puts "No admin user could be found".red + exit(1) + end + + Gitlab::ProjectTemplate.all.each do |template| + params = { + import_url: template.clone_url, + namespace_id: admin.namespace.id, + path: template.title, + skip_wiki: true + } + puts "Creating project for #{template.name}" + project = Projects::CreateService.new(admin, project).execute + + loop do + if project.import_status == "finished" + puts "Import finished for #{template.name}" + break + end + + if project.import_status == "failed" + puts "Failed to import from #{project_params[:import_url]}".red + exit(1) + end + + puts "Waiting for the import to finish" + sleep(5) + project = project.reload + end + + Projects::ImportExport::ExportService.new(project, admin).execute + FileUtils.cp(project.export_project_path, template.archive_path) + Projects::DestroyService.new(admin, project).execute + puts "Exported #{template.name}".green + end + puts "Done".green + end + def update(template) sub_dir = template.repo_url.match(/([A-Za-z-]+)\.git\z/)[1] dir = File.join(vendor_directory, sub_dir) |