Commit f64fb6dd authored by Douwe Maan's avatar Douwe Maan Committed by Yorick Peterse

Merge branch 'fix-registry-backups' into 'master'

Fix backups if registry is disabled

Fixes https://gitlab.com/gitlab-org/gitlab-ce/issues/17749

See merge request !4263
parent c0206b51
module Backup module Backup
class Manager class Manager
ARCHIVES_TO_BACKUP = %w[uploads builds artifacts lfs registry]
FOLDERS_TO_BACKUP = %w[repositories db]
def pack def pack
# Make sure there is a connection # Make sure there is a connection
ActiveRecord::Base.connection.reconnect! ActiveRecord::Base.connection.reconnect!
...@@ -147,7 +150,7 @@ module Backup ...@@ -147,7 +150,7 @@ module Backup
end end
def skipped?(item) def skipped?(item)
settings[:skipped] && settings[:skipped].include?(item) settings[:skipped] && settings[:skipped].include?(item) || disabled_features.include?(item)
end end
private private
...@@ -157,11 +160,17 @@ module Backup ...@@ -157,11 +160,17 @@ module Backup
end end
def archives_to_backup def archives_to_backup
%w{uploads builds artifacts lfs registry}.map{ |name| (name + ".tar.gz") unless skipped?(name) }.compact ARCHIVES_TO_BACKUP.map{ |name| (name + ".tar.gz") unless skipped?(name) }.compact
end end
def folders_to_backup def folders_to_backup
%w{repositories db}.reject{ |name| skipped?(name) } FOLDERS_TO_BACKUP.reject{ |name| skipped?(name) }
end
def disabled_features
features = []
features << 'registry' unless Gitlab.config.registry.enabled
features
end end
def settings def settings
......
...@@ -179,18 +179,26 @@ namespace :gitlab do ...@@ -179,18 +179,26 @@ namespace :gitlab do
task create: :environment do task create: :environment do
$progress.puts "Dumping container registry images ... ".blue $progress.puts "Dumping container registry images ... ".blue
if Gitlab.config.registry.enabled
if ENV["SKIP"] && ENV["SKIP"].include?("registry") if ENV["SKIP"] && ENV["SKIP"].include?("registry")
$progress.puts "[SKIPPED]".cyan $progress.puts "[SKIPPED]".cyan
else else
Backup::Registry.new.dump Backup::Registry.new.dump
$progress.puts "done".green $progress.puts "done".green
end end
else
$progress.puts "[DISABLED]".cyan
end
end end
task restore: :environment do task restore: :environment do
$progress.puts "Restoring container registry images ... ".blue $progress.puts "Restoring container registry images ... ".blue
if Gitlab.config.registry.enabled
Backup::Registry.new.restore Backup::Registry.new.restore
$progress.puts "done".green $progress.puts "done".green
else
$progress.puts "[DISABLED]".cyan
end
end end
end end
......
...@@ -2,6 +2,8 @@ require 'spec_helper' ...@@ -2,6 +2,8 @@ require 'spec_helper'
require 'rake' require 'rake'
describe 'gitlab:app namespace rake task' do describe 'gitlab:app namespace rake task' do
let(:enable_registry) { true }
before :all do before :all do
Rake.application.rake_require 'tasks/gitlab/task_helpers' Rake.application.rake_require 'tasks/gitlab/task_helpers'
Rake.application.rake_require 'tasks/gitlab/backup' Rake.application.rake_require 'tasks/gitlab/backup'
...@@ -15,6 +17,10 @@ describe 'gitlab:app namespace rake task' do ...@@ -15,6 +17,10 @@ describe 'gitlab:app namespace rake task' do
FileUtils.mkdir_p('public/uploads') FileUtils.mkdir_p('public/uploads')
end end
before do
stub_container_registry_config(enabled: enable_registry)
end
def run_rake_task(task_name) def run_rake_task(task_name)
Rake::Task[task_name].reenable Rake::Task[task_name].reenable
Rake.application.invoke_task task_name Rake.application.invoke_task task_name
...@@ -143,6 +149,18 @@ describe 'gitlab:app namespace rake task' do ...@@ -143,6 +149,18 @@ describe 'gitlab:app namespace rake task' do
expect(temp_dirs).to be_empty expect(temp_dirs).to be_empty
end end
context 'registry disabled' do
let(:enable_registry) { false }
it 'should not create registry.tar.gz' do
tar_contents, exit_status = Gitlab::Popen.popen(
%W{tar -tvf #{@backup_tar}}
)
expect(exit_status).to eq(0)
expect(tar_contents).not_to match('registry.tar.gz')
end
end
end # backup_create task end # backup_create task
describe "Skipping items" do describe "Skipping items" do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment