phase 1.0.0.rc1 → 1.0.0.rc2

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: 9418e0cabac33009818c8d089c896b5b4cb81004
4
- data.tar.gz: b7346fdc18bcad141314d0e96247e6bb9e3aaf55
3
+ metadata.gz: d23b4d3bd81128770584534b887898b10ca94dd3
4
+ data.tar.gz: 116bd3d5c7348e2bf1348fec4e6081f82d3f8748
5
5
  SHA512:
6
- metadata.gz: 94f9716929b4f0b402104f6c9012300664dde3c1e35df93bd914aa84ed4fbd236f59534f062648a56bc768e745369ea0d3ea0fefcd8dd6aeaaa8ee7eb1860026
7
- data.tar.gz: 15248f3be2d0e843db4f9778421715204d965af8d1822113f104aea05f081c7304808f96e0d95a6d9221084aeaba267baf8a885064ba8d592b0fa89726da372f
6
+ metadata.gz: ed13ea799acffc32bf3ac1cb7932bf1fc61034904378eb54b0a419171043dbeb73a8e2832708e573e22623137c49b92c80a4ec3c44422d2ee0b7087003d5c960
7
+ data.tar.gz: 2afba04a8973a9eb24488aa4db781ae09ade8ab6fb92c2b21c9dd91e313715768cb0dc9307306719aa999d4ad2131af4b1ac0b9b0f285cb26e0ece314a562b8c
@@ -3,37 +3,37 @@ module Phase
3
3
  class Deploy < Command
4
4
 
5
5
  command :deploy do |c|
6
- c.syntax = "phase deploy <environment_name> <version_number>"
6
+ c.syntax = "phase deploy <instance_role> [-n version_number]"
7
+
8
+ c.option "-n", "--number", String, "Specific version number to deploy."
7
9
 
8
10
  c.description = <<-EOS.strip_heredoc
9
- Builds and deploys code to the specified <environment_name>, which may be
10
- any environment configured in the Phasefile.
11
+ Builds and deploys code to instance with the specified <instance_role> in their
12
+ "Role" tags. Deploys the current version (in the file set via
13
+ `config.deploy.version_lockfile`) unless an alternate version is provided with the
14
+ -n option.
11
15
  EOS
12
16
 
13
17
  c.action do |args, options|
18
+ options.default(number: ::Phase::Deploy::Version.current)
14
19
  new(args, options).run
15
20
  end
16
21
  end
17
22
 
18
- attr_reader :env_name, :version_number
23
+ attr_reader :instance_role
19
24
 
20
25
  def initialize(args, options)
21
26
  super
22
27
 
23
- fail "must specify both environment and version number" unless args.count >= 2
24
-
25
- @env_name = args[0]
26
- @version_number = args[1]
27
-
28
- fail "must specify environment" unless env_name
29
- fail "must specify version number" unless version_number
28
+ fail "Must specify 'instance_role' name" if args.first.blank?
29
+ @instance_role = args.first
30
30
  end
31
31
 
32
32
  def run
33
- environment = config.deploy.environments.find { |e| e.name == env_name }
34
- fail "unknown environment: '#{env_name}'" unless environment
33
+ # environment = config.deploy.environments.find { |e| e.name == instance_role }
34
+ # fail "unknown environment: '#{instance_role}'" unless environment
35
35
 
36
- deployment = Deploy::Deployment.new(environment, version_tag: version_number)
36
+ deployment = ::Phase::Deploy::Deployment.new(instance_role, options.number)
37
37
  deployment.execute!
38
38
  end
39
39
 
@@ -25,6 +25,12 @@ module Phase
25
25
  attr_accessor :asset_bucket
26
26
 
27
27
 
28
+ # @return [String] any options or switches to be passed to the Docker daemon at runtime
29
+ # @example Sample settings
30
+ # config.deploy.docker_repository = "-v /dir:/dir -e VAR=value --env-file=.environment"
31
+ attr_accessor :docker_run_flags
32
+
33
+
28
34
  def initialize
29
35
  @environments = []
30
36
  @version_lockfile = "VERSION"
@@ -13,7 +13,7 @@ module Phase
13
13
  @aws_region = "us-east-1"
14
14
  @adapter = ::Phase::Adapters::AWS
15
15
 
