beanstalk_deploy 1.0.1 → 1.1.0
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/beanstalk.rb +102 -34
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5257886b242aa673988f08bb0c207666dcf4d40b
|
4
|
+
data.tar.gz: aef91f014e24a88b4442396ff236270f2023034b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9249e09aa5f2e6655ab928a50f536196230815dee7101326b75195ce9436167a0b025cdc575c58834f3f202889d683871e8a5a066a29111b230834e9f4f0768e
|
7
|
+
data.tar.gz: 8d76aaeaddbc7e46f7a7da62e79c50bd597ccf6088a8f096f95960f843c96c80ad34f28f172d70dcb4ac1729d7d972e963c4812be30e8a8da17cef5f50727af8
|
data/lib/beanstalk.rb
CHANGED
@@ -9,6 +9,7 @@ module Beanstalk
|
|
9
9
|
option :source_dir, :aliases => "-s", :default => './src'
|
10
10
|
option :profile, :aliases => "-p", :default => 'web-services'
|
11
11
|
option :region, :aliases => "-r", :default => 'eu-west-1'
|
12
|
+
option :tags, :aliases => "-t", :type => :hash
|
12
13
|
|
13
14
|
def deploy
|
14
15
|
|
@@ -17,53 +18,120 @@ module Beanstalk
|
|
17
18
|
source_dir = options[:source_dir]
|
18
19
|
profile_name = options[:profile]
|
19
20
|
region = options[:region]
|
21
|
+
tags = options[:tags]
|
22
|
+
|
23
|
+
# Authenticates the user & sets up a new ElasticBeanstalk client
|
24
|
+
authenticate_user(profile_name, region)
|
25
|
+
|
26
|
+
# Checks if the application exists & creates a new one if it doest
|
27
|
+
app = check_applications(app_name)
|
28
|
+
|
29
|
+
# Check if the environment exists then creates or deploys application as appropriate
|
30
|
+
deploy_environment(app_name, env_name, source_dir, tags)
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
no_commands {
|
35
|
+
# Authenticates the user & sets up a new ElasticBeanstalk client.
|
36
|
+
#
|
37
|
+
# ==== Parameters
|
38
|
+
# profile_name<String>:: Name of the profile to use for authentication
|
39
|
+
# region<String>:: Name of the AWS region to authenticate against
|
40
|
+
def authenticate_user(profile_name, region)
|
41
|
+
|
42
|
+
if !ENV['AWS_ACCESS_KEY_ID'].nil? || !ENV['AWS_SECRET_ACCESS_KEY'].nil?
|
43
|
+
puts 'Using environment variables for authentication '
|
44
|
+
creds = Aws::Credentials.new(ENV['AWS_ACCESS_KEY_ID'], ENV['AWS_SECRET_ACCESS_KEY'], session_token = nil)
|
45
|
+
else
|
46
|
+
puts 'Using profile for authentication'
|
47
|
+
creds = Aws::SharedCredentials.new(profile_name: profile_name)
|
48
|
+
end
|
49
|
+
|
50
|
+
puts 'Setting up ElasticBeanstalk client'
|
51
|
+
@eb = Aws::ElasticBeanstalk::Client.new(region: region, credentials: creds)
|
52
|
+
puts 'ElasticBeanstalk client setup complete'
|
20
53
|
|
21
|
-
if !ENV['AWS_ACCESS_KEY_ID'].nil? || !ENV['AWS_SECRET_ACCESS_KEY'].nil?
|
22
|
-
puts 'Using environment variables for authentication '
|
23
|
-
creds = Aws::Credentials.new(ENV['AWS_ACCESS_KEY_ID'], ENV['AWS_SECRET_ACCESS_KEY'], session_token = nil)
|
24
|
-
else
|
25
|
-
puts 'Using profile for authentication'
|
26
|
-
creds = Aws::SharedCredentials.new(profile_name: profile_name)
|
27
54
|
end
|
55
|
+
}
|
28
56
|
|
29
|
-
|
30
|
-
|
31
|
-
|
57
|
+
no_commands {
|
58
|
+
# Checks if the application exists & creates a new one if it doest.
|
59
|
+
#
|
60
|
+
# ==== Parameters
|
61
|
+
# app_name<String>:: Name of the application to be used
|
62
|
+
def check_applications(app_name)
|
63
|
+
puts 'Checking applications'
|
64
|
+
apps = @eb.describe_applications({
|
65
|
+
application_names: ["#{app_name}"]
|
66
|
+
})
|
32
67
|
|
33
|
-
|
34
|
-
|
35
|
-
|
68
|
+
if apps.applications.empty?
|
69
|
+
puts "Application does not exist, creating #{app_name}."
|
70
|
+
app =@eb.create_application({
|
71
|
+
application_name: "#{app_name}",
|
72
|
+
description: "#{app_name}"
|
36
73
|
})
|
74
|
+
puts 'Application creating completed'
|
75
|
+
end
|
37
76
|
|
38
|
-
if apps.applications.empty?
|
39
|
-
puts "Application does not exist, creating #{app_name}."
|
40
|
-
app = eb.create_application({
|
41
|
-
application_name: "#{app_name}",
|
42
|
-
description: "#{app_name}"
|
43
|
-
})
|
44
|
-
puts 'Application creating completed'
|
45
77
|
end
|
78
|
+
}
|
46
79
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
80
|
+
no_commands {
|
81
|
+
# Check if the environment exists then creates or deploys application as appropriate.
|
82
|
+
#
|
83
|
+
# ==== Parameters
|
84
|
+
# eb<Class>:: ElasticBeanstalk client
|
85
|
+
# app_name<String>:: Name of the application to be used
|
86
|
+
# env_name<String>:: Name of the environment to be used
|
87
|
+
# source_dir<String>:: Name of the environment to be used
|
88
|
+
# tags<Hash>:: Hash of tags to be added to environment
|
89
|
+
def deploy_environment(app_name, env_name, source_dir, tags)
|
90
|
+
puts 'Describing environments '
|
91
|
+
envs = @eb.describe_environments({
|
92
|
+
environment_names: ["#{env_name}"]
|
93
|
+
})
|
51
94
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
95
|
+
environment_available = false
|
96
|
+
envs.environments.each do |environemt|
|
97
|
+
if environemt.status != 'Terminated'
|
98
|
+
environment_available = true
|
99
|
+
end
|
56
100
|
end
|
101
|
+
|
102
|
+
if (envs.environments.empty?) or (!environment_available)
|
103
|
+
puts "CreateEnvironment is starting for #{env_name}."
|
104
|
+
system ("cd #{source_dir} && eb create #{env_name} --timeout 60") or raise "Something went wrong, check your source directory is correct."
|
105
|
+
# Tag the environment
|
106
|
+
unless tags.nil?
|
107
|
+
tag_environment(app_name, env_name, tags)
|
108
|
+
end
|
109
|
+
else
|
110
|
+
puts "Updating #{env_name}."
|
111
|
+
system ("cd #{source_dir} && eb deploy #{env_name}") or raise "Something went wrong, check your source directory is correct."
|
112
|
+
end
|
113
|
+
|
57
114
|
end
|
115
|
+
}
|
116
|
+
|
117
|
+
no_commands {
|
118
|
+
# Check if the environment exists then creates or deploys application as appropriate.
|
119
|
+
# Only called if the environment is being created.
|
120
|
+
#
|
121
|
+
# ==== Parameters
|
122
|
+
# app_name<String>:: Name of the application to be used
|
123
|
+
# env_name<String>:: Name of the environment to be used
|
124
|
+
# tags<Hash>:: Hash of tags to be added to environment
|
125
|
+
def tag_environment(app_name, env_name, tags)
|
126
|
+
|
127
|
+
puts "Tagging #{env_name}."
|
128
|
+
tags.each do |key, value|
|
129
|
+
puts "Adding #{key.to_s}=#{value.to_s}"
|
130
|
+
system "eb tags #{app_name}-#{env_name} -a #{key.to_s}=#{value.to_s}"
|
131
|
+
end
|
58
132
|
|
59
|
-
if (envs.environments.empty?) or (!environment_available)
|
60
|
-
puts "CreateEnvironment is starting for #{env_name}."
|
61
|
-
system "cd #{source_dir} && eb create #{env_name} --timeout 60"
|
62
|
-
else
|
63
|
-
puts "Updating #{env_name}."
|
64
|
-
system "cd #{source_dir} && eb deploy #{env_name}"
|
65
133
|
end
|
134
|
+
}
|
66
135
|
|
67
|
-
end
|
68
136
|
end
|
69
137
|
end
|