phase 0.0.14 → 0.0.15

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: 9590eb70829edd6661e39eb4068ee18a060ec7fa
4
- data.tar.gz: a57a7125ac33e183892a1106ffa54b246d9dc00e
3
+ metadata.gz: 0348a387cd72008efb9ac4e146666f193ac0007b
4
+ data.tar.gz: 3b871ecfcc7d89b48dcc90ff78cd114b3e749240
5
5
  SHA512:
6
- metadata.gz: 391d201d50bdf8fc062a267cbfa9420770ae91ae3ce964ec701b3b0413a59465ecbe91465b08b565898c829504bbf54c1c8f7b1728cdf8101d43e3eecc52366b
7
- data.tar.gz: 8ba069008cb11010e2ff2a08287b47684acb68a7d91be271fdc056e4db365bb05bfd494207f9d18defa6a5d577647c35ce2bb07d5aada630aa559e419976ad3f
6
+ metadata.gz: 7912b55eb7b03d26e9fae06c27f2dd46eb7f693dfdd5e4a89207ec03880e27abfb3221eaa35a451b26f06341be771d1a69a26ce49adba59c84466eef064970f1
7
+ data.tar.gz: df587124963dc679162d2e825a5a92ed1a4b7c1b0049dde356dba42b481d252df0adce6fa3486760d2de899c51cebe4d419c07d0a1d51ab4d4c87d6b03dd1ecf
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.14
1
+ 0.0.15
@@ -3,10 +3,12 @@ module Phase
3
3
  class Deploy < Command
4
4
 
5
5
  command :deploy do |c|
6
- c.syntax = "phase deploy <environment>"
6
+ c.syntax = "phase deploy [-e environment_name] version_number"
7
+
8
+ c.option "-e", "--env environment_name", String, "Deploy to this environment."
7
9
 
8
10
  c.description = <<-EOS.strip_heredoc
9
- Builds and deploys code to the specified <environment>. <environment> may be
11
+ Builds and deploys code to the specified 'environment_name'. 'environment_name' may be
10
12
  any environment configured in the Phasefile.
11
13
  EOS
12
14
 
@@ -15,18 +17,31 @@ module Phase
15
17
  end
16
18
  end
17
19
 
18
- attr_reader :environment
20
+ attr_reader :version_number
19
21
 
20
22
  def initialize(args, options)
21
- @environment = args.first
22
23
  super
24
+
25
+ @version_number = args.first
26
+
27
+ fail "must specify environment with '-e'" unless options.env
28
+ fail "must specify version number" unless version_number
23
29
  end
24
30
 
25
31
  def run
26
- if environment == "sandbox"
27
- deployment = ::Phase::Deploy::SandboxDeployment.new
32
+ opts = {
33
+ version_tag: version_number
34
+ }
35
+
36
+ deployment = case options.env
37
+ when "sandbox"
38
+ ::Phase::Deploy::SandboxDeployment.new(opts)
39
+ when "staging"
40
+ ::Phase::Deploy::StagingDeployment.new(opts)
41
+ when "production"
42
+ ::Phase::Deploy::ProductionDeployment.new(opts)
28
43
  else
29
- deployment = ::Phase::Deploy::Deployment.new(environment)
44
+ fail "unknown environment: '#{environment}'"
30
45
  end
31
46
 
32
47
  deployment.execute!
@@ -2,42 +2,56 @@ module Phase
2
2
  module Deploy
3
3
 
4
4
  class Build
5
+ include ::Phase::Util::Shell
6
+
5
7
  attr_reader :version_tag, :build_dir
6
8
 
7
9
  def initialize(version_tag, options = {})
8
10
  @version_tag = version_tag
9
- @build_dir = options.fetch(:build_dir, "./build")
11
+ @build_dir = ::Pathname.new( options.fetch(:build_dir, "build") )
10
12
  end
11
13
 
12
- def execute
14
+ def execute!
13
15
  build_image
14
- tag_image
16
+ # tag_image
15
17
  push
16
18
  end
17
19
 
18
20
  private
19
21
 
20
22
  def build_image
21
- clear_build_dir
23
+ remove_stale_build_dir
22
24
  clone_local_repo
23
- system("docker build -t #{repo_name}:#{version_tag} #{build_dir}")
25
+
26
+ shell("docker build -t #{repo_name}:#{version_tag} #{build_dir}") do |status|
27
+ fail "couldn't build Docker image"
28
+ end
24
29
  end
25
30
 
26
- def clear_build_dir
27
- ::FileUtils.mkdir_p(build_dir)
31
+ def remove_stale_build_dir
32
+ ::FileUtils.rm_r(build_dir)
28
33
  end
29
34
 
30
35
  def clone_local_repo
31
- system("git clone --depth 1 -- file://$(pwd) #{build_dir}")
36
+ shell("git clone --depth 1 -- file://$(pwd) #{build_dir}") do |status|
37
+ fail "couldn't clone local copy of git repository"
38
+ end
32
39
  end
33
40
 
34
- def tag_image
35
- system("docker tag #{repo_name}:#{version_tag} #{repo_name}:latest")
36
- end
41
+ # def tag_image
42
+ # shell("docker tag #{repo_name}:#{version_tag} #{repo_name}:latest") do |status|
43
+ # fail "couldn't tag Docker image"
44
+ # end
45
+ # end
37
46
 
38
47
  def push
39
- system("docker push #{repo_name}:#{version_tag}")
40
- system("docker push #{repo_name}:latest")
48
+ shell("docker push #{repo_name}:#{version_tag}") do |status|
49
+ fail "couldn't push #{repo_name}:#{version_tag}"
50
+ end
51
+
52
+ shell("docker push #{repo_name}:latest") do |status|
53
+ fail "couldn't push #{repo_name}:latest"
54
+ end
41
55
  end
42
56
 
43
57
  def repo_name
@@ -55,11 +69,15 @@ module Phase
55
69
  private
56
70
 
57
71
  def build_image
58
- system("docker build -t #{repo_name}:#{version_tag} .")
72
+ shell("docker build -t #{repo_name}:#{version_tag} .") do |status|
73
+ fail "couldn't build Docker image"
74
+ end
59
75
  end
60
76
 
61
77
  def push
62
- system("docker push #{repo_name}:#{version_tag}")
78
+ shell("docker push #{repo_name}:#{version_tag}") do |status|
79
+ fail "couldn't push #{repo_name}:#{version_tag}"
80
+ end
63
81
  end
64
82
  end
65
83
 
@@ -2,25 +2,42 @@ module Phase
2
2
  module Deploy
3
3
 
4
4
  class Deployment
5
- attr_reader :environment, :build
5
+ attr_reader :options, :build
6
6
 
7
- def initialize(environment, options = {})
8
- @environment = environment
9
- @build = Build.new(options[:version_tag])
7
+ def initialize(options = {})
8
+ @options = options
9
+ end
10
+
11
+ def build
12
+ @build ||= Build.new(options[:version_tag])
10
13
  end
11
14
 
12
15
  def execute!
13
- @build.execute
16
+ build.execute!
14
17
  deploy_image
15
18
  end
19
+
20
+ private
21
+
22
+ def deploy_image
23
+ system("")
24
+ end
16
25
  end
17
26
 
18
27
 
19
28
  class SandboxDeployment < Deployment
20
- def initialize(options = {})
21
- @build = SandboxBuild.new(options[:version_tag])
29
+ def build
30
+ @build ||= SandboxBuild.new(options[:version_tag])
22
31
  end
23
32
  end
24
33
 
34
+
35
+ class StagingDeployment < Deployment
36
+ end
37
+
38
+
39
+ class ProductionDeployment < Deployment
40
+ end
41
+
25
42
  end
26
43
  end
@@ -0,0 +1,15 @@
1
+ module Phase
2
+ module Util
3
+ module Shell
4
+ include Console
5
+
6
+ def shell(*args)
7
+ log "running: #{args.join(' ')}"
8
+ status = !!system(*args)
9
+ yield $? unless status
10
+ return status
11
+ end
12
+
13
+ end
14
+ end
15
+ end
data/lib/phase/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Phase
2
- VERSION = "0.0.14"
2
+ VERSION = "0.0.15"
3
3
  end
data/lib/phase.rb CHANGED
@@ -4,6 +4,7 @@ require 'colorize'
4
4
  require 'erb'
5
5
  require 'fog'
6
6
  require 'progressbar'
7
+ require 'pry'
7
8
  require 'sshkit'
8
9
  require 'terminal-table'
9
10
 
@@ -13,6 +14,10 @@ require 'phase/adapters/abstract'
13
14
  require 'phase/adapters/aws'
14
15
 
15
16
  require "phase/util/console"
17
+ require "phase/util/shell"
18
+
19
+ require 'phase/kit/deploy/build'
20
+ require 'phase/kit/deploy/deployment'
16
21
 
17
22
  require 'phase/kit/ipa/app'
18
23
  require 'phase/kit/ipa/enterprise_deployment'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phase
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.14
4
+ version: 0.0.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piers Mainwaring
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-05-11 00:00:00.000000000 Z
12
+ date: 2015-05-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: commander
@@ -232,6 +232,7 @@ files:
232
232
  - lib/phase/tasks/deploy.rb
233
233
  - lib/phase/templates/ipa_xml.plist
234
234
  - lib/phase/util/console.rb
235
+ - lib/phase/util/shell.rb
235
236
  - lib/phase/version.rb
236
237
  - phase.gemspec
237
238
  - spec/dsl_spec.rb