phase 0.0.15 → 0.0.16

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0348a387cd72008efb9ac4e146666f193ac0007b
4
- data.tar.gz: 3b871ecfcc7d89b48dcc90ff78cd114b3e749240
3
+ metadata.gz: e4d5af31cbe28ce6b554391603524b7b2e1f09c6
4
+ data.tar.gz: 0cb46939ed6cd9190d37e8c3ce8ca7687ff7e3dd
5
5
  SHA512:
6
- metadata.gz: 7912b55eb7b03d26e9fae06c27f2dd46eb7f693dfdd5e4a89207ec03880e27abfb3221eaa35a451b26f06341be771d1a69a26ce49adba59c84466eef064970f1
7
- data.tar.gz: df587124963dc679162d2e825a5a92ed1a4b7c1b0049dde356dba42b481d252df0adce6fa3486760d2de899c51cebe4d419c07d0a1d51ab4d4c87d6b03dd1ecf
6
+ metadata.gz: e8d0c8cfff6a464bd2393ada3cb073bd885d5114098a47444d7f4a73308f2d3328624af311af8cff3c7a01f30647f5bd66760f125d627f08622d0326d00cf186
7
+ data.tar.gz: 6fff147f369b8c82aea3c31b0bac1948eb6d62cdb144288953f2752c010a679d93ff40636ab5ae7be654852c46d852c89acc46be311359e332e60d68c7048f78
data/lib/phase/cli/all.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "phase/cli/command"
2
2
 
3
+ require "phase/cli/build"
3
4
  require "phase/cli/env"
4
5
  require "phase/cli/deploy"
5
6
  require "phase/cli/keys"
@@ -0,0 +1,35 @@
1
+ module Phase
2
+ module CLI
3
+ class Build < Command
4
+
5
+ command :build do |c|
6
+ c.syntax = "phase build <version_number>"
7
+
8
+ c.description = <<-EOS.strip_heredoc
9
+ Builds a new Docker image of the latest committed code on the current branch. Tags the
10
+ build with <version_number>.
11
+ EOS
12
+
13
+ c.action do |args, options|
14
+ new(args, options).run
15
+ end
16
+ end
17
+
18
+ attr_reader :version_number
19
+
20
+ def initialize(args, options)
21
+ super
22
+
23
+ @version_number = args[0]
24
+
25
+ fail "must specify version number" unless version_number
26
+ end
27
+
28
+ def run
29
+ build = ::Phase::Deploy::Build.new(version_number)
30
+ build.execute!
31
+ end
32
+
33
+ end
34
+ end
35
+ end
@@ -3,12 +3,10 @@ module Phase
3
3
  class Deploy < Command
4
4
 
5
5
  command :deploy do |c|
6
- c.syntax = "phase deploy [-e environment_name] version_number"
7
-
8
- c.option "-e", "--env environment_name", String, "Deploy to this environment."
6
+ c.syntax = "phase deploy <environment_name> <version_number>"
9
7
 
10
8
  c.description = <<-EOS.strip_heredoc
11
- Builds and deploys code to the specified 'environment_name'. 'environment_name' may be
9
+ Builds and deploys code to the specified <environment_name>, which may be
12
10
  any environment configured in the Phasefile.
13
11
  EOS
14
12
 
@@ -17,33 +15,25 @@ module Phase
17
15
  end
18
16
  end
19
17
 
20
- attr_reader :version_number
18
+ attr_reader :env_name, :version_number
21
19
 
22
20
  def initialize(args, options)
23
21
  super
24
22
 
25
- @version_number = args.first
23
+ fail "must specify both environment and version number" unless args.count >= 2
24
+
25
+ @env_name = args[0]
26
+ @version_number = args[1]
26
27
 
27
- fail "must specify environment with '-e'" unless options.env
28
+ fail "must specify environment" unless env_name
28
29
  fail "must specify version number" unless version_number
29
30
  end
30
31
 
31
32
  def run
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)
43
- else
44
- fail "unknown environment: '#{environment}'"
45
- end
33
+ environment = config.deploy.environments.find { |e| e.name == env_name }
34
+ fail "unknown environment: '#{env_name}'" unless environment
46
35
 
36
+ deployment = Deploy::Deployment.new(environment, version_tag: version_number)
47
37
  deployment.execute!
48
38
  end
49
39
 
@@ -0,0 +1,42 @@
1
+ module Phase
2
+ module Config
3
+ class Deploy
4
+
5
+ # @return [Array<Environment>] the configured deployment environments
6
+ attr_reader :environments
7
+
8
+
9
+ # @return [String] the compact or fully-qualified address of the Docker repository
10
+ # @example Sample settings
11
+ # config.deploy.docker_repository = "mycompany/myrepo"
12
+ # config.deploy.docker_repository = "https://docker.mycompany.com/myrepo"
13
+ attr_accessor :docker_repository
14
+
15
+
16
+ def initialize
17
+ @environments = []
18
+ end
19
+
20
+ # Adds a new deployment environment.
21
+ # @return [Environment] the new environment
22
+ def environment(name, options = {})
23
+ @environments << Environment.new(name, options)
24
+ end
25
+ end
26
+
27
+
28
+ class Environment
29
+
30
+ attr_accessor :name, :perform_build, :server_filters
31
+
32
+ alias_method :perform_build?, :perform_build
33
+
34
+ def initialize(name, options = {})
35
+ @name = name
36
+ @perform_build = options.fetch(:build, true)
37
+ @server_filters = options.fetch(:servers, {})
38
+ end
39
+
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,42 @@
1
+ module Phase
2
+ module Config
3
+ class IPA
4
+
5
+ # @return [String] the bundle ID prefix
6
+ # @example Sample setting
7
+ # config.ipa.bundle_id_prefix = "com.mycompany"
8
+ attr_accessor :bundle_id_prefix
9
+
10
+
11
+ # @return [String] the directory keypath (e.g. 'prefix' at S3) for storing uploaded files
12
+ # @example Sample setting
13
+ # config.ipa.directory_prefix = "somedir/nesteddir"
14
+ attr_accessor :directory_prefix
15
+
16
+
17
+ # @return [String] the bucket for storing uploaded files
18
+ # @example Sample setting
19
+ # config.ipa.bucket_name = "mycompany-enterprise-builds"
20
+ attr_accessor :bucket_name
21
+
22
+
23
+ # @return [String] the company name to provide with enterprise app installs
24
+ # @example Sample setting
25
+ # config.ipa.company_name = "ACME Corp"
26
+ attr_accessor :company_name
27
+
28
+
29
+ # @return [String] the URL of a full-size (512px x 512px) app icon PNG
30
+ # @example Sample setting
31
+ # config.ipa.full_image_url = "https://....png"
32
+ attr_accessor :full_image_url
33
+
34
+
35
+ # @return [String] the URL of a Springboard-size (72px x 72px) app icon PNG
36
+ # @example Sample setting
37
+ # config.ipa.icon_image_url = "https://....png"
38
+ attr_accessor :icon_image_url
39
+
40
+ end
41
+ end
42
+ end
@@ -22,21 +22,14 @@ module Phase
22
22
  ::SSHKit.config.backend = @backend
23
23
  end
24
24
 
25
- # Available options:
26
- # * docker_repository [String]
25
+ # @see Phase::Config::Deploy
27
26
  def deploy
28
- @deploy ||= ::ActiveSupport::OrderedOptions.new
27
+ @deploy ||= Config::Deploy.new
29
28
  end
30
29
 
31
- # Available options:
32
- # * bundle_id_prefix [String]
33
- # * directory_prefix [String]
34
- # * bucket_name [String]
35
- # * company_name [String]
36
- # * full_image_url [String]
37
- # * icon_image_url [String]
30
+ # @see Phase::Config::IPA
38
31
  def ipa
39
- @ipa ||= ::ActiveSupport::OrderedOptions.new
32
+ @ipa ||= Config::IPA.new
40
33
  end
41
34
 
42
35
  def load_phasefile!
@@ -45,10 +38,10 @@ module Phase
45
38
  end
46
39
  end
47
40
 
48
- def set_aws_credentials!
41
+ def set_aws_credentials!(access_key_id = nil, secret_access_key = nil)
49
42
  Fog.credentials = {
50
- aws_access_key_id: ENV.fetch('AWS_ACCESS_KEY_ID'),
51
- aws_secret_access_key: ENV.fetch('AWS_SECRET_ACCESS_KEY')
43
+ aws_access_key_id: ENV.fetch('AWS_ACCESS_KEY_ID', access_key_id),
44
+ aws_secret_access_key: ENV.fetch('AWS_SECRET_ACCESS_KEY', secret_access_key)
52
45
  }
53
46
  end
54
47
 
@@ -20,24 +20,26 @@ module Phase
20
20
  private
21
21
 
22
22
  def build_image
23
- remove_stale_build_dir
24
- clone_local_repo
23
+ prepare_build
25
24
 
26
25
  shell("docker build -t #{repo_name}:#{version_tag} #{build_dir}") do |status|
27
26
  fail "couldn't build Docker image"
28
27
  end
29
28
  end
30
29
 
31
- def remove_stale_build_dir
32
- ::FileUtils.rm_r(build_dir)
33
- end
34
-
35
- def clone_local_repo
36
- shell("git clone --depth 1 -- file://$(pwd) #{build_dir}") do |status|
30
+ def clone_local_git_repo
31
+ current_branch = `git rev-parse --abbrev-ref HEAD`.strip
32
+ shell("git clone --reference $(pwd) --branch #{current_branch} --depth 1 -- file://$(pwd) #{build_dir}") do |status|
37
33
  fail "couldn't clone local copy of git repository"
38
34
  end
39
35
  end
40
36
 
37
+ def prepare_build
38
+ remove_stale_build_dir!
39
+ clone_local_git_repo
40
+ set_file_modification_timestamps
41
+ end
42
+
41
43
  # def tag_image
42
44
  # shell("docker tag #{repo_name}:#{version_tag} #{repo_name}:latest") do |status|
43
45
  # fail "couldn't tag Docker image"
@@ -49,35 +51,21 @@ module Phase
49
51
  fail "couldn't push #{repo_name}:#{version_tag}"
50
52
  end
51
53
 
52
- shell("docker push #{repo_name}:latest") do |status|
53
- fail "couldn't push #{repo_name}:latest"
54
- end
54
+ # shell("docker push #{repo_name}:latest") do |status|
55
+ # fail "couldn't push #{repo_name}:latest"
56
+ # end
55
57
  end
56
58
 
57
- def repo_name
58
- ::Phase.config.deploy.docker_repository
59
+ def remove_stale_build_dir!
60
+ ::FileUtils.rm_rf(build_dir)
59
61
  end
60
- end
61
-
62
-
63
- class SandboxBuild < Build
64
- def execute
65
- build_image
66
- push
67
- end
68
-
69
- private
70
62
 
71
- def build_image
72
- shell("docker build -t #{repo_name}:#{version_tag} .") do |status|
73
- fail "couldn't build Docker image"
74
- end
63
+ def repo_name
64
+ ::Phase.config.deploy.docker_repository
75
65
  end
76
66
 
77
- def push
78
- shell("docker push #{repo_name}:#{version_tag}") do |status|
79
- fail "couldn't push #{repo_name}:#{version_tag}"
80
- end
67
+ def set_file_modification_timestamps
68
+
81
69
  end
82
70
  end
83
71
 
@@ -2,42 +2,27 @@ module Phase
2
2
  module Deploy
3
3
 
4
4
  class Deployment
5
- attr_reader :options, :build
5
+ attr_reader :options#, :build
6
6
 
7
7
  def initialize(options = {})
8
8
  @options = options
9
9
  end
10
10
 
11
- def build
12
- @build ||= Build.new(options[:version_tag])
13
- end
11
+ # def build
12
+ # @build ||= Build.new(options[:version_tag])
13
+ # end
14
14
 
15
15
  def execute!
16
- build.execute!
16
+ # build.execute!
17
17
  deploy_image
18
18
  end
19
19
 
20
20
  private
21
21
 
22
22
  def deploy_image
23
- system("")
23
+ system("echo yaaaay")
24
24
  end
25
25
  end
26
26
 
27
-
28
- class SandboxDeployment < Deployment
29
- def build
30
- @build ||= SandboxBuild.new(options[:version_tag])
31
- end
32
- end
33
-
34
-
35
- class StagingDeployment < Deployment
36
- end
37
-
38
-
39
- class ProductionDeployment < Deployment
40
- end
41
-
42
27
  end
43
28
  end
@@ -7,6 +7,7 @@ module Phase
7
7
  end
8
8
 
9
9
  def fail(str)
10
+ puts
10
11
  abort "[phase]".red + " #{ str }"
11
12
  end
12
13
 
data/lib/phase/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Phase
2
- VERSION = "0.0.15"
2
+ VERSION = "0.0.16"
3
3
  end
data/lib/phase.rb CHANGED
@@ -29,6 +29,9 @@ require 'phase/kit/ssh/command'
29
29
  require 'phase/kit/ssh/runners'
30
30
 
31
31
  require 'phase/configuration'
32
+ require 'phase/config/deploy'
33
+ require 'phase/config/ipa'
34
+
32
35
  require 'phase/version'
33
36
 
34
37
 
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.15
4
+ version: 0.0.16
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-13 00:00:00.000000000 Z
12
+ date: 2015-05-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: commander
@@ -209,6 +209,7 @@ files:
209
209
  - lib/phase/adapters/aws/subnet.rb
210
210
  - lib/phase/cli.rb
211
211
  - lib/phase/cli/all.rb
212
+ - lib/phase/cli/build.rb
212
213
  - lib/phase/cli/command.rb
213
214
  - lib/phase/cli/deploy.rb
214
215
  - lib/phase/cli/env.rb
@@ -218,6 +219,8 @@ files:
218
219
  - lib/phase/cli/mosh.rb
219
220
  - lib/phase/cli/ssh.rb
220
221
  - lib/phase/cli/status.rb
222
+ - lib/phase/config/deploy.rb
223
+ - lib/phase/config/ipa.rb
221
224
  - lib/phase/configuration.rb
222
225
  - lib/phase/dsl.rb
223
226
  - lib/phase/kit/deploy/build.rb
@@ -265,3 +268,4 @@ summary: A simple way to manage cloud instances within a multi-subnet network, l
265
268
  test_files:
266
269
  - spec/dsl_spec.rb
267
270
  - spec/spec_helper.rb
271
+ has_rdoc: