firespring_dev_commands 1.4.3.pre.alpha.1 → 1.4.3.pre.alpha.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cb403fd1ae12470807a778fbb3314f74b80a5f7d7c8fe0cf1ac28bab1d56d837
4
- data.tar.gz: ff65c1e27fe4f4d63f3d31f5817b552d5dd4c930b615fadb0403e178e30fa597
3
+ metadata.gz: 6202dfc1befb402bba5013a33cc9fb85181aa1ba704eed0cae6b1fc1a1a14a89
4
+ data.tar.gz: 5a83b16623b5f0d0ebb822dcd4bf3bc4a171b349a76c7e53a489c346a50e920e
5
5
  SHA512:
6
- metadata.gz: 864a3659c6164459f8623f55e9d995cf77c09d03da85fe23c1b6e9f45e7dde3fe0982891b6e662b0b3942695a12f98d4ba4abe71eb3131e3f9898fa5afa146bd
7
- data.tar.gz: 323ed9adeba33220e791ef078c0e3c4390ed93cdc262b3c3aa18e9b103099bf2f57e727e1b1e412773f3c54cd734fda8b1304953b5bdc2bd1350ba4fdf7a58a4
6
+ metadata.gz: ee53711a91212ce350041b15b338230bd1ca7c314fc165b154ee73e3997329194184dea206b6ebfe222672e2705e1de9a625c3628bc14a2c15ec20a7d9cb24f7
7
+ data.tar.gz: 79fe039edb3293f8b5dd4a507d8d4639b34964c1e58614497517c5d37631bc8e0e6a6f6f7af8aa9166f569ca627be54941571e07c621ad45ac2a9f75f0d78f80
@@ -3,7 +3,11 @@ 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, :ecr_registry_ids, :login_to_account_ecr_registry)
6
+
7
+ # TODO: Can we add a "login_to_account_registry?
8
+ # TODO: And then add additional_registries?
9
+
10
+ Config = Struct.new(:root, :children, :default, :registry, :registries)
7
11
 
8
12
  # Instantiates a new top level config object if one hasn't already been created
9
13
  # Yields that config object to any given block
@@ -22,7 +26,7 @@ module Dev
22
26
  # The name of the file containing the Aws settings
23
27
  CONFIG_FILE = "#{Dev::Aws::CONFIG_DIR}/config".freeze
24
28
 
25
- attr_accessor :root, :children, :default, :registry, :ecr_registry_ids
29
+ attr_accessor :root, :children, :default, :registry, :registries
26
30
 
27
31
  # Instantiate an account object
28
32
  # Requires that root account and at least one child account have been configured
@@ -35,12 +39,7 @@ module Dev
35
39
  @root = self.class.config.root
36
40
  @children = self.class.config.children
37
41
  @default = self.class.config.default
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
42
+ @registries = (Array(self.class.config.registries) << self.class.config.registry).compact.uniq
44
43
  end
45
44
 
46
45
  # Returns all configured account information objects
@@ -60,7 +59,7 @@ module Dev
60
59
 
61
60
  # Look up the account name for the given account id
62
61
  def name_by_account(account)
63
- all.find { |it| it.id == account }.name
62
+ all.find { |it| it.id == account }&.name
64
63
  end
65
64
 
66
65
  # Setup base Aws settings
@@ -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
@@ -67,7 +67,7 @@ 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 registry_logins!(registry_ids: Dev::Aws::Account.new.ecr_registry_ids, region: Dev::Aws::DEFAULT_REGION)
70
+ def registry_logins!(registry_ids: Dev::Aws::Account.new.registries, region: Dev::Aws::DEFAULT_REGION)
71
71
  return if registry_ids.empty?
72
72
 
73
73
  puts
@@ -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 to the #{Dev::Aws::Account.new.name_by_account(current)} (#{current})".light_yellow
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 _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
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 "Stops the #{application} container"
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
@@ -6,6 +6,6 @@ module Dev
6
6
  # Use 'v.v.v.pre.alpha.v' for pre-release vesions
7
7
  # Use 'v.v.v.beta.v for beta versions
8
8
  # Use semantic versioning for any releases (https://semver.org/)
9
- VERSION = '1.4.3.pre.alpha.1'.freeze
9
+ VERSION = '1.4.3.pre.alpha.2'.freeze
10
10
  end
11
11
  end
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.1
4
+ version: 1.4.3.pre.alpha.2
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-09 00:00:00.000000000 Z
11
+ date: 2023-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport