phase 1.0.0.rc1 → 1.0.0.rc2
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 +4 -4
- data/lib/phase/cli/deploy.rb +14 -14
- data/lib/phase/config/deploy.rb +6 -0
- data/lib/phase/configuration.rb +1 -1
- data/lib/phase/kit/deploy/build.rb +2 -2
- data/lib/phase/kit/deploy/deployment.rb +43 -11
- data/lib/phase/util/shell.rb +1 -1
- data/lib/phase/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d23b4d3bd81128770584534b887898b10ca94dd3
|
4
|
+
data.tar.gz: 116bd3d5c7348e2bf1348fec4e6081f82d3f8748
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed13ea799acffc32bf3ac1cb7932bf1fc61034904378eb54b0a419171043dbeb73a8e2832708e573e22623137c49b92c80a4ec3c44422d2ee0b7087003d5c960
|
7
|
+
data.tar.gz: 2afba04a8973a9eb24488aa4db781ae09ade8ab6fb92c2b21c9dd91e313715768cb0dc9307306719aa999d4ad2131af4b1ac0b9b0f285cb26e0ece314a562b8c
|
data/lib/phase/cli/deploy.rb
CHANGED
@@ -3,37 +3,37 @@ module Phase
|
|
3
3
|
class Deploy < Command
|
4
4
|
|
5
5
|
command :deploy do |c|
|
6
|
-
c.syntax = "phase deploy <
|
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 <
|
10
|
-
|
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 :
|
23
|
+
attr_reader :instance_role
|
19
24
|
|
20
25
|
def initialize(args, options)
|
21
26
|
super
|
22
27
|
|
23
|
-
fail "
|
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 ==
|
34
|
-
fail "unknown 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(
|
36
|
+
deployment = ::Phase::Deploy::Deployment.new(instance_role, options.number)
|
37
37
|
deployment.execute!
|
38
38
|
end
|
39
39
|
|
data/lib/phase/config/deploy.rb
CHANGED
@@ -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"
|
data/lib/phase/configuration.rb
CHANGED
@@ -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
|
-
|
5
|
+
include ::Phase::Util::Console
|
6
|
+
include ::Phase::Util::Shell
|
6
7
|
|
7
|
-
|
8
|
-
@options = options
|
9
|
-
end
|
8
|
+
attr_reader :role_name, :version_tag, :options
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
|
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
|
-
|
17
|
-
|
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
|
-
|
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
|
|
data/lib/phase/util/shell.rb
CHANGED
data/lib/phase/version.rb
CHANGED
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.
|
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-
|
12
|
+
date: 2015-06-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: commander
|