16
- self.backend = ::Phase::SSH::Backend
16
+ # self.backend = ::Phase::SSH::Backend
17
17
  set_aws_credentials!
18
18
  end
19
19
 
@@ -80,7 +80,7 @@ module Phase
80
80
  # directory rather than building in a clean, committed environment. This could lead
81
81
  # to errors in the compiled assets.
82
82
  def precompile_assets
83
- shell("RAILS_GROUPS=assets rake assets:precompile") do |status|
83
+ shell("RAILS_GROUPS=assets RAILS_ENV=production rake assets:precompile") do |status|
84
84
  fail "Couldn't precompile assets"
85
85
  end
86
86
  end
@@ -94,7 +94,7 @@ module Phase
94
94
  # This needs to run *before* the version gets updated so we know which version
95
95
  # number to pull from the registry.
96
96
  def pull_latest_build
97
- shell("docker pull #{docker_repo}:#{::Phase::Deploy::Version.current}")
97
+ shell("docker pull #{docker_repo}:#{::Phase::Deploy::Version.current}", allow_failure: true)
98
98
  end
99
99
 
100
100
  def push
@@ -2,25 +2,57 @@ module Phase
2
2
  module Deploy
3
3
 
4
4
  class Deployment
5
- attr_reader :options#, :build
5
+ include ::Phase::Util::Console
6
+ include ::Phase::Util::Shell
6
7
 
7
- def initialize(options = {})
8
- @options = options
9
- end
8
+ attr_reader :role_name, :version_tag, :options
10
9
 
11
- # def build
12
- # @build ||= Build.new(options[:version_tag])
13
- # end
10
+ def initialize(role_name, version_tag, options = {})
11
+ @role_name, @version_tag, @options = role_name, version_tag, options
12
+ end
14
13
 
15
14
  def execute!
16
- # build.execute!
17
- deploy_image
15
+ hosts = ::Phase::Adapters::AWS::Server.where(role: role_name).map do |host|
16
+ "deploy@#{host.resource.dns_name}"
17
+ end
18
+
19
+ fail "No instance with role `role_name' found" if hosts.blank?
20
+
21
+ deploy_image(hosts)
18
22
  end
19
23
 
20
24
  private
21
25
 
22
- def deploy_image
23
- system("echo yaaaay")
26
+ def deploy_image(hosts, options = {})
27
+ image_name = docker_image_name
28
+ server_count = 2 # FIXME: make this a config var
29
+ run_flags = docker_run_flags
30
+
31
+ ::SSHKit::Coordinator.new(hosts).each(options) do
32
+ execute(:docker, :pull, image_name)
33
+
34
+ # TODO: fail if pending migrations
35
+ execute(:docker, :run, run_flags, "--rm -it", image_name,
36
+ "bundle exec rails runner '::ActiveRecord::Migrator.needs_migration? ? exit(1) : exit(0)'")
37
+
38
+ server_count.times do |i|
39
+ server_name = "server-#{i}"
40
+ port_number = 3000 + i # FIXME: make this a config var
41
+
42
+ execute(:docker, :stop, server_name, raise_on_non_zero_exit: false)
43
+ execute(:docker, :rm, server_name, raise_on_non_zero_exit: false)
44
+
45
+ execute(:docker, :run, run_flags, "-p #{port_number}:3000 -d", image_name)
46
+ end
47
+ end
48
+ end
49
+
50
+ def docker_image_name
51
+ @docker_image ||= "#{::Phase.config.deploy.docker_repository}:#{version_tag}"
52
+ end
53
+
54
+ def docker_run_flags
55
+ @docker_run_flags ||= ::Phase.config.deploy.docker_run_flags
24
56
  end
25
57
  end
26
58
 
@@ -5,7 +5,7 @@ module Phase
5
5
 
6
6
  def shell(*args)
7
7
  options = args.extract_options!
8
- options.reverse_merge({
8
+ options.reverse_merge!({
9
9
  allow_failure: false
10
10
  })
11
11
 
data/lib/phase/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Phase
2
- VERSION = "1.0.0.rc1"
2
+ VERSION = "1.0.0.rc2"
3
3
  end
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: 1.0.0.rc1
4
+ version: 1.0.0.rc2
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-06-18 00:00:00.000000000 Z
12
+ date: 2015-06-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: commander