Class: Concourse
- Inherits:
-
Object
- Object
- Concourse
- Includes:
- Rake::DSL
- Defined in:
- lib/concourse.rb,
lib/concourse/version.rb
Constant Summary collapse
- RUBIES =
these numbers/names align with public docker image names
{ mri: %w[2.1 2.2 2.3 2.4], # docker repository: "ruby" jruby: %w[1.7 9.1], # docker repository: "jruby" rbx: %w[latest], # docker repository: "rubinius/docker" }
- DIRECTORY =
"concourse"- PRIVATE_VAR_FILE =
File.join DIRECTORY, "private.yml"
- VERSION =
"0.7.0"
Instance Attribute Summary collapse
-
#pipeline_erb_filename ⇒ Object
readonly
Returns the value of attribute pipeline_erb_filename.
-
#pipeline_filename ⇒ Object
readonly
Returns the value of attribute pipeline_filename.
-
#project_name ⇒ Object
readonly
Returns the value of attribute project_name.
Class Method Summary collapse
Instance Method Summary collapse
- #badge_url_for(url_prefix, team_name, job_name) ⇒ Object
- #create_tasks! ⇒ Object
- #each_job ⇒ Object
- #each_task ⇒ Object
- #find_task(job_task) ⇒ Object
-
#initialize(project_name) ⇒ Concourse
constructor
A new instance of Concourse.
- #job_url_for(url_prefix, team_name, job_name) ⇒ Object
- #titleize(string) ⇒ Object
Constructor Details
#initialize(project_name) ⇒ Concourse
Returns a new instance of Concourse.
29 30 31 32 33 |
# File 'lib/concourse.rb', line 29 def initialize project_name @project_name = project_name @pipeline_filename = File.join(DIRECTORY, "#{project_name}.yml") @pipeline_erb_filename = "#{pipeline_filename}.erb" end |
Instance Attribute Details
#pipeline_erb_filename ⇒ Object (readonly)
Returns the value of attribute pipeline_erb_filename.
16 17 18 |
# File 'lib/concourse.rb', line 16 def pipeline_erb_filename @pipeline_erb_filename end |
#pipeline_filename ⇒ Object (readonly)
Returns the value of attribute pipeline_filename.
16 17 18 |
# File 'lib/concourse.rb', line 16 def pipeline_filename @pipeline_filename end |
#project_name ⇒ Object (readonly)
Returns the value of attribute project_name.
16 17 18 |
# File 'lib/concourse.rb', line 16 def project_name @project_name end |
Class Method Details
.url_for(fly_target) ⇒ Object
25 26 27 |
# File 'lib/concourse.rb', line 25 def self.url_for fly_target `fly targets`.split("\n").grep(/^#{fly_target}/).first.split(/ +/)[1] end |
.validate_fly_target(task, task_args) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/concourse.rb', line 18 def self.validate_fly_target task, task_args unless task_args[:fly_target] raise "ERROR: must specify a fly target, like `rake #{task.name}[targetname]`" end return task_args[:fly_target] end |
Instance Method Details
#badge_url_for(url_prefix, team_name, job_name) ⇒ Object
173 174 175 176 177 178 179 180 181 182 |
# File 'lib/concourse.rb', line 173 def badge_url_for url_prefix, team_name, job_name File.join url_prefix, "api/v1/teams", team_name, "pipelines", project_name, "jobs", job_name, "badge" end |
#create_tasks! ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/concourse.rb', line 35 def create_tasks! unless Dir.exist? DIRECTORY mkdir_p DIRECTORY end unless File.exist? pipeline_erb_filename raise "ERROR: concourse pipeline template #{pipeline_erb_filename.inspect} does not exist" end CLOBBER.include pipeline_filename if defined?(CLOBBER) namespace :concourse do # # pipeline commands # desc "generate and validate the pipeline file for #{project_name}" task "generate" do |t| File.open pipeline_filename, "w" do |f| f.write ERB.new(File.read(pipeline_erb_filename)).result(binding) end sh "fly validate-pipeline -c #{pipeline_filename}" end desc "upload the pipeline file for #{project_name}" task "set", [:fly_target] => ["generate"] do |t, args| fly_target = Concourse.validate_fly_target t, args = [ "-p '#{project_name}'", "-c '#{pipeline_filename}'", ] if File.exist? PRIVATE_VAR_FILE puts "using #{PRIVATE_VAR_FILE} to resolve template vars" << "-l '#{PRIVATE_VAR_FILE}'" end sh "fly -t #{fly_target} set-pipeline #{options.join(" ")}" end %w[expose hide pause unpause].each do |command| desc "#{command} the #{project_name} pipeline" task "#{command}", [:fly_target] do |t, args| fly_target = Concourse.validate_fly_target t, args sh "fly -t #{fly_target} #{command}-pipeline -p #{project_name}" end end desc "remove generate pipeline file" task "clean" do |t| rm_f pipeline_filename end # # task commands # desc "list all the available tasks from the #{project_name} pipeline" task "tasks" => "generate" do tasks = [] each_task do |job, task| tasks << "#{job["name"]}/#{task["task"]}" end puts "Available Concourse tasks for #{project_name} are:" tasks.sort.each { |task| puts " * #{task}" } end desc "fly execute the specified task" task "task", [:fly_target, :job_task, :fly_execute_args] => "generate" do |t, args| fly_target = Concourse.validate_fly_target t, args job_task = args[:job_task] fly_execute_args = args[:fly_execute_args] || "--input=#{project_name}=." unless job_task raise "ERROR: must specify a task name, like `rake #{t.name}[target,taskname]`" end concourse_task = find_task job_task raise "ERROR: could not find task `#{job_task}`" unless concourse_task puts concourse_task.to_yaml Tempfile.create do |f| f.write concourse_task["config"].to_yaml f.close sh "fly -t #{fly_target} execute #{fly_execute_args} -c #{f.path} -x" end end # # badge commands # desc "display a list of jobs and badge urls" task "badges", [:fly_target, :team_name] => "generate" do |t, args| fly_target = Concourse.validate_fly_target t, args team_name = args[:team_name] || "main" url_prefix = Concourse.url_for fly_target puts "" puts "| Build | Status |" puts "|--|--|" each_job do |job| job_name = job["name"] badge_url = badge_url_for url_prefix, team_name, job_name job_url = job_url_for url_prefix, team_name, job_name puts %Q'| #{titleize job_name} | [](#{job_url}) |' end end end end |
#each_job ⇒ Object
145 146 147 148 149 150 151 |
# File 'lib/concourse.rb', line 145 def each_job pipeline = YAML.load_file(pipeline_filename) pipeline["jobs"].each do |job| yield job end end |
#each_task ⇒ Object
153 154 155 156 157 158 159 |
# File 'lib/concourse.rb', line 153 def each_task each_job do |job| job["plan"].each do |task| yield job, task if task["task"] end end end |
#find_task(job_task) ⇒ Object
161 162 163 164 165 166 167 |
# File 'lib/concourse.rb', line 161 def find_task job_task job_name, task_name = *job_task.split("/") each_task do |job, task| return task if task["task"] == task_name && job["name"] == job_name end nil end |
#job_url_for(url_prefix, team_name, job_name) ⇒ Object
184 185 186 187 188 189 190 191 192 |
# File 'lib/concourse.rb', line 184 def job_url_for url_prefix, team_name, job_name File.join url_prefix, "teams", team_name, "pipelines", project_name, "jobs", job_name end |
#titleize(string) ⇒ Object
169 170 171 |
# File 'lib/concourse.rb', line 169 def titleize string string.gsub(/[^a-zA-Z0-9\.]/, " ") end |