summaryrefslogtreecommitdiff
path: root/lib/tasks
diff options
context:
space:
mode:
Diffstat (limited to 'lib/tasks')
-rw-r--r--lib/tasks/ci/.gitkeep0
-rw-r--r--lib/tasks/ci/cleanup.rake8
-rw-r--r--lib/tasks/ci/migrate.rake63
-rw-r--r--lib/tasks/ci/schedule_builds.rake6
-rw-r--r--lib/tasks/gitlab/backup.rake21
5 files changed, 98 insertions, 0 deletions
diff --git a/lib/tasks/ci/.gitkeep b/lib/tasks/ci/.gitkeep
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/lib/tasks/ci/.gitkeep
diff --git a/lib/tasks/ci/cleanup.rake b/lib/tasks/ci/cleanup.rake
new file mode 100644
index 00000000000..2f4d11bd942
--- /dev/null
+++ b/lib/tasks/ci/cleanup.rake
@@ -0,0 +1,8 @@
+namespace :ci do
+ namespace :cleanup do
+ desc "GitLab CI | Clean running builds"
+ task builds: :environment do
+ Ci::Build.running.update_all(status: 'canceled')
+ end
+ end
+end
diff --git a/lib/tasks/ci/migrate.rake b/lib/tasks/ci/migrate.rake
new file mode 100644
index 00000000000..e7d41874a11
--- /dev/null
+++ b/lib/tasks/ci/migrate.rake
@@ -0,0 +1,63 @@
+namespace :ci do
+ desc 'GitLab | Import and migrate CI database'
+ task migrate: :environment do
+ unless ENV['force'] == 'yes'
+ puts "This will truncate all CI tables and restore it from provided backup."
+ puts "You will lose any previous CI data stored in the database."
+ ask_to_continue
+ puts ""
+ end
+
+ Rake::Task["ci:migrate:db"].invoke
+ Rake::Task["ci:migrate:autoincrements"].invoke
+ Rake::Task["ci:migrate:tags"].invoke
+ Rake::Task["ci:migrate:services"].invoke
+ end
+
+ namespace :migrate do
+ desc 'GitLab | Import CI database'
+ task db: :environment do
+ if ENV["CI_DUMP"].nil?
+ puts "No CI SQL dump specified:"
+ puts "rake gitlab:backup:restore CI_DUMP=ci_dump.sql"
+ exit 1
+ end
+
+ ci_dump = ENV["CI_DUMP"]
+ unless File.exists?(ci_dump)
+ puts "The specified sql dump doesn't exist!"
+ exit 1
+ end
+
+ ::Ci::Migrate::Database.new.restore(ci_dump)
+ end
+
+ desc 'GitLab | Migrate CI tags'
+ task tags: :environment do
+ ::Ci::Migrate::Tags.new.restore
+ end
+
+ desc 'GitLab | Migrate CI auto-increments'
+ task autoincrements: :environment do
+ c = ActiveRecord::Base.connection
+ c.tables.select { |t| t.start_with?('ci_') }.each do |table|
+ result = c.select_one("SELECT id FROM #{table} ORDER BY id DESC LIMIT 1")
+ if result
+ ai_val = result['id'].to_i + 1
+ puts "Resetting auto increment ID for #{table} to #{ai_val}"
+ if c.adapter_name == 'PostgreSQL'
+ c.execute("ALTER SEQUENCE #{table}_id_seq RESTART WITH #{ai_val}")
+ else
+ c.execute("ALTER TABLE #{table} AUTO_INCREMENT = #{ai_val}")
+ end
+ end
+ end
+ end
+
+ desc 'GitLab | Migrate CI services'
+ task services: :environment do
+ c = ActiveRecord::Base.connection
+ c.execute("UPDATE ci_services SET type=CONCAT('Ci::', type) WHERE type NOT LIKE 'Ci::%'")
+ end
+ end
+end
diff --git a/lib/tasks/ci/schedule_builds.rake b/lib/tasks/ci/schedule_builds.rake
new file mode 100644
index 00000000000..49435504c67
--- /dev/null
+++ b/lib/tasks/ci/schedule_builds.rake
@@ -0,0 +1,6 @@
+namespace :ci do
+ desc "GitLab CI | Clean running builds"
+ task schedule_builds: :environment do
+ Ci::Scheduler.new.perform
+ end
+end
diff --git a/lib/tasks/gitlab/backup.rake b/lib/tasks/gitlab/backup.rake
index 4c73f90bbf2..f20c7f71ba5 100644
--- a/lib/tasks/gitlab/backup.rake
+++ b/lib/tasks/gitlab/backup.rake
@@ -11,6 +11,7 @@ namespace :gitlab do
Rake::Task["gitlab:backup:db:create"].invoke
Rake::Task["gitlab:backup:repo:create"].invoke
Rake::Task["gitlab:backup:uploads:create"].invoke
+ Rake::Task["gitlab:backup:builds:create"].invoke
backup = Backup::Manager.new
backup.pack
@@ -30,6 +31,7 @@ namespace :gitlab do
Rake::Task["gitlab:backup:db:restore"].invoke unless backup.skipped?("db")
Rake::Task["gitlab:backup:repo:restore"].invoke unless backup.skipped?("repositories")
Rake::Task["gitlab:backup:uploads:restore"].invoke unless backup.skipped?("uploads")
+ Rake::Task["gitlab:backup:builds:restore"].invoke unless backup.skipped?("builds")
Rake::Task["gitlab:shell:setup"].invoke
backup.cleanup
@@ -73,6 +75,25 @@ namespace :gitlab do
end
end
+ namespace :builds do
+ task create: :environment do
+ $progress.puts "Dumping builds ... ".blue
+
+ if ENV["SKIP"] && ENV["SKIP"].include?("builds")
+ $progress.puts "[SKIPPED]".cyan
+ else
+ Backup::Builds.new.dump
+ $progress.puts "done".green
+ end
+ end
+
+ task restore: :environment do
+ $progress.puts "Restoring builds ... ".blue
+ Backup::Builds.new.restore
+ $progress.puts "done".green
+ end
+ end
+
namespace :uploads do
task create: :environment do
$progress.puts "Dumping uploads ... ".blue