Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJames Fargher <proglottis@gmail.com>2019-07-18 06:45:12 +0300
committerJames Fargher <proglottis@gmail.com>2019-08-20 05:12:44 +0300
commit30004bc9b77ec02cfbf30e951c8adc7978081762 (patch)
treed5059bf603340b2cb47af257ba966c7fc32a5314 /lib
parent1068483f7260e5866c7d54f1f09b716dbf463c80 (diff)
Initial detection of Auto-DevOps buildable projects
Contains a large list of files we expect to find for an Auto-DevOps project.
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/auto_devops/buildable_detector.rb103
-rw-r--r--lib/gitlab/ci/build/prerequisite/auto_devops_buildable.rb32
-rw-r--r--lib/gitlab/ci/build/prerequisite/factory.rb2
-rw-r--r--lib/gitlab/ci/pipeline/chain/validate/config.rb6
4 files changed, 141 insertions, 2 deletions
diff --git a/lib/gitlab/auto_devops/buildable_detector.rb b/lib/gitlab/auto_devops/buildable_detector.rb
new file mode 100644
index 00000000000..68f29f8bc34
--- /dev/null
+++ b/lib/gitlab/auto_devops/buildable_detector.rb
@@ -0,0 +1,103 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module AutoDevops
+ class BuildableDetector
+ VARIABLES = [
+ 'BUILDPACK_URL'
+ ].freeze
+
+ FILE_PATTERNS = [
+ 'Dockerfile',
+
+ # https://github.com/heroku/heroku-buildpack-clojure
+ 'project.clj',
+
+ # https://github.com/heroku/heroku-buildpack-go
+ 'go.mod',
+ 'Gopkg.mod',
+ 'Godeps/Godeps.json',
+ 'vendor/vendor.json',
+ 'glide.yaml',
+ 'src/**.go',
+
+ # https://github.com/heroku/heroku-buildpack-gradle
+ 'gradlew',
+ 'build.gradle',
+ 'settings.gradle',
+
+ # https://github.com/heroku/heroku-buildpack-java
+ 'pom.xml',
+ 'pom.atom',
+ 'pom.clj',
+ 'pom.groovy',
+ 'pom.rb',
+ 'pom.scala',
+ 'pom.yaml',
+ 'pom.yml',
+
+ # https://github.com/heroku/heroku-buildpack-multi
+ '.buildpacks',
+
+ # https://github.com/heroku/heroku-buildpack-nodejs
+ 'package.json',
+
+ # https://github.com/heroku/heroku-buildpack-php
+ 'composer.json',
+ 'index.php',
+
+ # https://github.com/heroku/heroku-buildpack-play
+ # TODO: detect script excludes some scala files
+ '*/conf/application.conf',
+ '*modules*',
+
+ # https://github.com/heroku/heroku-buildpack-python
+ # TODO: detect script checks that all of these exist, not any
+ 'requirements.txt',
+ 'setup.py',
+ 'Pipfile',
+
+ # https://github.com/heroku/heroku-buildpack-ruby
+ 'Gemfile',
+
+ # https://github.com/heroku/heroku-buildpack-scala
+ '*.sbt',
+ 'project/*.scala',
+ '.sbt/*.scala',
+ 'project/build.properties',
+
+ # https://github.com/dokku/buildpack-nginx
+ '.static'
+ ].freeze
+
+ def initialize(project, ref)
+ @project = project
+ @ref = ref
+ end
+
+ def buildable?
+ detected_variables? || detected_files?
+ end
+
+ private
+
+ attr_accessor :project, :ref
+
+ def detected_variables?
+ project.ci_variables_for(ref: ref).exists?(key: VARIABLES) # rubocop:disable CodeReuse/ActiveRecord
+ end
+
+ def detected_files?
+ return if !ref && !project.repository.root_ref
+
+ project.repository.ls_files(ref).find do |filename|
+ FILE_PATTERNS.any? do |pattern|
+ File.fnmatch?(pattern, filename, File::FNM_CASEFOLD)
+ end
+ end
+ rescue GRPC::NotFound
+ false
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/ci/build/prerequisite/auto_devops_buildable.rb b/lib/gitlab/ci/build/prerequisite/auto_devops_buildable.rb
new file mode 100644
index 00000000000..1c03be32d19
--- /dev/null
+++ b/lib/gitlab/ci/build/prerequisite/auto_devops_buildable.rb
@@ -0,0 +1,32 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Ci
+ module Build
+ module Prerequisite
+ class AutoDevopsBuildable < Base
+ def unmet?
+ build.project.auto_devops_enabled? &&
+ !build.project.has_auto_devops_explicitly_enabled? &&
+ build.pipeline.auto_devops_buildable.nil? &&
+ build.pipeline.auto_devops_source?
+ end
+
+ def complete!
+ return unless unmet?
+
+ build.pipeline.update!(auto_devops_buildable: auto_devops_buildable?)
+
+ throw :unsupported unless build.pipeline.auto_devops_buildable?
+ end
+
+ private
+
+ def auto_devops_buildable?
+ !!Gitlab::AutoDevops::BuildableDetector.new(build.project, build.pipeline.sha).buildable?
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/ci/build/prerequisite/factory.rb b/lib/gitlab/ci/build/prerequisite/factory.rb
index 60cdf7af418..a42c88ded58 100644
--- a/lib/gitlab/ci/build/prerequisite/factory.rb
+++ b/lib/gitlab/ci/build/prerequisite/factory.rb
@@ -8,7 +8,7 @@ module Gitlab
attr_reader :build
def self.prerequisites
- [KubernetesNamespace]
+ [KubernetesNamespace, AutoDevopsBuildable]
end
def initialize(build)
diff --git a/lib/gitlab/ci/pipeline/chain/validate/config.rb b/lib/gitlab/ci/pipeline/chain/validate/config.rb
index 28c38cc3d18..a6f63eabb80 100644
--- a/lib/gitlab/ci/pipeline/chain/validate/config.rb
+++ b/lib/gitlab/ci/pipeline/chain/validate/config.rb
@@ -11,7 +11,11 @@ module Gitlab
def perform!
unless @pipeline.config_processor
unless @pipeline.ci_yaml_file
- return error("Missing #{@pipeline.ci_yaml_file_path} file")
+ if @pipeline.project.auto_devops_enabled?
+ return error("Auto-DevOps enabled but no buildable files found")
+ else
+ return error("Missing #{@pipeline.ci_yaml_file_path} file")
+ end
end
if @command.save_incompleted && @pipeline.has_yaml_errors?