mina-infinum 2.1.0 → 2.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7515a358a97fb531c9234b5af9f66d38b21ca179baa2630a6c0cdab7594bc81d
4
- data.tar.gz: 0d1c15c942585a620cae300808ae5c509dbc8329fd68a17a67913e27203e3ab0
3
+ metadata.gz: d0ba2dc913ff35e4416588b4f58baab6070960c1d33dc619acbda331ed46da48
4
+ data.tar.gz: fc982c1d6374965b0c347fccd3f11983dcf8ccd5c94cdc48b65737fe57ce1437
5
5
  SHA512:
6
- metadata.gz: d636c8821a835dc329c263ebe7da0cafc1689aa4b4c41829988e243979c76f1867fedea43b1d2fdad509e11ff2bd96ed0e60a27645b217b47591056c29c386b0
7
- data.tar.gz: 28ce51888667a163a17dd3274643f9071d1cc88fa2981f593454cb92a2940996665deb17d9512e6cdcfa0c3f319af8003e778e2632faae3306927bd89ab4c725
6
+ metadata.gz: 83dc2eba39533955f29e8cec5ba626626b0b52d6c3f7cc1f6df2e77891217d615f304f989f46a58ff55532cb68bd41b8ef89fca08f2148a96cd17d755079e19e
7
+ data.tar.gz: a0d9cb6a87a5db0a41dbeb77fefcbbcf04d726807a986151e7eb931204fb4b55a4dc1d45a54e2a1ebd4154bbdb58c6e60b41945c72e332acc45d29c31e034b44
data/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # Changelog
2
2
 
