easy_eb 0.1.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +1 -1
- data/lib/easy_eb/cli.rb +14 -5
- data/lib/easy_eb/dns.rb +53 -0
- data/lib/easy_eb/environment.rb +5 -4
- data/lib/easy_eb/ssh.rb +4 -2
- data/lib/easy_eb/version.rb +1 -1
- data/lib/easy_eb.rb +1 -0
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de397e90eac0d556add92272f97f6a114bc7e672969965ba3bf1b01bd043f928
|
4
|
+
data.tar.gz: dbfb95e0c53d3e3cf9186eae8c1ce3c771d75307ebbfee00e7084e0ce46a52c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c3f9969320c8983f85f28361122d96eb07fc3539be7e98b7f1ee5e060774cde047958b02eae06e8a7cf81af68ea23a9f7067a9f7864fa419a9ebde37e1d0a56
|
7
|
+
data.tar.gz: 3d60ad3a820cb8564c806ace141bf5ea4cdc670a4043a9618cb62290935a9d0ca4f2ad22ffddeb59259b4d3f37c8c1fba200c37e11f9a234adb4cb20534079d7
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -34,7 +34,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
34
34
|
|
35
35
|
## Contributing
|
36
36
|
|
37
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
37
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/Ungerware/easy_eb. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/pingortle/easy_eb/blob/master/CODE_OF_CONDUCT.md).
|
38
38
|
|
39
39
|
## License
|
40
40
|
|
data/lib/easy_eb/cli.rb
CHANGED
@@ -4,22 +4,31 @@ module EasyEb
|
|
4
4
|
class CLI < Thor
|
5
5
|
desc "create-environment TARGET [--slug SLUG]", "Creates an EB environment for the target stack (e.g. staging or production) with a unique slug appended"
|
6
6
|
option :slug, type: :string
|
7
|
+
option :region, type: :string
|
7
8
|
def create_environment(target)
|
8
9
|
EasyEb::Environment.create!(target: target, **options.transform_keys(&:to_sym))
|
9
10
|
end
|
10
11
|
|
12
|
+
desc "dns ENVIRONMENT DOMAIN", "Updates or creates a DNS record to point at the specified environment"
|
13
|
+
option :slug, type: :string
|
14
|
+
option :region, type: :string
|
15
|
+
def dns(environment, domain)
|
16
|
+
EasyEb::Dns.create!(environment: environment, domain: domain, **options.transform_keys(&:to_sym))
|
17
|
+
end
|
18
|
+
|
19
|
+
desc "install", "Install essential eb helpers to be checked into your repo"
|
20
|
+
def install
|
21
|
+
EasyEb::Generators::Install.start
|
22
|
+
end
|
23
|
+
|
11
24
|
desc "ssh [--environment ENVIRONMENT] [COMMAND]", "Intelligent ssh for elastic beanstalk"
|
12
25
|
option :environment, type: :string
|
26
|
+
option :region, type: :string
|
13
27
|
option :ssh, type: :string
|
14
28
|
option :eb_flags, type: :string
|
15
29
|
option :env_command, type: :string
|
16
30
|
def ssh(*command)
|
17
31
|
EasyEb::Ssh.start!(command: command.any? ? command.join(" ") : nil, **options.transform_keys(&:to_sym))
|
18
32
|
end
|
19
|
-
|
20
|
-
desc "install", "Install essential eb helpers to be checked into your repo"
|
21
|
-
def install
|
22
|
-
EasyEb::Generators::Install.start
|
23
|
-
end
|
24
33
|
end
|
25
34
|
end
|
data/lib/easy_eb/dns.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require "json"
|
2
|
+
|
3
|
+
module EasyEb
|
4
|
+
# Data sourced from https://docs.aws.amazon.com/general/latest/gr/elasticbeanstalk.html
|
5
|
+
HOSTED_ZONES_BY_REGION = {
|
6
|
+
"us-east-1" => "Z117KPS5GTRQ2G",
|
7
|
+
"us-east-2" => "Z14LCN19Q5QHIC",
|
8
|
+
"us-west-1" => "Z1LQECGX5PH1X",
|
9
|
+
"us-west-2" => "Z38NKT9BP95V3O",
|
10
|
+
"eu-west-2" => "Z1GKAAAUGATPF1"
|
11
|
+
}
|
12
|
+
|
13
|
+
class Dns
|
14
|
+
def self.create!(environment:, domain:, region: nil)
|
15
|
+
root_domain = /(?<root>\w+\.\w+)\.?$/.match(domain)&.then { |results| results[:root] }
|
16
|
+
raise "Must supply valid domain name." unless root_domain
|
17
|
+
|
18
|
+
region_flag = region && " --region #{region}"
|
19
|
+
|
20
|
+
puts hosted_zones = JSON.parse(`aws route53 list-hosted-zones`)
|
21
|
+
hosted_zone = hosted_zones.fetch("HostedZones").find { |zone| zone.fetch("Name").start_with?(root_domain) }
|
22
|
+
hosted_zone_id = hosted_zone["Id"]
|
23
|
+
|
24
|
+
puts environments = JSON.parse(`aws#{region_flag} elasticbeanstalk describe-environments --environment-names #{environment}`)
|
25
|
+
environment_cname = environments.dig("Environments", 0, "CNAME")
|
26
|
+
environment_region = /(?<region>[1-9a-z-]+).elasticbeanstalk.com$/.match(environment_cname)[:region]
|
27
|
+
|
28
|
+
change_batch = {
|
29
|
+
Comment: "Point #{domain} to Elastic Beanstalk Environment #{environment}",
|
30
|
+
Changes: [
|
31
|
+
{
|
32
|
+
Action: :UPSERT,
|
33
|
+
ResourceRecordSet: {
|
34
|
+
Name: domain,
|
35
|
+
Type: :A,
|
36
|
+
AliasTarget: {
|
37
|
+
HostedZoneId: HOSTED_ZONES_BY_REGION[environment_region],
|
38
|
+
DNSName: environment_cname,
|
39
|
+
EvaluateTargetHealth: false
|
40
|
+
}
|
41
|
+
}
|
42
|
+
}
|
43
|
+
]
|
44
|
+
}
|
45
|
+
|
46
|
+
system(
|
47
|
+
"aws route53 change-resource-record-sets --hosted-zone-id #{hosted_zone_id} --change-batch '#{change_batch.to_json}'".tap do |command|
|
48
|
+
puts "Running… \"#{command}\""
|
49
|
+
end
|
50
|
+
)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/lib/easy_eb/environment.rb
CHANGED
@@ -5,7 +5,8 @@ module EasyEb
|
|
5
5
|
class Environment
|
6
6
|
SLUGS = JSON.parse(File.read("#{__dir__}/firstNames.json")).fetch("firstNames")
|
7
7
|
|
8
|
-
def self.create!(target:, slug: SLUGS.sample)
|
8
|
+
def self.create!(target:, region: nil, slug: SLUGS.sample)
|
9
|
+
region_flag = region && " --region #{region}"
|
9
10
|
eb_config = YAML.safe_load(File.read(".elasticbeanstalk/config.yml"))
|
10
11
|
application_name = eb_config.dig("global", "application_name")
|
11
12
|
|
@@ -17,11 +18,11 @@ module EasyEb
|
|
17
18
|
raise "Failed to create a valid Elastic Beanstalk environment with name '#{environment_name}'. Must be 40 characters or less."
|
18
19
|
end
|
19
20
|
|
20
|
-
system("eb config put #{target}", exception: true)
|
21
|
-
system("eb create #{environment_name} --cfg #{target}", exception: true)
|
21
|
+
system("eb config put #{target}#{region_flag}", exception: true)
|
22
|
+
system("eb create #{environment_name} --cfg #{target}#{region_flag}", exception: true)
|
22
23
|
|
23
24
|
puts("Success! Now you may want to run elastic beanstalk commands like this:")
|
24
|
-
puts("eb deploy #{environment_name}")
|
25
|
+
puts("eb deploy #{environment_name}#{region_flag}")
|
25
26
|
end
|
26
27
|
end
|
27
28
|
end
|
data/lib/easy_eb/ssh.rb
CHANGED
@@ -1,17 +1,19 @@
|
|
1
1
|
module EasyEb
|
2
2
|
class Ssh
|
3
|
-
def self.start!(environment: nil, command: nil, ssh: nil, eb_flags: nil, env_command: "bin/ebenv")
|
3
|
+
def self.start!(environment: nil, command: nil, ssh: nil, eb_flags: nil, env_command: "bin/ebenv", region: nil)
|
4
4
|
bash_args = command && "-c \\\"#{env_command} #{command}\\\""
|
5
5
|
tty_flag = command && "-t"
|
6
|
+
ssh_flag = ssh && "-e #{ssh}"
|
6
7
|
command_arg = [
|
7
8
|
tty_flag,
|
8
9
|
"cd /var/app/current; sudo bash -i #{bash_args}"
|
9
10
|
].compact.join(" ")
|
10
11
|
|
11
12
|
args = [
|
13
|
+
region && "--region #{region}",
|
12
14
|
eb_flags,
|
13
15
|
environment,
|
14
|
-
|
16
|
+
ssh_flag,
|
15
17
|
"--command \"#{command_arg}\""
|
16
18
|
].compact.join(" ")
|
17
19
|
|
data/lib/easy_eb/version.rb
CHANGED
data/lib/easy_eb.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: easy_eb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kaleb Lape
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-10-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -45,6 +45,7 @@ files:
|
|
45
45
|
- exe/ezeb
|
46
46
|
- lib/easy_eb.rb
|
47
47
|
- lib/easy_eb/cli.rb
|
48
|
+
- lib/easy_eb/dns.rb
|
48
49
|
- lib/easy_eb/environment.rb
|
49
50
|
- lib/easy_eb/firstNames.json
|
50
51
|
- lib/easy_eb/generators/install.rb
|
@@ -61,7 +62,7 @@ metadata:
|
|
61
62
|
homepage_uri: https://unger-ware.com
|
62
63
|
source_code_uri: https://github.com/Ungerware/easy_eb.git
|
63
64
|
changelog_uri: https://github.com/Ungerware/easy_eb/blob/master/CHANGELOG.md
|
64
|
-
post_install_message:
|
65
|
+
post_install_message:
|
65
66
|
rdoc_options: []
|
66
67
|
require_paths:
|
67
68
|
- lib
|
@@ -76,8 +77,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
76
77
|
- !ruby/object:Gem::Version
|
77
78
|
version: '0'
|
78
79
|
requirements: []
|
79
|
-
rubygems_version: 3.
|
80
|
-
signing_key:
|
80
|
+
rubygems_version: 3.1.6
|
81
|
+
signing_key:
|
81
82
|
specification_version: 4
|
82
83
|
summary: Make Elastic Beanstalk easier to work with.
|
83
84
|
test_files: []
|