Module: Concourse::Util
Constant Summary collapse
- GITIGNORE_FILE =
".gitignore"
- GITATTRIBUTES_FILE =
".gitattributes"
Instance Method Summary collapse
- #docker_compose(command) ⇒ Object
- #docker_compose_path ⇒ Object
- #each_job(pipeline) ⇒ Object
- #each_task(pipeline) ⇒ Object
- #ensure_in_gitignore(file_glob) ⇒ Object
- #erbify_file(filename, working_directory: nil) ⇒ Object
- #find_task(job_task) ⇒ Object
- #fly(command) ⇒ Object
- #note(message) ⇒ Object
- #running(message) ⇒ Object
- #sh(command) ⇒ Object
Instance Method Details
#docker_compose(command) ⇒ Object
25 26 27 |
# File 'lib/concourse/util.rb', line 25 def docker_compose command sh "docker-compose -f #{docker_compose_path} #{command}" end |
#docker_compose_path ⇒ Object
29 30 31 |
# File 'lib/concourse/util.rb', line 29 def docker_compose_path File.join(directory, CONCOURSE_DOCKER_COMPOSE) end |
#each_job(pipeline) ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/concourse/util.rb', line 59 def each_job pipeline pdata = YAML.load_file(pipeline.filename) pdata["jobs"].each do |job| yield job end end |
#each_task(pipeline) ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/concourse/util.rb', line 67 def each_task pipeline each_job(pipeline) do |job| job["plan"].each do |task| yield job, task if task["task"] end end end |
#ensure_in_gitignore(file_glob) ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/concourse/util.rb', line 10 def ensure_in_gitignore file_glob if File.exist?(GITIGNORE_FILE) if File.read(GITIGNORE_FILE).split("\n").include?(file_glob) note "found '#{file_glob}' already present in #{GITIGNORE_FILE}" return end end note "adding '#{file_glob}' to #{GITIGNORE_FILE}" File.open(GITIGNORE_FILE, "a") { |f| f.puts file_glob } end |
#erbify_file(filename, working_directory: nil) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/concourse/util.rb', line 46 def erbify_file filename, working_directory: nil raise "ERROR: erbify_file: could not find file `#{filename}`" unless File.exist?(filename) template = File.read(filename) if working_directory.nil? working_directory = "." # so chdir is a no-op below else fqwd = File.(working_directory) $LOAD_PATH << fqwd unless $LOAD_PATH.include?(fqwd) # so "require" can load relative paths end Dir.chdir(working_directory) { ERB.new(template, nil, "%-").result(binding) } end |
#find_task(job_task) ⇒ Object
75 76 77 78 79 80 81 82 83 |
# File 'lib/concourse/util.rb', line 75 def find_task job_task job_name, task_name = *job_task.split("/") pipelines.each do |pipeline| each_task(pipeline) do |job, task| return task if task["task"] == task_name && job["name"] == job_name end end nil end |
#fly(command) ⇒ Object
21 22 23 |
# File 'lib/concourse/util.rb', line 21 def fly command sh "fly -t #{fly_target} #{command}" end |
#note(message) ⇒ Object
42 43 44 |
# File 'lib/concourse/util.rb', line 42 def note print bold, green, "NOTE: ", reset, , "\n" end |
#running(message) ⇒ Object
38 39 40 |
# File 'lib/concourse/util.rb', line 38 def running print bold, red, "RUNNING: ", reset, , "\n" end |
#sh(command) ⇒ Object
33 34 35 36 |
# File 'lib/concourse/util.rb', line 33 def sh command running "(in #{Dir.pwd}) #{command}" Rake.sh command, verbose: false end |