shiprails 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/shiprails/ship/config.rb +4 -0
- data/lib/shiprails/ship/deploy.rb +9 -3
- data/lib/shiprails/ship/exec.rb +3 -14
- data/lib/shiprails/ship/install/shiprails.yml.erb +1 -0
- data/lib/shiprails/ship/install.rb +5 -0
- data/lib/shiprails/ship/setup.rb +8 -5
- data/lib/shiprails/ship.rb +2 -2
- data/lib/shiprails/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: 48924907329f2d0287023689d913f38e94020b7b
|
4
|
+
data.tar.gz: a2f84d51b8751d5125958fb9d741a4c7cd6ec9ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 291e29842b74feaa4c88024249dd0f132d1b8d07e9ebab9e4b4bd9ed8713eae261e125853d34e3ad749be401b3cd50accaecc17341c5afeb163aeeee2dc8f102
|
7
|
+
data.tar.gz: 7b1cee9f15ff1b725bb0bd759f233d624e815899f21c7d419101722ccc01fe94a86ae956283a6cde76baadffa3e3e950cb446b9321854fab3815cef44a5f04cc
|
@@ -21,12 +21,14 @@ module Shiprails
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def update_ecs_tasks
|
24
|
+
environment = args.second
|
24
25
|
return unless @version
|
25
26
|
say "Updating config version for ECS tasks..."
|
26
27
|
configuration[:services].each do |service_name, service|
|
27
28
|
service[:regions].each do |region_name, region|
|
28
29
|
ecs = Aws::ECS::Client.new(region: region_name.to_s)
|
29
30
|
region[:environments].each do |environment_name|
|
31
|
+
next unless environment == environment_name
|
30
32
|
cluster_name = "#{project_name}_#{environment_name}"
|
31
33
|
task_name = "#{project_name}_#{service_name}_#{environment_name}"
|
32
34
|
begin
|
@@ -56,12 +58,14 @@ module Shiprails
|
|
56
58
|
end
|
57
59
|
|
58
60
|
def update_ecs_services
|
61
|
+
environment = args.second
|
59
62
|
return unless @version
|
60
63
|
say "Updating ECS services..."
|
61
64
|
configuration[:services].each do |service_name, service|
|
62
65
|
service[:regions].each do |region_name, region|
|
63
66
|
ecs = Aws::ECS::Client.new(region: region_name.to_s)
|
64
67
|
region[:environments].each do |environment_name|
|
68
|
+
next unless environment == environment_name
|
65
69
|
cluster_name = "#{project_name}_#{environment_name}"
|
66
70
|
task_name = "#{project_name}_#{service_name}_#{environment_name}"
|
67
71
|
begin
|
@@ -16,7 +16,7 @@ module Shiprails
|
|
16
16
|
def check_git_status
|
17
17
|
if git.status.added.any? or git.status.changed.any? or git.status.deleted.any?
|
18
18
|
say "You have uncommitted changes. Commit and try again.", :red
|
19
|
-
exit
|
19
|
+
# exit # TESTING
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
@@ -29,9 +29,10 @@ module Shiprails
|
|
29
29
|
service[:regions].each do |region_name, region|
|
30
30
|
aws_region = region_name.to_s
|
31
31
|
region[:environments].each do |environment_name|
|
32
|
+
next unless args.empty? or args.include?(environment_name)
|
32
33
|
result = `S3_CONFIG_BUCKET=#{s3_config_bucket} bundle exec config list #{environment_name}`
|
33
34
|
s3_config_revision = result.match(/#{environment_name} \(v([0-9]+)\)/)[1] rescue 0
|
34
|
-
commands << "docker build -t #{image_name} --build-arg AWS_ACCESS_KEY_ID='#{aws_access_key_id}' --build-arg AWS_SECRET_ACCESS_KEY='#{aws_access_key_secret}' --build-arg AWS_REGION='#{aws_region}' --build-arg S3_CONFIG_BUCKET='#{s3_config_bucket}' --build-arg S3_CONFIG_REVISION='#{s3_config_revision}' -f Dockerfile.production ."
|
35
|
+
commands << "docker build -t #{image_name}_#{environment_name} --build-arg AWS_ACCESS_KEY_ID='#{aws_access_key_id}' --build-arg AWS_SECRET_ACCESS_KEY='#{aws_access_key_secret}' --build-arg AWS_REGION='#{aws_region}' --build-arg S3_CONFIG_BUCKET='#{s3_config_bucket}' --build-arg S3_CONFIG_REVISION='#{s3_config_revision}' -f Dockerfile.production ."
|
35
36
|
end
|
36
37
|
end
|
37
38
|
end
|
@@ -47,7 +48,10 @@ module Shiprails
|
|
47
48
|
image_name = "#{compose_project_name}_#{service[:image]}"
|
48
49
|
service[:regions].each do |region_name, region|
|
49
50
|
repository_url = region[:repository_url]
|
50
|
-
|
51
|
+
region[:environments].each do |environment_name|
|
52
|
+
next unless args.empty? or args.include?(environment_name)
|
53
|
+
commands << "docker tag #{image_name}_#{environment_name} #{repository_url}:#{git_sha}"
|
54
|
+
end
|
51
55
|
end
|
52
56
|
end
|
53
57
|
commands.uniq!
|
@@ -77,6 +81,7 @@ module Shiprails
|
|
77
81
|
service[:regions].each do |region_name, region|
|
78
82
|
ecs = Aws::ECS::Client.new(region: region_name.to_s)
|
79
83
|
region[:environments].each do |environment_name|
|
84
|
+
next unless args.empty? or args.include?(environment_name)
|
80
85
|
cluster_name = "#{project_name}_#{environment_name}"
|
81
86
|
task_name = "#{project_name}_#{service_name}_#{environment_name}"
|
82
87
|
image_name = "#{region[:repository_url]}:#{git_sha}"
|
@@ -120,6 +125,7 @@ module Shiprails
|
|
120
125
|
service[:regions].each do |region_name, region|
|
121
126
|
ecs = Aws::ECS::Client.new(region: region_name.to_s)
|
122
127
|
region[:environments].each do |environment_name|
|
128
|
+
next unless args.empty? or args.include?(environment_name)
|
123
129
|
cluster_name = "#{project_name}_#{environment_name}"
|
124
130
|
task_name = "#{project_name}_#{service_name}_#{environment_name}"
|
125
131
|
begin
|
data/lib/shiprails/ship/exec.rb
CHANGED
@@ -20,7 +20,7 @@ module Shiprails
|
|
20
20
|
default: "app",
|
21
21
|
desc: "Specify the service name"
|
22
22
|
class_option "private-key",
|
23
|
-
default: "
|
23
|
+
default: "shiprails.pem",
|
24
24
|
desc: "Specify the AWS SSH private key path"
|
25
25
|
|
26
26
|
def run_command
|
@@ -74,13 +74,6 @@ module Shiprails
|
|
74
74
|
# get its current security groups to restory later
|
75
75
|
security_group_ids = ec2_instance.security_groups.map(&:group_id)
|
76
76
|
|
77
|
-
# create new public ip
|
78
|
-
elastic_ip = ec2.allocate_address({ domain: "vpc" })
|
79
|
-
# link ip to ec2 instance
|
80
|
-
associate_address_response = ec2.associate_address({
|
81
|
-
allocation_id: elastic_ip.allocation_id,
|
82
|
-
instance_id: ec2_instance_id
|
83
|
-
})
|
84
77
|
# create security group for us
|
85
78
|
security_group_response = ec2.create_security_group({
|
86
79
|
group_name: "shiprails-exec-#{cluster}-#{Time.now.to_i}",
|
@@ -114,9 +107,9 @@ module Shiprails
|
|
114
107
|
|
115
108
|
say "Waiting for AWS to setup networking..."
|
116
109
|
sleep 5 # AWS just needs a little bit to setup networking
|
117
|
-
say "Connecting #{ssh_user}@#{
|
110
|
+
say "Connecting #{ssh_user}@#{ec2_instance.public_ip_address}..."
|
118
111
|
say "Executing: $ #{command_string}"
|
119
|
-
system "ssh -o ConnectTimeout=15 -o 'StrictHostKeyChecking no' -t -i #{ssh_private_key_path} #{ssh_user}@#{
|
112
|
+
system "ssh -o ConnectTimeout=15 -o 'StrictHostKeyChecking no' -t -i #{ssh_private_key_path} #{ssh_user}@#{ec2_instance.public_ip_address} '#{command_string}'"
|
120
113
|
rescue => e
|
121
114
|
say "Error: #{e.message}", :red
|
122
115
|
ensure
|
@@ -128,10 +121,6 @@ module Shiprails
|
|
128
121
|
}) rescue nil
|
129
122
|
# remove our access security group
|
130
123
|
ec2.delete_security_group({ group_id: security_group_response.group_id }) rescue nil
|
131
|
-
# unlink ec2 instance from public ip
|
132
|
-
ec2.disassociate_address({ association_id: associate_address_response.association_id }) rescue nil
|
133
|
-
# release public ip address
|
134
|
-
ec2.release_address({ allocation_id: elastic_ip.allocation_id }) rescue nil
|
135
124
|
say "Done.", :green
|
136
125
|
end
|
137
126
|
|
@@ -47,6 +47,10 @@ module Shiprails
|
|
47
47
|
@bucket_name = bucket_name
|
48
48
|
end
|
49
49
|
|
50
|
+
def ec2_ssh_private_key_path
|
51
|
+
@ec2_ssh_private_key_path ||= ask "Where is your AWS EC2 SSH private key?", default: 'shiprails.pem'
|
52
|
+
end
|
53
|
+
|
50
54
|
def environments
|
51
55
|
environments = Dir.entries("#{Dir.getwd}/config/environments").grep(/\.rb$/).map { |fname| fname.chomp!(".rb") }.select{ |e| !['development', 'test'].include? e } rescue ['production']
|
52
56
|
environments ||= ['production']
|
@@ -122,6 +126,7 @@ module Shiprails
|
|
122
126
|
|
123
127
|
# Ignore Docker ENV
|
124
128
|
/.env
|
129
|
+
/shiprails.pem
|
125
130
|
EOF
|
126
131
|
end
|
127
132
|
end
|
data/lib/shiprails/ship/setup.rb
CHANGED
@@ -22,7 +22,10 @@ module Shiprails
|
|
22
22
|
region[:environments].each do |environment_name|
|
23
23
|
cluster_name = "#{project_name}_#{environment_name}"
|
24
24
|
unless created_groups.include? cluster_name
|
25
|
-
|
25
|
+
begin
|
26
|
+
client.create_log_group({ log_group_name: cluster_name })
|
27
|
+
rescue Aws::CloudWatchLogs::Errors::ResourceAlreadyExistsException => err
|
28
|
+
end
|
26
29
|
say "Created #{cluster_name} log group."
|
27
30
|
created_groups << cluster_name
|
28
31
|
end
|
@@ -53,7 +56,7 @@ module Shiprails
|
|
53
56
|
task_definition = {
|
54
57
|
container_definitions: [
|
55
58
|
{
|
56
|
-
command: service[:command],
|
59
|
+
command: [service[:command]],
|
57
60
|
cpu: service[:resources][:cpu_units],
|
58
61
|
essential: true,
|
59
62
|
environment: [
|
@@ -66,9 +69,9 @@ module Shiprails
|
|
66
69
|
log_configuration: {
|
67
70
|
log_driver: "awslogs",
|
68
71
|
options: {
|
69
|
-
"
|
72
|
+
"awslogs-group" => cluster_name,
|
70
73
|
"awslogs-region" => region_name.to_s,
|
71
|
-
"awslogs-stream-prefix" =>
|
74
|
+
"awslogs-stream-prefix" => service_name
|
72
75
|
}
|
73
76
|
},
|
74
77
|
memory: service[:resources][:memory_units],
|
@@ -149,7 +152,7 @@ module Shiprails
|
|
149
152
|
task_definition: task_definition_response.task_definition.task_definition_arn
|
150
153
|
}
|
151
154
|
(service[:ports] || []).each do |port|
|
152
|
-
if yes? "Should port #{port} for #{image_name} be load balanced?"
|
155
|
+
if yes? "Should port #{port} for #{image_name} be load balanced in #{environment_name}?"
|
153
156
|
ecs_service[:role] = "ecsServiceRole"
|
154
157
|
load_balancers = elb.describe_load_balancers.to_h
|
155
158
|
say "EC2 Load Balancers"
|
data/lib/shiprails/ship.rb
CHANGED
data/lib/shiprails/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shiprails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zane Shannon
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-04-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|