argus-builder 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 145c2ab7806fa9d79f972c7c7204fab58c7f991f
4
- data.tar.gz: afbc50652c564cfd36b3de596c01d901072290c3
3
+ metadata.gz: 88b9eb34ea2855eef14e84724d8a49746255fb3b
4
+ data.tar.gz: e0d866df02658db26a327ba49a27c783fbe71721
5
5
  SHA512:
6
- metadata.gz: 45bb8ebdb954fbff07336c80f870b0dd0a102a63256e11c541daf4f777ba9cad1801d54c4a34b1ccc4f4571defd2a76d965418bb2f95f46dbe421a354fb3ae4d
7
- data.tar.gz: d9c5c2c0848dfd1be63a487deacd4db6993d7fe30d4c5ae0156498e9f26114cd596bf72d87c4d43f677655417ae0a91ac675666e9e91c149569826ca8a721268
6
+ metadata.gz: 12b77e5e546de73c42ac94cc4b107009899764a3872505494318171c534928fe6117726a228a7d1d1ec3bd143b1c702f62f51244d9d145c9d3c7e9e180c6b307
7
+ data.tar.gz: afaa3cfa70c350ce7d88635a5f9d5a9a1dcb1880776a4d299293ee9b9df9f19a39fe697e176c947e599316b5b4aca0c0b182ac74d6c8d8afe31a7bc0adbbc2bc
data/README.md CHANGED
@@ -116,8 +116,8 @@ require 'aws-sdk'
116
116
  msg = {
117
117
  org: org,
118
118
  repo: repo,
119
- branch: branch,
120
- tag: repo:branch # optional
119
+ branch: branch, # optional, defaults to master
120
+ tag: repo:branch # optional. defaults to repo:branch
121
121
  }
122
122
 
123
123
  sqs = Aws::SQS::Client.new
@@ -2,28 +2,39 @@
2
2
  ## run a single argus build directly
3
3
 
4
4
  require 'argus'
5
+ require 'optparse'
5
6
 
6
- usage = 'argus-build org/repo:branch [sha]'
7
+ USAGE = 'argus-build org/repo:branch'
7
8
 
8
- if ARGV.empty?
9
- puts "Usage: #{usage}"
10
- exit
11
- end
12
-
13
- ## parse github repo
14
- org, repo, branch = ARGV[0].split(/[\/:]+/, 3)
15
- sha = ARGV[1] || nil
16
-
17
- ## incoming message from sqs
9
+ ## msg to send to argus runner
18
10
  msg = {
19
- org: org,
20
- repo: repo,
21
- branch: branch,
22
- sha: sha
11
+ build_options: {}
23
12
  }
24
13
 
14
+ OptionParser.new do |opts|
15
+ opts.banner = USAGE
16
+
17
+ opts.on('-s', '--sha SHA', 'Git SHA to build') do |s|
18
+ msg[:sha] = s
19
+ end
20
+
21
+ opts.on('-d', '--dockerfile FILENAME', 'Name of Dockerfile') do |d|
22
+ msg[:build_options][:dockerfile] = d
23
+ end
24
+
25
+ opts.on('-n', '--no-cache', 'Invalidate docker build cache') do |n|
26
+ msg[:build_options][:nocache] = true
27
+ end
28
+ end.parse!
29
+
30
+ abort("Usage: #{USAGE}") if ARGV.empty?
31
+
32
+ ## parse github repo
33
+ msg[:org], msg[:repo], msg[:branch] = ARGV[0].split(/[\/:]+/, 3)
34
+ msg.reject! { |_,v| v.nil? }
35
+
25
36
  ## prevent timeout on docker api operations (e.g. long bundle install during build)
26
- Excon.defaults[:write_timeout] = ENV.fetch('DOCKER_WRITE_TIMEOUT', 1000)
27
- Excon.defaults[:read_timeout] = ENV.fetch('DOCKER_READ_TIMEOUT', 1000)
37
+ Excon.defaults[:write_timeout] = ENV.fetch('DOCKER_WRITE_TIMEOUT', 10000)
38
+ Excon.defaults[:read_timeout] = ENV.fetch('DOCKER_READ_TIMEOUT', 10000)
28
39
 
29
40
  Argus::Runner.new(msg)
@@ -28,12 +28,12 @@ module Argus
28
28
  end
29
29
  end
30
30
 
31
- ## build docker image
32
- def build!
31
+ ## build docker image, with optional API /build params
32
+ def build!(options = {})
33
33
  puts "building #{self}"
34
34
 
35
35
  @build_time = Benchmark.realtime do
36
- @image = Docker::Image.build_from_dir('.', dockerfile: 'Dockerfile') do |chunk|
36
+ @image = Docker::Image.build_from_dir('.', options) do |chunk|
37
37
  chunk.split(/[\r\n]+/).each do |line| # latest docker jams multiple streams into chunk
38
38
  begin
39
39
  stream = JSON.parse(line)['stream']
@@ -46,6 +46,10 @@ module Argus
46
46
 
47
47
  def initialize(msg)
48
48
  msg = symbolize_keys(msg)
49
+ puts "Received message: #{msg}"
50
+
51
+ ## set default
52
+ msg[:branch] ||= 'master'
49
53
 
50
54
  ## make working directory
51
55
  dir = File.join(ENV.fetch('ARGUS_HOME', '/tmp'), msg[:org], msg[:repo])
@@ -65,15 +69,18 @@ module Argus
65
69
  git.pull # get the git repo
66
70
  raise ArgusError, "git sha not found: #{git}" unless git.sha
67
71
 
68
- img.build! # build docker image
72
+ options = msg.fetch(:build_options, {})
73
+ img.build!(options) # build docker image
69
74
  raise ArgusError, 'docker build failed' unless img.is_ok?
70
75
 
71
- notify("build complete for #{img} (#{img.build_time.round}s)", :good)
76
+ short_sha = git.sha.slice(0,7) # human-readable sha for messages
77
+
78
+ notify("build complete for #{img} #{short_sha} (#{img.build_time.round}s)", :good)
72
79
 
73
80
  img.tag!(git.sha) # tag the image
74
81
  img.push(git.sha) # push to registry
75
82
 
76
- notify("push complete for #{img} (#{img.push_time.round}s)", :good)
83
+ notify("push complete for #{img} #{short_sha} (#{img.push_time.round}s)", :good)
77
84
  end
78
85
  rescue ArgusError => e
79
86
  notify(e.message, :danger)
@@ -1,3 +1,3 @@
1
1
  module Argus
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: argus-builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Lister
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-20 00:00:00.000000000 Z
11
+ date: 2016-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler