hillary 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OTY4ZWVkM2MxZjMwYmEyOGIxNGYyMmZhOTliMGVlYzI3MjFkNTVmNg==
4
+ Y2VjZmE1YTk5NDFjYWQ2MTlhOTlmMzMxZWVlNDcyMTM1OTU2MzkxZg==
5
5
  data.tar.gz: !binary |-
6
- N2E4YzZlMmM5ZDZjZGVhMzZlMTZkYjAxMzY2MjNmNzM4NWYxYTQ4Ng==
6
+ YjgxODllNzQ1MDA4NjAwNWQ5MDVjNWI0MjMxMjZkZmI3MmFhMGNmMQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MzMyMjhjZThlNTVhYTA4N2Q2NmY2YmM1YzU0OTFkOTYzNDhhYmNmMGQxZWI1
10
- Yjk1OTFjZGI3NzY3MDdhMTM3YTQ5MDU4OWE5OWI4MTcxMzZjNTg5NDc1Y2Rl
11
- ZDQ2ODIxY2U2OTUxZDE1OTFlM2Q4ZTZlOGNmYjYxOWZjODI1ZGE=
9
+ YWNhOTUwMzU4YjZmNjg4NTRkOTU4N2QzMDgyNmQ2YzgzM2UwMWM0MDhmMWI3
10
+ MjMxM2M2OTQyMzYzYWRmNTkyMTI5MDEwNjAwMTA4NWM4ZTBiOTE0YmY0Nzhk
11
+ MmY1NzM4NDhjYzg4ODg5ZjUzMTQyMDc0MzI2N2YyNjk0MzM3NDY=
12
12
  data.tar.gz: !binary |-
13
- MjkyYzg2ZWMxMDgyNjhhODgzOTcyNDI4YjhkYjZmYmY5ZTg0MzA5MmMwNWMw
14
- Y2YzNTVkYjJhYTZiYTI4NWRjODBmZjI5N2YyZTc0ODI2MWRhYzZhMmU1NzQx
15
- MjIwYTdhNzA2NTM1ZTQ0YmIxNDRiOWJiMDk3NjVjNWI5ODgwYWQ=
13
+ OGI2ZWI5NDcwYjcyOTZlOTUwM2NmNWU0ZjIwODhhY2I0MDAzMmZiMmNlNzY1
14
+ YmYzNjVjZjg4NmJhNjU2MTg0ZjRmNWNlNjU2NmMxNDk3NmI3NGYxOWNmZTUy
15
+ MWE0NTE4OWZlNTAwODZjM2UxNzYzZGIzNjEyZGEzZGIwOTE1YmQ=
@@ -4,8 +4,8 @@ module Hillary
4
4
  class Repo
5
5
  class Version
6
6
  BRANCHES = [
7
- DEV = 'dev',
8
- MASTER = 'master'
7
+ DEV = ENV['DEV_BRANCH'] || 'dev',
8
+ MASTER = ENV['MASTER_BRANCH'] || 'master'
9
9
  ]
10
10
 
11
11
  InvalidRepositoryState = Class.new(StandardError)
@@ -21,7 +21,7 @@ module Hillary
21
21
  def shell(command, options = {})
22
22
  options = {ignore_errors: false, logger: Logger.new($stdout)}.merge(options)
23
23
  logger = options[:logger]
24
- logger.info(command)
24
+ logger.debug(command)
25
25
 
26
26
  output = `#{command} 2>1`
27
27
  status = $?
@@ -15,6 +15,10 @@ module Hillary
15
15
  @directory = @storage.directories.get(name)
16
16
  end
17
17
 
18
+ def exists?(name)
19
+ @directory.files.head(name)
20
+ end
21
+
18
22
  def write(name, file)
19
23
  @directory.files.create(
20
24
  key: name,
data/lib/hillary/slug.rb CHANGED
@@ -11,6 +11,7 @@ module Hillary
11
11
  attr_reader :branch, :version
12
12
 
13
13
  SlugArchiveError = Class.new(StandardError)
14
+ SlugNotFoundError = Class.new(StandardError)
14
15
 
15
16
  class << self
16
17
  def build(path = File.expand_path('.'), version = Repo::Version.create!, options = {})
@@ -23,16 +24,24 @@ module Hillary
23
24
  def initialize(path, version, options = {})
24
25
  @path = path
25
26
  @version = version
26
- @logger = options[:logger] || Logger.new($stdout)
27
27
  @bucket = options[:bucket] || Bucket.new
28
28
 
29
- logger.formatter = proc{|_, _, _, msg| msg + "\n"}
29
+ @logger = if options[:logger]
30
+ options[:logger]
31
+ else
32
+ Logger.new($stdout).tap do |logger|
33
+ logger.formatter = proc do |severity, time, _, msg|
34
+ "#{time.strftime('%Y-%m-%d %H:%M:%S')} #{severity} - #{msg}\n"
35
+ end
36
+ end
37
+ end
30
38
  end
31
39
 
32
40
  def build
33
41
  if version.master?
42
+ create_slug_if_missing
34
43
  copy_slug
35
- else
44
+ elsif version.dev?
36
45
  create_slug
37
46
  upload_slug
38
47
  end
@@ -49,6 +58,18 @@ module Hillary
49
58
  private
50
59
  attr_reader :logger, :bucket, :path
51
60
 
61
+ def create_slug_if_missing
62
+ return if bucket.exists?(canonical_storage_slug_file)
63
+
64
+ if version.production?
65
+ raise SlugNotFoundError, "Attempted to create production slug from RC, but canonical slug (#{bucket.name}:/#{canonical_storage_slug_file}) couldn't be found"
66
+ else
67
+ logger.warn("Unable to find slug #{bucket.name}:/#{canonical_storage_slug_file}")
68
+ create_slug
69
+ upload_slug
70
+ end
71
+ end
72
+
52
73
  def copy_slug
53
74
  logger.info("Copying #{bucket.name}:/#{canonical_storage_slug_file} to #{bucket.name}:/#{storage_slug_file}")
54
75
  bucket.copy(canonical_storage_slug_file, storage_slug_file)
@@ -57,7 +78,10 @@ module Hillary
57
78
  def create_slug
58
79
  Dir.chdir(project_parent_directory) do
59
80
  logger.info("Creating slug #{canonical_slug_file}")
60
- shell("tar --exclude \".git\" --exclude \"vendor/bundle\" -zcvf #{canonical_slug_file} #{project_name}")
81
+
82
+ command = "tar --exclude \".git\" --exclude \"vendor/bundle\" -zcvf #{canonical_slug_file} #{project_name}"
83
+
84
+ shell(command, logger: logger)
61
85
  end
62
86
  end
63
87
 
@@ -1,3 +1,3 @@
1
1
  module Hillary
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -25,6 +25,17 @@ describe Hillary::Slug::Bucket do
25
25
 
26
26
  subject{Hillary::Slug::Bucket.new(bucket_name, access_key, secret_key)}
27
27
 
28
+ describe '#exists?' do
29
+ it 'returns false when the file does not exist' do
30
+ expect(subject.exists?(canonical_slug_path)).to be_falsy
31
+ end
32
+
33
+ it 'returns true when the file does exist' do
34
+ bucket.files.create(key: canonical_slug_path, body: StringIO.new(''), public: false)
35
+ expect(subject.exists?(canonical_slug_path)).to be_truthy
36
+ end
37
+ end
38
+
28
39
  describe '#write' do
29
40
  it 'writes the file to the bucket with the given name' do
30
41
  subject.write(canonical_slug_path, slug_file_path)
@@ -17,9 +17,10 @@ describe Hillary::Slug do
17
17
  let(:out){StringIO.new}
18
18
  let(:logger) do
19
19
  Logger.new(out).tap do |logger|
20
+ logger.formatter = proc{|_, _, _, msg| msg + "\n"}
20
21
  end
21
22
  end
22
- let(:bucket){double(Hillary::Slug::Bucket, write: nil, copy: nil, name: 'gz-slugbucket')}
23
+ let(:bucket){double(Hillary::Slug::Bucket, write: nil, copy: nil, name: 'gz-slugbucket', exists?: true)}
23
24
  let(:path){File.expand_path('../../tmp/g3', __FILE__)}
24
25
 
25
26
  describe '.build' do
@@ -45,20 +46,22 @@ describe Hillary::Slug do
45
46
  end
46
47
 
47
48
  describe '#build' do
49
+ let(:slug_name){'g3_slug_b26206aaf36207304d4fa583ce9837d0bdb48966.tar.gz'}
50
+ let(:slug_path){Pathname.new(path).join('..', slug_name).expand_path}
51
+
52
+ before(:each){FileUtils.mkdir_p(path)}
53
+ after(:each){FileUtils.rm_rf(path)}
54
+
48
55
  context 'when branch is dev' do
49
56
  subject(:slug){described_class.new(path, version, logger: logger, bucket: bucket)}
50
- let(:slug_name){'g3_slug_b26206aaf36207304d4fa583ce9837d0bdb48966.tar.gz'}
51
- let(:slug_path){Pathname.new(path).join('..', slug_name).expand_path}
52
57
 
53
58
  describe 'when everything is successful' do
54
59
  before(:each) do
55
- FileUtils.mkdir_p(path)
56
60
  allow(bucket).to receive(:write)
57
61
  end
58
62
 
59
63
  after(:each) do
60
64
  FileUtils.rm_rf(slug_path)
61
- FileUtils.rm_rf(path)
62
65
  end
63
66
 
64
67
  it 'creates the slug' do
@@ -78,6 +81,7 @@ describe Hillary::Slug do
78
81
 
79
82
  expect(out.string).to eq(
80
83
  "Creating slug g3_slug_b26206aaf36207304d4fa583ce9837d0bdb48966.tar.gz\n"\
84
+ "tar --exclude \".git\" --exclude \"vendor/bundle\" -zcvf g3_slug_b26206aaf36207304d4fa583ce9837d0bdb48966.tar.gz g3\n"\
81
85
  'Uploading g3_slug_b26206aaf36207304d4fa583ce9837d0bdb48966.tar.gz '\
82
86
  "to gz-slugbucket:/dev/g3_slug_b26206aaf36207304d4fa583ce9837d0bdb48966.tar.gz\n"
83
87
  )
@@ -86,6 +90,7 @@ describe Hillary::Slug do
86
90
 
87
91
  describe 'when archiving fails' do
88
92
  it 'raises an error' do
93
+ FileUtils.rm_rf(path)
89
94
  expect{slug.build}.to raise_error(Hillary::Shellable::ExecutionError)
90
95
  end
91
96
  end
@@ -107,18 +112,55 @@ describe Hillary::Slug do
107
112
 
108
113
  subject(:slug){described_class.new(path, version, logger: logger, bucket: bucket)}
109
114
 
110
- it 'copies the canonical slug to rc slug name' do
111
- expect(bucket).to receive(:copy).with('dev/g3_slug_b26206aaf36207304d4fa583ce9837d0bdb48966.tar.gz', 'rc/g3_slug_RC2014_01_01_01_01_01.tar.gz')
115
+ context 'when the canonical slug exists' do
116
+ it 'copies the canonical slug to rc slug name' do
117
+ expect(bucket).to receive(:copy).with('dev/g3_slug_b26206aaf36207304d4fa583ce9837d0bdb48966.tar.gz', 'rc/g3_slug_RC2014_01_01_01_01_01.tar.gz')
112
118
 
113
- slug.build
119
+ slug.build
120
+ end
121
+
122
+ it 'logs information about what is happening' do
123
+ slug.build
124
+
125
+ expect(out.string).to eq(
126
+ 'Copying gz-slugbucket:/dev/g3_slug_b26206aaf36207304d4fa583ce9837d0bdb48966.tar.gz '\
127
+ "to gz-slugbucket:/rc/g3_slug_RC2014_01_01_01_01_01.tar.gz\n"
128
+ )
129
+ end
114
130
  end
115
131
 
116
- it 'logs information about what is happening' do
117
- slug.build
132
+ context 'when the canonical slug does not exist' do
133
+ before(:each){allow(bucket).to receive(:exists?).and_return(false)}
118
134
 
119
- expect(out.string).to eq('Copying gz-slugbucket:/dev/g3_slug_b26206aaf36207304d4fa583ce9837d0bdb48966.tar.gz '\
120
- "to gz-slugbucket:/rc/g3_slug_RC2014_01_01_01_01_01.tar.gz\n"
121
- )
135
+ it 'creates the slug' do
136
+ slug.build
137
+
138
+ expect(File.exist?(slug_path)).to eq(true)
139
+ end
140
+
141
+ it 'writes the slug to the bucket' do
142
+ expect(bucket).to receive(:write).with('dev/' + slug_name, slug_path)
143
+
144
+ slug.build
145
+ end
146
+
147
+ it 'copies the canonical slug to rc slug name' do
148
+ expect(bucket).to receive(:copy).with('dev/g3_slug_b26206aaf36207304d4fa583ce9837d0bdb48966.tar.gz', 'rc/g3_slug_RC2014_01_01_01_01_01.tar.gz')
149
+
150
+ slug.build
151
+ end
152
+
153
+ it 'logs information about what is happening' do
154
+ slug.build
155
+
156
+ expect(out.string).to eq(
157
+ "Unable to find slug gz-slugbucket:/dev/g3_slug_b26206aaf36207304d4fa583ce9837d0bdb48966.tar.gz\n"\
158
+ "Creating slug g3_slug_b26206aaf36207304d4fa583ce9837d0bdb48966.tar.gz\n"\
159
+ "tar --exclude \".git\" --exclude \"vendor/bundle\" -zcvf g3_slug_b26206aaf36207304d4fa583ce9837d0bdb48966.tar.gz g3\n"\
160
+ "Uploading g3_slug_b26206aaf36207304d4fa583ce9837d0bdb48966.tar.gz to gz-slugbucket:/dev/g3_slug_b26206aaf36207304d4fa583ce9837d0bdb48966.tar.gz\n"\
161
+ "Copying gz-slugbucket:/dev/g3_slug_b26206aaf36207304d4fa583ce9837d0bdb48966.tar.gz to gz-slugbucket:/rc/g3_slug_RC2014_01_01_01_01_01.tar.gz\n"
162
+ )
163
+ end
122
164
  end
123
165
  end
124
166
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hillary
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
  - Allen Madsen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-11 00:00:00.000000000 Z
11
+ date: 2014-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: grit