From 6e58e7ff7ce151fb7a8329faef69cd3a42194216 Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Wed, 1 Jun 2016 20:43:33 +0200 Subject: Use downcased path to container repository as this is expected path by Docker --- app/models/project.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'app/models/project.rb') diff --git a/app/models/project.rb b/app/models/project.rb index c1d9bae44c9..13376da9948 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -313,17 +313,17 @@ class Project < ActiveRecord::Base return unless Gitlab.config.registry.enabled @container_registry_repository ||= begin - token = Auth::ContainerRegistryAuthenticationService.full_access_token(path_with_namespace) + token = Auth::ContainerRegistryAuthenticationService.full_access_token(path_with_namespace.downcase) url = Gitlab.config.registry.api_url host_port = Gitlab.config.registry.host_port registry = ContainerRegistry::Registry.new(url, token: token, path: host_port) - registry.repository(path_with_namespace) + registry.repository(path_with_namespace.downcase) end end def container_registry_repository_url if Gitlab.config.registry.enabled - "#{Gitlab.config.registry.host_port}/#{path_with_namespace}" + "#{Gitlab.config.registry.host_port}/#{path_with_namespace.downcase}" end end -- cgit v1.2.1 From 77cb8ec4d14e3a8b03164423176b3b95977ee809 Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Wed, 1 Jun 2016 22:57:50 +0200 Subject: Introduce container_registry_path_with_namespace --- app/models/project.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'app/models/project.rb') diff --git a/app/models/project.rb b/app/models/project.rb index 13376da9948..525a82c7534 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -309,21 +309,25 @@ class Project < ActiveRecord::Base @repository ||= Repository.new(path_with_namespace, self) end + def container_registry_path_with_namespace + path_with_namespace.downcase + end + def container_registry_repository return unless Gitlab.config.registry.enabled @container_registry_repository ||= begin - token = Auth::ContainerRegistryAuthenticationService.full_access_token(path_with_namespace.downcase) + token = Auth::ContainerRegistryAuthenticationService.full_access_token(container_registry_path_with_namespace) url = Gitlab.config.registry.api_url host_port = Gitlab.config.registry.host_port registry = ContainerRegistry::Registry.new(url, token: token, path: host_port) - registry.repository(path_with_namespace.downcase) + registry.repository(container_registry_path_with_namespace) end end def container_registry_repository_url if Gitlab.config.registry.enabled - "#{Gitlab.config.registry.host_port}/#{path_with_namespace.downcase}" + "#{Gitlab.config.registry.host_port}/#{container_registry_path_with_namespace}" end end -- cgit v1.2.1 From 2d05de7af8de9a11f5bdfec0dd3f294a0148d023 Mon Sep 17 00:00:00 2001 From: Josh Frye Date: Tue, 31 May 2016 08:51:13 -0400 Subject: Cache project build count. Closes #18032 --- app/models/project.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'app/models/project.rb') diff --git a/app/models/project.rb b/app/models/project.rb index 525a82c7534..1375dab8c34 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1011,4 +1011,10 @@ class Project < ActiveRecord::Base update_attribute(:pending_delete, true) end + + def running_or_pending_build_count + Rails.cache.fetch(['projects', id, 'running_or_pending_build_count'], expires_in: 60) do + builds.running_or_pending.count(:all) + end + end end -- cgit v1.2.1 From 4d9622e7d3e927ad158d26c780fee64c6d8183bc Mon Sep 17 00:00:00 2001 From: Josh Frye Date: Tue, 31 May 2016 16:01:16 -0400 Subject: Invalidate cache on build change --- app/models/project.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'app/models/project.rb') diff --git a/app/models/project.rb b/app/models/project.rb index 1375dab8c34..3b5ca05dc3f 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1013,8 +1013,12 @@ class Project < ActiveRecord::Base end def running_or_pending_build_count - Rails.cache.fetch(['projects', id, 'running_or_pending_build_count'], expires_in: 60) do + Rails.cache.fetch(['projects', id, 'running_or_pending_build_count']) do builds.running_or_pending.count(:all) end end + + def expire_running_or_pending_build_count + Rails.cache.delete(['projects', id, 'running_or_pending_build_count']) + end end -- cgit v1.2.1 From 2605a0a844f187daeeff1f16920db445f53e2793 Mon Sep 17 00:00:00 2001 From: Josh Frye Date: Wed, 1 Jun 2016 10:50:32 -0400 Subject: Refactor. Add tests. --- app/models/project.rb | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'app/models/project.rb') diff --git a/app/models/project.rb b/app/models/project.rb index 3b5ca05dc3f..9ccf6a97df6 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1012,13 +1012,9 @@ class Project < ActiveRecord::Base update_attribute(:pending_delete, true) end - def running_or_pending_build_count - Rails.cache.fetch(['projects', id, 'running_or_pending_build_count']) do + def running_or_pending_build_count(force: false) + Rails.cache.fetch(['projects', id, 'running_or_pending_build_count'], force: force) do builds.running_or_pending.count(:all) end end - - def expire_running_or_pending_build_count - Rails.cache.delete(['projects', id, 'running_or_pending_build_count']) - end end -- cgit v1.2.1 From 64c3905523808942ac62b7ebfbce3634b6e9dc17 Mon Sep 17 00:00:00 2001 From: James Lopez Date: Tue, 31 May 2016 11:00:59 +0200 Subject: some refactoring and fixing spec --- app/models/project.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'app/models/project.rb') diff --git a/app/models/project.rb b/app/models/project.rb index 9ccf6a97df6..03429fb7a46 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1017,4 +1017,9 @@ class Project < ActiveRecord::Base builds.running_or_pending.count(:all) end end + + def mark_import_as_failed(error_message) + import_fail + update_column(:import_error, Gitlab::UrlSanitizer.sanitize(error_message)) + end end -- cgit v1.2.1 From 097eafc8c74f97912a52399d422fb24be84e734d Mon Sep 17 00:00:00 2001 From: James Lopez Date: Tue, 31 May 2016 14:53:33 +0200 Subject: fix some issues and improved error output for forking --- app/models/project.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'app/models/project.rb') diff --git a/app/models/project.rb b/app/models/project.rb index 03429fb7a46..e4a9d17a20c 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1019,7 +1019,14 @@ class Project < ActiveRecord::Base end def mark_import_as_failed(error_message) + original_errors = errors.dup + sanitized_message = Gitlab::UrlSanitizer.sanitize(error_message) + import_fail - update_column(:import_error, Gitlab::UrlSanitizer.sanitize(error_message)) + update_column(:import_error, sanitized_message) + rescue ActiveRecord::ActiveRecordError => e + Rails.logger.error("Error setting import status to failed: #{e.message}. Original error: #{sanitized_message}") + ensure + @errors = original_errors end end -- cgit v1.2.1