diff options
author | Douwe Maan <douwe@gitlab.com> | 2015-08-26 04:42:46 +0300 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2015-08-26 04:42:46 +0300 |
commit | 046b28312704f3131e72dcd2dbdacc5264d4aa62 (patch) | |
tree | a8c2b14a6e1db3b662fee2c79af70d9fcb643c2e /lib/tasks/ci | |
parent | e449426a4e7d15cdd582d4f136add52cbfb5e04e (diff) |
Groundwork for merging CI into CE
Diffstat (limited to 'lib/tasks/ci')
-rw-r--r-- | lib/tasks/ci/.gitkeep | 0 | ||||
-rw-r--r-- | lib/tasks/ci/backup.rake | 62 | ||||
-rw-r--r-- | lib/tasks/ci/cleanup.rake | 8 | ||||
-rw-r--r-- | lib/tasks/ci/schedule_builds.rake | 6 | ||||
-rw-r--r-- | lib/tasks/ci/setup.rake | 7 | ||||
-rw-r--r-- | lib/tasks/ci/sidekiq.rake | 13 |
6 files changed, 96 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/backup.rake b/lib/tasks/ci/backup.rake new file mode 100644 index 00000000000..1cb2e43f875 --- /dev/null +++ b/lib/tasks/ci/backup.rake @@ -0,0 +1,62 @@ +namespace :ci do + namespace :backup do + + desc "GITLAB | Create a backup of the GitLab CI database" + task create: :environment do + configure_cron_mode + + $progress.puts "Dumping database ... ".blue + Ci::Backup::Database.new.dump + $progress.puts "done".green + + $progress.puts "Dumping builds ... ".blue + Ci::Backup::Builds.new.dump + $progress.puts "done".green + + backup = Ci::Backup::Manager.new + backup.pack + backup.cleanup + backup.remove_old + end + + desc "GITLAB | Restore a previously created backup" + task restore: :environment do + configure_cron_mode + + backup = Ci::Backup::Manager.new + backup.unpack + + $progress.puts "Restoring database ... ".blue + Ci::Backup::Database.new.restore + $progress.puts "done".green + + $progress.puts "Restoring builds ... ".blue + Ci::Backup::Builds.new.restore + $progress.puts "done".green + + backup.cleanup + end + + def configure_cron_mode + if ENV['CRON'] + # We need an object we can say 'puts' and 'print' to; let's use a + # StringIO. + require 'stringio' + $progress = StringIO.new + else + $progress = $stdout + end + end + end + + # Disable colors for CRON + unless STDOUT.isatty + module Colored + extend self + + def colorize(string, options={}) + string + end + end + end +end 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/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/ci/setup.rake b/lib/tasks/ci/setup.rake new file mode 100644 index 00000000000..ab83581ec1b --- /dev/null +++ b/lib/tasks/ci/setup.rake @@ -0,0 +1,7 @@ +namespace :ci do + desc "GitLab CI | Setup gitlab db" + task :setup do + Rake::Task["db:setup"].invoke + Rake::Task["ci:add_limits_mysql"].invoke + end +end diff --git a/lib/tasks/ci/sidekiq.rake b/lib/tasks/ci/sidekiq.rake new file mode 100644 index 00000000000..12fd3635933 --- /dev/null +++ b/lib/tasks/ci/sidekiq.rake @@ -0,0 +1,13 @@ +namespace :ci do + namespace :sidekiq do + desc "GitLab CI | Stop sidekiq" + task :stop do + exec({'RAILS_ENV' => Rails.env}, 'script/background_jobs stop') + end + + desc "GitLab CI | Start sidekiq" + task :start do + exec({'RAILS_ENV' => Rails.env}, 'script/background_jobs start') + end + end +end |