3
+ ## [v2.3.0](https://github.com/infinum/mina-infinum/tree/v-2.3.0) (2025-10-02)
4
+ [Full Changelog](https://github.com/infinum/mina-infinum/compare/v2.2.0...v2.3.0)
5
+
6
+ ### Enhancements
7
+
8
+ - Add logs and logs:tail AWS tasks [\#8](https://github.com/infinum/mina-infinum/pull/8)
9
+
10
+ ## [v2.2.0](https://github.com/infinum/mina-infinum/tree/v-2.2.0) (2025-07-25)
11
+ [Full Changelog](https://github.com/infinum/mina-infinum/compare/v2.1.0...v2.2.0)
12
+
13
+ ### Enhancements
14
+
15
+ - Add aliases for aws:login and rails:console tasks [\#6](https://github.com/infinum/mina-infinum/pull/6)
16
+ - Add params:pull and params:read tasks to AWS tasks [\#7](https://github.com/infinum/mina-infinum/pull/7)
17
+
3
18
  ## [v2.1.0](https://github.com/infinum/mina-infinum/tree/v-2.1.0) (2025-05-29)
4
19
  [Full Changelog](https://github.com/infinum/mina-infinum/compare/v2.0.0...v2.1.0)
5
20
 
@@ -91,3 +91,6 @@ def profile_exists?(profile)
91
91
 
92
92
  profiles.split("\n").include?(profile)
93
93
  end
94
+
95
+ desc 'Alias for aws:login'
96
+ task :login => 'aws:login'
@@ -0,0 +1,112 @@
1
+ require 'time'
2
+ require 'mina/infinum/ecs/aws'
3
+
4
+ desc <<~TXT
5
+ Print logs from CloudWatch
6
+
7
+ Logs are printed from :log_group, which is a CloudWatch log group name.
8
+
9
+ Logs are fetched in range :since to :until (both inclusive). Both values must be
10
+ parseable by `Time.parse` (e.g. ISO8601 timestamps). :since is required,
11
+ :until is optional (if omitted, value will be current time).
12
+
13
+ If date is ommitted in either value, the current date is assumed.
14
+
15
+ Examples:
16
+ # logs since 26.9.2025. 14:00 in local time zone
17
+ $ mina logs since="2025-09-26 14:00"
18
+
19
+ # logs on 26.9.2025. between 14:00 and 15:00 in local time zone
20
+ $ mina logs since="2025-09-26 14:00" until="2025-09-26 15:00"
21
+
22
+ # logs between 14:00 and 15:00 today in local time zone
23
+ $ mina logs since="14:00" until="15:00"
24
+
25
+ # logs between 14:00 and 15:00 today in UTC
26
+ $ mina logs since="14:00Z" until="15:00Z"
27
+
28
+ # logs since 26.9.2025. 14:00 in UTC (ISO 8601 format)
29
+ $ mina logs since="2025-09-26T14:00Z"
30
+ TXT
31
+ task logs: ['aws:profile:check'] do
32
+ ensure!(:log_group)
33
+ ensure!(:since)
34
+
35
+ since_time = Time.parse(fetch(:since))
36
+ until_time = fetch(:until) ? Time.parse(fetch(:until)) : Time.now
37
+
38
+ puts "Printing logs from #{fetch(:log_group)} in range [#{since_time.iso8601},#{until_time.iso8601}]"
39
+ raw_logs = run_cmd squish(<<~CMD)
40
+ aws logs filter-log-events
41
+ --log-group-name #{fetch(:log_group)}
42
+ --profile #{fetch(:aws_profile)}
43
+ --start-time #{since_time.strftime('%s%L')}
44
+ --end-time #{until_time.strftime('%s%L')}
45
+ --output json
46
+ --query "events[].{timestamp: timestamp, message: message}"
47
+ CMD
48
+
49
+ next if raw_logs.empty? # response can be empty due to auth issues, user will see error in terminal
50
+
51
+ logs = JSON.parse(raw_logs)
52
+ if logs.any?
53
+ logs.each do |log|
54
+ time = Time.at(0, log.fetch('timestamp'), :millisecond)
55
+ puts "#{green_text(time.utc.iso8601)} #{log.fetch('message')}"
56
+ end
57
+ else
58
+ puts 'There are no logs'
59
+ end
60
+ end
61
+
62
+ namespace :logs do
63
+ desc <<~TXT
64
+ Tail logs from CloudWatch
65
+
66
+ Logs are tailed from :log_group, which is a CloudWatch log group name.
67
+
68
+ Before new logs are tailed, recent logs are first printed. You can control
69
+ from what time recent logs are printed with :since. The value can be absolute
70
+ time parseable by `Time.parse`, or relative time.
71
+
72
+ If date is ommitted in absolute time, the current date is assumed.
73
+
74
+ Examples:
75
+ # tail logs since 26.9.2025. 14:00 in local time zone
76
+ $ mina logs:tail since="2025-09-26 14:00"
77
+
78
+ # tail logs since 14:00 today in local time zone
79
+ $ mina logs:tail since="14:00"
80
+
81
+ # tail logs since 26.9.2025. 14:00 in UTC (ISO 8601 format)
82
+ $ mina logs:tail since="2025-09-26T14:00Z"
83
+
84
+ # tail logs since 5 minutes ago
85
+ $ mina logs:tail since="5m"
86
+
87
+ For more info on accepted :since values, see --since options
88
+ https://docs.aws.amazon.com/cli/latest/reference/logs/tail.html#options
89
+ TXT
90
+ task tail: ['aws:profile:check'] do
91
+ ensure!(:log_group)
92
+
93
+ since_time = fetch(:since)&.strip
94
+
95
+ if since_time && !since_time.empty? && !since_time.match?(/\A\d+\w\z/)
96
+ since_time = Time.parse(since_time).iso8601
97
+ end
98
+
99
+ puts "Tailing logs from #{fetch(:log_group)}"
100
+ run_cmd squish(<<~CMD), exec: true
101
+ aws logs tail #{fetch(:log_group)}
102
+ --profile #{fetch(:aws_profile)}
103
+ --follow
104
+ --format short
105
+ #{"--since #{since_time}" if since_time}
106
+ CMD
107
+ end
108
+ end
109
+
110
+ def green_text(text)
111
+ "\e[32m#{text}\e[0m"
112
+ end
@@ -0,0 +1,73 @@
1
+ require 'mina/infinum/ecs/aws'
2
+
3
+ namespace :params do
4
+ desc <<~TXT
5
+ Print AWS Param Store params to stdout
6
+
7
+ By default, params are fetched from path "/:cluster/".
8
+ All levels of params are fetched under this path, e.g.
9
+ both "/:cluster/A" and "/:cluster/A/B/C" will be fetched.
10
+
11
+ You can override the path by setting :params_path.
12
+ TXT
13
+ task read: ['aws:profile:check'] do
14
+ puts get_params.map(&:as_env)
15
+ end
16
+
17
+ desc <<~TXT
18
+ Save AWS Param Store params to .env file
19
+
20
+ See params:read documentation for details on how params
21
+ are fetched.
22
+ TXT
23
+ task pull: ['aws:profile:check'] do
24
+ env_file_path = File.join(Dir.pwd, '.env')
25
+
26
+ File.write(env_file_path, get_params.map(&:as_env).join("\n"))
27
+ end
28
+ end
29
+
30
+ Param = Data.define(:name, :value) do
31
+ # /staging-acme/acme/staging/BUGSNAG_API_KEY -> BUGSNAG_API_KEY
32
+ def variable_name
33
+ name.split('/').last
34
+ end
35
+
36
+ def as_env
37
+ "#{variable_name}=#{value}"
38
+ end
39
+ end
40
+
41
+ def get_params
42
+ normalize_params(get_params_from_aws)
43
+ end
44
+
45
+ def normalize_params(raw_params)
46
+ raw_params.map do |param|
47
+ Param.new(name: param.fetch('Name'), value: param.fetch('Value'))
48
+ end
49
+ end
50
+
51
+ def get_params_from_aws
52
+ params_path = fetch(:params_path) || default_params_path
53
+ output = run_cmd squish(<<~CMD)
54
+ aws ssm get-parameters-by-path
55
+ --path #{params_path}
56
+ --with-decryption
57
+ --recursive
58
+ --profile #{fetch(:aws_profile)}
59
+ #{'--debug' if debug?}
60
+ CMD
61
+
62
+ unless $CHILD_STATUS.success?
63
+ error! "Cannot fetch params from AWS... do you need to log in (use task aws:login)? For more info, add debug=true to command"
64
+ end
65
+
66
+ JSON.parse(output).dig('Parameters') || error!('There are no params in the response')
67
+ end
68
+
69
+ def default_params_path
70
+ ensure!(:cluster)
71
+
72
+ "/#{fetch(:cluster)}/"
73
+ end
@@ -21,7 +21,7 @@ end
21
21
 
22
22
  namespace :rails do
23
23
  desc <<~TXT
24
- Open rails console
24
+ Open Rails console
25
25
 
26
26
  Runs "bundle exec rails console" on the ECS container.
27
27
  TXT
@@ -40,3 +40,6 @@ namespace :rails do
40
40
  invoke 'ecs:exec', "tail -f log/#{fetch(:rails_env)}.log"
41
41
  end
42
42
  end
43
+
44
+ desc 'Alias for rails:console'
45
+ task :console => 'rails:console'
@@ -1,6 +1,8 @@
1
1
  require 'mina/default'
2
2
  require 'mina/infinum/ecs/rails'
3
+ require 'mina/infinum/ecs/logs'
3
4
  require 'mina/infinum/ecs/db'
5
+ require 'mina/infinum/ecs/params'
4
6
 
5
7
  # INFO: hides default Mina tasks when running "mina --tasks"
6
8
  Rake::Task['run'].clear_comments
@@ -1,5 +1,5 @@
1
1
  module Mina
2
2
  module Infinum
3
- VERSION = '2.1.0'.freeze
3
+ VERSION = '2.3.0'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mina-infinum
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stjepan Hadjic
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-05-29 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: bundler
@@ -145,6 +145,8 @@ files:
145
145
  - lib/mina/infinum/ecs/aws.rb
146
146
  - lib/mina/infinum/ecs/db.rb
147
147
  - lib/mina/infinum/ecs/ecs.rb
148
+ - lib/mina/infinum/ecs/logs.rb
149
+ - lib/mina/infinum/ecs/params.rb
148
150
  - lib/mina/infinum/ecs/rails.rb
149
151
  - lib/mina/infinum/helpers.rb
150
152
  - lib/mina/infinum/tasks.rb
@@ -169,7 +171,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
169
171
  - !ruby/object:Gem::Version
170
172
  version: '0'
171
173
  requirements: []
172
- rubygems_version: 3.6.2
174
+ rubygems_version: 3.6.7
173
175
  specification_version: 4
174
176
  summary: Collection of mina plugins we use in infinum
175
177
  test_files: []