firespring_dev_commands 1.4.3.pre.alpha.1 → 1.4.3.pre.alpha.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/firespring_dev_commands/aws/account.rb +2 -2
- data/lib/firespring_dev_commands/aws/credentials.rb +10 -0
- data/lib/firespring_dev_commands/aws/login.rb +3 -3
- data/lib/firespring_dev_commands/aws/profile.rb +12 -1
- data/lib/firespring_dev_commands/templates/aws.rb +14 -0
- data/lib/firespring_dev_commands/templates/base_interface.rb +17 -3
- data/lib/firespring_dev_commands/templates/docker/application.rb +20 -1
- data/lib/firespring_dev_commands/templates/docker/default.rb +24 -0
- 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: 764aab3927a5dc24b6474ba35af2e54f7b97dfa93ac54ae8187989ff954cfbbe
|
4
|
+
data.tar.gz: 33c04cd996134dcb26fa12358b5ec3ab436dcaa07f5db69f0f96d8b13fb1c5e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 572c3b804cf02d5d7e4a62060a4a779b67843a14047a36f207b3e1198868326eb1379b3cc44ee0160c714ef8bbdfaf14e3c76ccf58e75cf88784415df4595ea5
|
7
|
+
data.tar.gz: f91c0898808c71729efe61cb841eec2901824f7793d49a50fe42bee80b2accb42b415baf20659e52e95850b4a9fae6355c5f82b70f02a7fa4e19dcd12d28ba5f
|
data/README.md
CHANGED
@@ -11,7 +11,7 @@ gem 'firespring_dev_commands', '~> 0.0.1'
|
|
11
11
|
* This is not common
|
12
12
|
* It is mostly used for testing local changes before the gem is released
|
13
13
|
```
|
14
|
-
gem 'firespring_dev_commands', path: '/path/to/
|
14
|
+
gem 'firespring_dev_commands', path: '/path/to/dev_commands'
|
15
15
|
```
|
16
16
|
|
17
17
|
* Add the following to your Rakefile
|
@@ -60,7 +60,7 @@ module Dev
|
|
60
60
|
|
61
61
|
# Look up the account name for the given account id
|
62
62
|
def name_by_account(account)
|
63
|
-
all.find { |it| it.id == account }
|
63
|
+
all.find { |it| it.id == account }&.name
|
64
64
|
end
|
65
65
|
|
66
66
|
# Setup base Aws settings
|
@@ -78,7 +78,7 @@ module Dev
|
|
78
78
|
region_default = defaultini['region'] || ENV['AWS_DEFAULT_REGION'] || Dev::Aws::DEFAULT_REGION
|
79
79
|
defaultini['region'] = Dev::Common.new.ask('Default region name', region_default)
|
80
80
|
|
81
|
-
mfa_default = defaultini['mfa_serial'] || ENV['AWS_MFA_ARN'] || "arn:aws:iam::#{root}:mfa/#{ENV.fetch('USERNAME', nil)}"
|
81
|
+
mfa_default = defaultini['mfa_serial'] || ENV['AWS_MFA_ARN'] || "arn:aws:iam::#{root.id}:mfa/#{ENV.fetch('USERNAME', nil)}"
|
82
82
|
defaultini['mfa_serial'] = Dev::Common.new.ask('Default mfa arn', mfa_default)
|
83
83
|
|
84
84
|
session_name_default = defaultini['role_session_name'] || "#{ENV.fetch('USERNAME', nil)}_cli"
|
@@ -16,6 +16,16 @@ module Dev
|
|
16
16
|
::Aws::STS::Client.new.get_caller_identity.account
|
17
17
|
end
|
18
18
|
|
19
|
+
# The arn of the currently logged in identity
|
20
|
+
def logged_in_arn
|
21
|
+
::Aws::STS::Client.new.get_caller_identity.arn
|
22
|
+
end
|
23
|
+
|
24
|
+
# The role the current identity is using
|
25
|
+
def logged_in_role
|
26
|
+
logged_in_arn.split(%r{/})[1]
|
27
|
+
end
|
28
|
+
|
19
29
|
# The region associated with the current login
|
20
30
|
def logged_in_region
|
21
31
|
::Aws::STS::Client.new.send(:config).region
|
@@ -77,7 +77,7 @@ module Dev
|
|
77
77
|
|
78
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
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.
|
80
|
+
def registry_login!(registry_id: Dev::Aws::Account.new.ecr_registry_ids.last, region: Dev::Aws::DEFAULT_REGION)
|
81
81
|
raise 'registry_id is required' if registry_id.to_s.strip.empty?
|
82
82
|
raise 'region is required' if region.to_s.strip.empty?
|
83
83
|
|
@@ -92,7 +92,7 @@ module Dev
|
|
92
92
|
# Authroizes the docker cli to pull/push images from the Aws container registry
|
93
93
|
# (e.g. if docker compose needs to pull an image)
|
94
94
|
# @deprecated Please use {Dev::Aws::Login#registry_login!} instead
|
95
|
-
def docker_login!(registry_id: Dev::Aws::Account.new.
|
95
|
+
def docker_login!(registry_id: Dev::Aws::Account.new.ecr_registry_ids.last, region: Dev::Aws::DEFAULT_REGION)
|
96
96
|
warn '[DEPRECATION] `Dev::Aws::Login#docker_login!` is deprecated. Please use `Dev::Aws::Login#registry_login!` instead.'
|
97
97
|
docker_cli_login!(registry: "#{registry_id}.dkr.ecr.#{region}.amazonaws.com", region: region)
|
98
98
|
puts
|
@@ -110,7 +110,7 @@ module Dev
|
|
110
110
|
|
111
111
|
# Authroizes the docker ruby library to pull/push images from the Aws container registry
|
112
112
|
# @deprecated Please use {Dev::Aws::Login#registry_login!} instead
|
113
|
-
def ecr_login!(registry_id: Dev::Aws::Account.new.
|
113
|
+
def ecr_login!(registry_id: Dev::Aws::Account.new.ecr_registry_ids.last, region: Dev::Aws::DEFAULT_REGION)
|
114
114
|
warn '[DEPRECATION] `Dev::Aws::Login#ecr_login!` is deprecated. Please use `Dev::Aws::Login#registry_login!` instead.'
|
115
115
|
docker_lib_login!(registry_id: registry_id, region: region)
|
116
116
|
end
|
@@ -33,8 +33,10 @@ 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
|
37
|
+
current_account_name = Dev::Aws::Account.new.name_by_account(current)
|
36
38
|
puts
|
37
|
-
puts " Currently logged in
|
39
|
+
puts " Currently logged in as #{current_role} in the #{current_account_name} (#{current}) account".light_yellow
|
38
40
|
puts
|
39
41
|
puts ' To use this profile in your local aws cli, you must either pass the profile as a command line argument ' \
|
40
42
|
'or export the corresponding aws variable:'.light_white
|
@@ -50,6 +52,15 @@ module Dev
|
|
50
52
|
puts " export AWS_SESSION_TOKEN=#{ENV.fetch('AWS_SESSION_TOKEN', nil)}"
|
51
53
|
puts
|
52
54
|
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
|
53
64
|
end
|
54
65
|
end
|
55
66
|
end
|
@@ -31,6 +31,20 @@ 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
|
34
48
|
end
|
35
49
|
end
|
36
50
|
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_down_hooks tasks to add any pre-down actions the down process
|
122
|
+
# Define this process in the appropriate namespace to add them only to a specific down
|
123
|
+
# In that case it is recommended that you call the base _pre_down_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,6 +130,20 @@ 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
|
+
|
133
147
|
# Define an empty _pre_reload_hooks handler which can be overridden by the user
|
134
148
|
task :_pre_reload_hooks do
|
135
149
|
# 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 "Shut down the #{application} container and remove associated resources"
|
112
112
|
task down: %w(init_docker _pre_down_hooks) do
|
113
113
|
LOG.debug "In #{application} down"
|
114
114
|
|
@@ -125,6 +125,25 @@ 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
|
+
|
128
147
|
# Create the rake task which stops, cleans, and starts the application
|
129
148
|
def create_reload_task!
|
130
149
|
application = @name
|
@@ -76,6 +76,30 @@ 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
|
+
|
79
103
|
# Create the rake task which runs a docker compose down followed by an up
|
80
104
|
def create_reload_task!
|
81
105
|
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.3.pre.alpha.
|
4
|
+
version: 1.4.3.pre.alpha.3
|
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-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|