firespring_dev_commands 1.4.2.pre.alpha.1 → 1.4.3.pre.alpha.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/firespring_dev_commands/aws/account.rb +9 -4
- data/lib/firespring_dev_commands/aws/credentials.rb +0 -5
- data/lib/firespring_dev_commands/aws/login.rb +16 -6
- data/lib/firespring_dev_commands/aws/profile.rb +1 -12
- data/lib/firespring_dev_commands/templates/aws.rb +0 -14
- data/lib/firespring_dev_commands/templates/base_interface.rb +3 -17
- data/lib/firespring_dev_commands/templates/docker/application.rb +1 -20
- data/lib/firespring_dev_commands/templates/docker/default.rb +0 -24
- data/lib/firespring_dev_commands/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb403fd1ae12470807a778fbb3314f74b80a5f7d7c8fe0cf1ac28bab1d56d837
|
4
|
+
data.tar.gz: ff65c1e27fe4f4d63f3d31f5817b552d5dd4c930b615fadb0403e178e30fa597
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 864a3659c6164459f8623f55e9d995cf77c09d03da85fe23c1b6e9f45e7dde3fe0982891b6e662b0b3942695a12f98d4ba4abe71eb3131e3f9898fa5afa146bd
|
7
|
+
data.tar.gz: 323ed9adeba33220e791ef078c0e3c4390ed93cdc262b3c3aa18e9b103099bf2f57e727e1b1e412773f3c54cd734fda8b1304953b5bdc2bd1350ba4fdf7a58a4
|
@@ -3,7 +3,7 @@ module Dev
|
|
3
3
|
# Class containing useful methods for interacting with the Aws account
|
4
4
|
class Account
|
5
5
|
# Config object for setting top level Aws account config options
|
6
|
-
Config = Struct.new(:root, :children, :default, :registry)
|
6
|
+
Config = Struct.new(:root, :children, :default, :registry, :ecr_registry_ids, :login_to_account_ecr_registry)
|
7
7
|
|
8
8
|
# Instantiates a new top level config object if one hasn't already been created
|
9
9
|
# Yields that config object to any given block
|
@@ -22,7 +22,7 @@ module Dev
|
|
22
22
|
# The name of the file containing the Aws settings
|
23
23
|
CONFIG_FILE = "#{Dev::Aws::CONFIG_DIR}/config".freeze
|
24
24
|
|
25
|
-
attr_accessor :root, :children, :default, :registry
|
25
|
+
attr_accessor :root, :children, :default, :registry, :ecr_registry_ids
|
26
26
|
|
27
27
|
# Instantiate an account object
|
28
28
|
# Requires that root account and at least one child account have been configured
|
@@ -35,7 +35,12 @@ module Dev
|
|
35
35
|
@root = self.class.config.root
|
36
36
|
@children = self.class.config.children
|
37
37
|
@default = self.class.config.default
|
38
|
-
|
38
|
+
|
39
|
+
# Create the ecr registry list based off several possible configuration values
|
40
|
+
@ecr_registry_ids = Array(self.class.config.ecr_registry_ids)
|
41
|
+
@ecr_registry_ids << self.class.config.registry
|
42
|
+
@ecr_registry_ids << Dev::Aws::Profile.new.current if self.class.config.login_to_account_ecr_registry
|
43
|
+
@ecr_registry_ids = @ecr_registry_ids.flatten.compact.reject(&:empty?).uniq
|
39
44
|
end
|
40
45
|
|
41
46
|
# Returns all configured account information objects
|
@@ -55,7 +60,7 @@ module Dev
|
|
55
60
|
|
56
61
|
# Look up the account name for the given account id
|
57
62
|
def name_by_account(account)
|
58
|
-
all.find { |it| it.id == account }
|
63
|
+
all.find { |it| it.id == account }.name
|
59
64
|
end
|
60
65
|
|
61
66
|
# Setup base Aws settings
|
@@ -16,11 +16,6 @@ module Dev
|
|
16
16
|
::Aws::STS::Client.new.get_caller_identity.account
|
17
17
|
end
|
18
18
|
|
19
|
-
# The role the profile is currently logged in to
|
20
|
-
def logged_in_role
|
21
|
-
::Aws::STS::Client.new.get_caller_identity.arn
|
22
|
-
end
|
23
|
-
|
24
19
|
# The region associated with the current login
|
25
20
|
def logged_in_region
|
26
21
|
::Aws::STS::Client.new.send(:config).region
|
@@ -8,7 +8,7 @@ module Dev
|
|
8
8
|
class Login
|
9
9
|
# Main interface for logging in to an AWS account
|
10
10
|
# If an account is not specified the user is given an account selection menu
|
11
|
-
# If
|
11
|
+
# If account registries have been configured, the user is also logged in to the docker registries
|
12
12
|
def login!(account = nil)
|
13
13
|
# If more than one child account has been configured, have the user select the account they want to log in to
|
14
14
|
account ||= Dev::Aws::Account.new.select
|
@@ -22,8 +22,8 @@ module Dev
|
|
22
22
|
# Load credentials into the ENV for subprocesses
|
23
23
|
Dev::Aws::Credentials.new.export!
|
24
24
|
|
25
|
-
# Login in to
|
26
|
-
|
25
|
+
# Login in to all configured docker registries
|
26
|
+
registry_logins!
|
27
27
|
end
|
28
28
|
|
29
29
|
# Authorize your local credentials
|
@@ -67,7 +67,17 @@ module Dev
|
|
67
67
|
|
68
68
|
# Authroizes the docker cli to pull/push images from the Aws container registry (e.g. if docker compose needs to pull an image)
|
69
69
|
# Authroizes the docker ruby library to pull/push images from the Aws container registry
|
70
|
-
def
|
70
|
+
def registry_logins!(registry_ids: Dev::Aws::Account.new.ecr_registry_ids, region: Dev::Aws::DEFAULT_REGION)
|
71
|
+
return if registry_ids.empty?
|
72
|
+
|
73
|
+
puts
|
74
|
+
registry_ids.each { |id| registry_login!(registry_id: id, region: region) }
|
75
|
+
puts
|
76
|
+
end
|
77
|
+
|
78
|
+
# Authroizes the docker cli to pull/push images from the Aws container registry (e.g. if docker compose needs to pull an image)
|
79
|
+
# Authroizes the docker ruby library to pull/push images from the Aws container registry
|
80
|
+
def registry_login!(registry_id: Dev::Aws::Account.new.registries, region: Dev::Aws::DEFAULT_REGION)
|
71
81
|
raise 'registry_id is required' if registry_id.to_s.strip.empty?
|
72
82
|
raise 'region is required' if region.to_s.strip.empty?
|
73
83
|
|
@@ -85,17 +95,17 @@ module Dev
|
|
85
95
|
def docker_login!(registry_id: Dev::Aws::Account.new.registry, region: Dev::Aws::DEFAULT_REGION)
|
86
96
|
warn '[DEPRECATION] `Dev::Aws::Login#docker_login!` is deprecated. Please use `Dev::Aws::Login#registry_login!` instead.'
|
87
97
|
docker_cli_login!(registry: "#{registry_id}.dkr.ecr.#{region}.amazonaws.com", region: region)
|
98
|
+
puts
|
88
99
|
end
|
89
100
|
|
90
101
|
# Authroizes the docker cli to pull/push images from the Aws container registry
|
91
102
|
# (e.g. if docker compose needs to pull an image)
|
92
103
|
private def docker_cli_login!(registry:, region:)
|
93
|
-
print(
|
104
|
+
print(" Logging in to #{registry} in docker... ")
|
94
105
|
login_cmd = "aws --profile=#{Dev::Aws::Profile.new.current} ecr --region=#{region} get-login-password"
|
95
106
|
login_cmd << ' | '
|
96
107
|
login_cmd << "docker login --password-stdin --username AWS #{registry}"
|
97
108
|
Dev::Common.new.run_command([login_cmd])
|
98
|
-
puts
|
99
109
|
end
|
100
110
|
|
101
111
|
# Authroizes the docker ruby library to pull/push images from the Aws container registry
|
@@ -33,10 +33,8 @@ module Dev
|
|
33
33
|
# Print the profile info for the current account
|
34
34
|
def info
|
35
35
|
Dev::Aws::Credentials.new.export!
|
36
|
-
current_role = Dev::Aws::Credentials.new.logged_in_role.split(%r{/})[1]
|
37
|
-
current_account_name = Dev::Aws::Account.new.name_by_account(current)
|
38
36
|
puts
|
39
|
-
puts " Currently logged in
|
37
|
+
puts " Currently logged in to the #{Dev::Aws::Account.new.name_by_account(current)} (#{current})".light_yellow
|
40
38
|
puts
|
41
39
|
puts ' To use this profile in your local aws cli, you must either pass the profile as a command line argument ' \
|
42
40
|
'or export the corresponding aws variable:'.light_white
|
@@ -52,15 +50,6 @@ module Dev
|
|
52
50
|
puts " export AWS_SESSION_TOKEN=#{ENV.fetch('AWS_SESSION_TOKEN', nil)}"
|
53
51
|
puts
|
54
52
|
end
|
55
|
-
|
56
|
-
# Print the export commands for the current credentials
|
57
|
-
def export_info
|
58
|
-
Dev::Aws::Credentials.new.export!
|
59
|
-
puts "export AWS_DEFAULT_REGION=#{ENV.fetch('AWS_DEFAULT_REGION', nil)}"
|
60
|
-
puts "export AWS_ACCESS_KEY_ID=#{ENV.fetch('AWS_ACCESS_KEY_ID', nil)}"
|
61
|
-
puts "export AWS_SECRET_ACCESS_KEY=#{ENV.fetch('AWS_SECRET_ACCESS_KEY', nil)}"
|
62
|
-
puts "export AWS_SESSION_TOKEN=#{ENV.fetch('AWS_SESSION_TOKEN', nil)}"
|
63
|
-
end
|
64
53
|
end
|
65
54
|
end
|
66
55
|
end
|
@@ -31,20 +31,6 @@ module Dev
|
|
31
31
|
task profile: %w(init) do
|
32
32
|
Dev::Aws::Profile.new.info
|
33
33
|
end
|
34
|
-
|
35
|
-
namespace :profile do
|
36
|
-
desc 'Return the commands to export your AWS credentials into your environment'
|
37
|
-
task :export do
|
38
|
-
# Turn off all logging except for errors
|
39
|
-
LOG.level = Logger::ERROR
|
40
|
-
|
41
|
-
# Run the init
|
42
|
-
Rake::Task[:init].invoke
|
43
|
-
|
44
|
-
# Print the export info
|
45
|
-
Dev::Aws::Profile.new.export_info
|
46
|
-
end
|
47
|
-
end
|
48
34
|
end
|
49
35
|
end
|
50
36
|
end
|
@@ -118,9 +118,9 @@ DEV_COMMANDS_TOP_LEVEL.instance_eval do
|
|
118
118
|
|
119
119
|
# Define an empty _pre_down_hooks handler which can be overridden by the user
|
120
120
|
task :_pre_down_hooks do
|
121
|
-
# The user may define custom
|
122
|
-
# Define this process in the appropriate namespace to add them only to a specific
|
123
|
-
# In that case it is recommended that you call the base
|
121
|
+
# The user may define custom _pre_logs_hooks tasks to add any pre-logs actions the logs process
|
122
|
+
# Define this process in the appropriate namespace to add them only to a specific logs
|
123
|
+
# In that case it is recommended that you call the base _pre_logs_hooks as a dependency of that task
|
124
124
|
end
|
125
125
|
|
126
126
|
# Define an empty _post_down_hooks handler which can be overridden by the user
|
@@ -130,20 +130,6 @@ DEV_COMMANDS_TOP_LEVEL.instance_eval do
|
|
130
130
|
# In that case it is recommended that you call the base _post_down_hooks as a dependency of that task
|
131
131
|
end
|
132
132
|
|
133
|
-
# Define an empty _pre_stop_hooks handler which can be overridden by the user
|
134
|
-
task :_pre_stop_hooks do
|
135
|
-
# The user may define custom _pre_stop_hooks tasks to add any pre-stop actions the stop process
|
136
|
-
# Define this process in the appropriate namespace to add them only to a specific stop
|
137
|
-
# In that case it is recommended that you call the base _pre_stop_hooks as a dependency of that task
|
138
|
-
end
|
139
|
-
|
140
|
-
# Define an empty _post_stop_hooks handler which can be overridden by the user
|
141
|
-
task :_post_stop_hooks do
|
142
|
-
# The user may define custom _post_stop_hooks tasks to add any post-stop actions the stop process
|
143
|
-
# Define this process in the appropriate namespace to add them only to a specific stop
|
144
|
-
# In that case it is recommended that you call the base _post_stop_hooks as a dependency of that task
|
145
|
-
end
|
146
|
-
|
147
133
|
# Define an empty _pre_reload_hooks handler which can be overridden by the user
|
148
134
|
task :_pre_reload_hooks do
|
149
135
|
# The user may define custom _pre_reload_hooks tasks to add any pre-reload actions the reload process
|
@@ -108,7 +108,7 @@ module Dev
|
|
108
108
|
namespace application do
|
109
109
|
return if exclude.include?(:down)
|
110
110
|
|
111
|
-
desc "
|
111
|
+
desc "Stops the #{application} container"
|
112
112
|
task down: %w(init_docker _pre_down_hooks) do
|
113
113
|
LOG.debug "In #{application} down"
|
114
114
|
|
@@ -125,25 +125,6 @@ module Dev
|
|
125
125
|
end
|
126
126
|
end
|
127
127
|
|
128
|
-
# Create the rake task which runs a docker compose stop for the application name
|
129
|
-
def create_stop_task!
|
130
|
-
application = @name
|
131
|
-
exclude = @exclude
|
132
|
-
|
133
|
-
DEV_COMMANDS_TOP_LEVEL.instance_eval do
|
134
|
-
namespace application do
|
135
|
-
return if exclude.include?(:stop)
|
136
|
-
|
137
|
-
desc "Stops the #{application} container"
|
138
|
-
task stop: %w(init_docker _pre_stop_hooks) do
|
139
|
-
LOG.debug "In #{application} stop"
|
140
|
-
Dev::Docker::Compose.new(services: [application]).stop
|
141
|
-
Rake::Task[:_post_stop_hooks].execute
|
142
|
-
end
|
143
|
-
end
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
128
|
# Create the rake task which stops, cleans, and starts the application
|
148
129
|
def create_reload_task!
|
149
130
|
application = @name
|
@@ -76,30 +76,6 @@ module Dev
|
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
79
|
-
# Create the rake task which stops all running containers
|
80
|
-
def create_stop_task!
|
81
|
-
exclude = @exclude
|
82
|
-
|
83
|
-
DEV_COMMANDS_TOP_LEVEL.instance_eval do
|
84
|
-
return if exclude.include?(:stop)
|
85
|
-
|
86
|
-
desc 'Stops all running containers'
|
87
|
-
task stop: %w(init_docker _pre_stop_hooks) do
|
88
|
-
LOG.debug('In base stop')
|
89
|
-
|
90
|
-
containers = ::Docker::Container.all(filters: {status: %w(restarting running)}.to_json)
|
91
|
-
containers.each do |container|
|
92
|
-
next if container&.info&.dig('Names')&.any? { |name| name.start_with?('/windows_tcp') }
|
93
|
-
|
94
|
-
LOG.info "Stopping container #{container.id[0, 12]}"
|
95
|
-
container.stop(timeout: 120)
|
96
|
-
end
|
97
|
-
|
98
|
-
Rake::Task[:_post_stop_hooks].execute
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
79
|
# Create the rake task which runs a docker compose down followed by an up
|
104
80
|
def create_reload_task!
|
105
81
|
exclude = @exclude
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: firespring_dev_commands
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.3.pre.alpha.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Firespring
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-05-
|
11
|
+
date: 2023-05-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|