lucy_dockerunner 0.1.0 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f5e5a03a9ef72ac78d552d8f4961132d292f72bf10e3fe0aa9a0b8e3aca17f5a
4
- data.tar.gz: dd65c50f4cd8f8f44f2f8090c591a307e7e57550bd642319afed5bc2afd46d94
3
+ metadata.gz: 53e94959b2b2e657d75c97d7e4c3d7657d712df97c12177d83e3410402691705
4
+ data.tar.gz: d18ce98ae20af0851862335e5b09864c5a3ac215319154273ed8044b309274a1
5
5
  SHA512:
6
- metadata.gz: 179f532102d570dcbf439046f3bdc19c861fa99919d13ec47f43b8aca8504e417631aed62fad9935aef600abf0e5d3e2f7faf20895237c40f5774981205a2568
7
- data.tar.gz: 6e3487f0144a3ddd385bece9540094cb6d4679868c7f4ee18cfca96b8cd31297a680df8ac82a05161aab3df689584414f4114bdaf3d0ef6cf04589f1e03ce459
6
+ metadata.gz: a2d9027e40592cec52e4b9701ffcf26f654b2d75661f19b6d5a25ccfa3353840e51a16cae3c050130222db8df87bfc49d29102e6bd1cc44b2ea6c9b21375e6c3
7
+ data.tar.gz: f7d6fee82bb28d4060a93cc0889678b1f415a96e14fb0ee136d53ab621c790e1ef4df799ebd36268cc312483fd41e9f7aaf25d4ce8fda15cf9c5844733c2ad6f
data/Gemfile CHANGED
@@ -7,16 +7,11 @@ gemspec
7
7
 
8
8
  gem "rake"
9
9
 
10
- gem "rake-hooks", git: "https://github.com/JesusGautamah/rake-hooks.git", branch: "master"
11
-
12
10
  group :test, :development do
13
11
  gem "rspec", "~> 3.0"
14
12
  gem "rubocop", "~> 1.21"
15
- gem "rubocop-rspec", "~> 2.4"
16
13
  gem "rubocop-performance", "~> 1.11"
17
14
  gem "rubocop-rake", "~> 0.5"
15
+ gem "rubocop-rspec", "~> 2.4"
18
16
  gem "simplecov", "~> 0.21"
19
17
  end
20
-
21
-
22
-
data/Gemfile.lock CHANGED
@@ -1,16 +1,7 @@
1
- GIT
2
- remote: https://github.com/JesusGautamah/rake-hooks.git
3
- revision: 4ee50e368c9cbc0ecb087df0ffdfdf1c647739c8
4
- branch: master
5
- specs:
6
- rake-hooks (1.2.5)
7
- rake
8
-
9
1
  PATH
10
2
  remote: .
11
3
  specs:
12
- lucy_dockerunner (0.1.8)
13
- rake-hooks
4
+ lucy_dockerunner (0.1.4)
14
5
 
15
6
  GEM
16
7
  remote: https://rubygems.org/
@@ -76,7 +67,6 @@ PLATFORMS
76
67
  DEPENDENCIES
77
68
  lucy_dockerunner!
78
69
  rake
79
- rake-hooks!
80
70
  rspec (~> 3.0)
81
71
  rubocop (~> 1.21)
82
72
  rubocop-performance (~> 1.11)
data/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Igor Lima de Jesus
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  Lucy Dockerunner is a Ruby gem that provides a simple wrapper around the Docker Compose CLI to make it easier to run Docker Compose commands from Ruby.
4
4
 
5
+ [![Gem Version](https://badge.fury.io/rb/lucy_dockerunner.svg)](https://badge.fury.io/rb/lucy_dockerunner)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
+ [![Ruby Version](https://img.shields.io/badge/Ruby-2.6.0%2B-blue.svg)](https://www.ruby-lang.org/en/)
8
+
9
+ Ruby version: >= 2.6.0
10
+
5
11
  ## Installation
6
12
 
7
13
  You can install the gem by executing:
@@ -17,11 +23,17 @@ Or add it to your Gemfile:
17
23
  * `rake compose:build` - build docker compose services
18
24
  * `rake compose:up` - start the docker compose services
19
25
  * `rake compose:down` - stop the docker compose services
26
+ * `rake compose:status` - show the status of the docker compose services
27
+ * `rake compose:shell` - open a shell in the web service
20
28
  * `rake compose:db_detach` - detach the database from the docker compose services
21
29
  * `rake compose:redis_detach` - detach the redis from the docker compose services
22
30
  * `rake compose:back_detach` - detach the backend(redis, sidekiq, db) from the docker compose services
23
31
  * `rake compose:restart` - restart the docker compose services
24
32
  * `rake compose:clean_all` - clean all docker compose services
33
+ * `rake compose:clean_images` - clean all docker compose images
34
+ * `rake compose:clean_volumes` - clean all docker compose volumes
35
+ * `rake compose:clean_orphans` - clean all docker compose orphans
36
+ * `rake compose:clean_containers` - clean all docker compose containers
25
37
  #### Database actions
26
38
  * `rake compose_db:migrate` - migrate the database
27
39
  * `rake compose_db:reset` - reset the database
@@ -56,21 +68,20 @@ Or add it to your Gemfile:
56
68
  * `rake compose_logs:tail_redis` - tail redis logs
57
69
  * `rake compose_logs:tail_sidekiq` - tail sidekiq logs
58
70
  * `rake compose_logs:tail_all` - tail all logs
59
- * `rake compose_logs:follow_web` - follow web logs
60
- * `rake compose_logs:follow_db` - follow db logs
61
- * `rake compose_logs:follow_redis` - follow redis logs
62
- * `rake compose_logs:follow_sidekiq` - follow sidekiq logs
63
- * `rake compose_logs:follow_all` - follow all logs
64
71
 
65
- ## Start the blockchain
72
+ ## Start the docker compose services
66
73
  ````bash
67
74
  $ rake compose:up
68
75
  ````
69
- ### Access the blockchain web interface
76
+ ### Access the web service
70
77
  http://localhost
78
+
79
+
80
+ ## References
81
+ The code code inside the 'lib/rake/hooks.rb' file is based on the code of the [rake-hooks](https://github.com/guillermo/rake-hooks) from Guillermo Iguaran, Joel Moss as described in the [Ruby Toolbox](https://www.ruby-toolbox.com/projects/rake-hooks) page.
71
82
  ## Contributing
72
83
 
73
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/lucy_dockerunner. 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/[USERNAME]/lucy_dockerunner/blob/master/CODE_OF_CONDUCT.md).
84
+ Bug reports and pull requests are welcome on GitHub at https://github.com/JesusGautamah/lucy_dockerunner. 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/JesusGautamah/lucy_dockerunner/blob/master/CODE_OF_CONDUCT.md).
74
85
 
75
86
  ## License
76
87
 
@@ -78,4 +89,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
78
89
 
79
90
  ## Code of Conduct
80
91
 
81
- Everyone interacting in the LucyDockerunner project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/lucy_dockerunner/blob/master/CODE_OF_CONDUCT.md).
92
+ Everyone interacting in the LucyDockerunner project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/JesusGautamah/lucy_dockerunner/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile CHANGED
@@ -11,4 +11,4 @@ RuboCop::RakeTask.new
11
11
 
12
12
  task default: %i[spec rubocop]
13
13
 
14
- Dir.glob("lib/tasks/*.rake").each { |r| import r }
14
+ Dir.glob("lib/tasks/*.rake").each { |r| import r }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LucyDockerunner
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.4"
5
5
  end
@@ -1,14 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "lucy_dockerunner/version"
4
- # require "rake/hooks"
5
4
 
5
+ # Main module
6
6
  module LucyDockerunner
7
7
  class Error < StandardError; end
8
-
9
8
  class << self
10
9
  def load_tasks
11
- Dir[File.join(__dir__, 'tasks', '*.rake')].each { |r| load r }
10
+ Dir[File.join(__dir__, "tasks", "*.rake")].each { |r| load r }
12
11
  end
13
12
  end
14
13
  end
data/lib/rake/hooks.rb ADDED
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Rake::Hooks from https://github.com/guillermo/rake-hooks, authors Guillermo Iguaran, Joel Moss
4
+ module Rake
5
+ module Hooks
6
+ def before(*task_names, &new_task)
7
+ task_names.each do |task_name|
8
+ old_task = Rake.application.instance_variable_get("@tasks").delete(task_name.to_s)
9
+ next unless old_task
10
+
11
+ desc old_task.full_comment if old_task.respond_to?(:full_comment)
12
+ task task_name => old_task.prerequisites do
13
+ new_task.call
14
+ old_task.invoke
15
+ end
16
+ end
17
+ end
18
+
19
+ def after(*task_names, &new_task)
20
+ options = task_names.last.is_a?(Hash) ? task_names.pop : {}
21
+ ignore_exceptions = options.delete(:ignore_exceptions) || false
22
+
23
+ task_names.each do |task_name|
24
+ old_task = Rake.application.instance_variable_get("@tasks").delete(task_name.to_s)
25
+ next unless old_task
26
+
27
+ desc old_task.full_comment if old_task.respond_to?(:full_comment)
28
+ task task_name => old_task.prerequisites do
29
+ begin
30
+ old_task.invoke
31
+ rescue StandardError
32
+ raise unless ignore_exceptions
33
+ end
34
+
35
+ new_task.call
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+
42
+ Rake::DSL.include Rake::Hooks if defined?(Rake::DSL)
43
+ include Rake::Hooks unless self.class.included_modules.include?(Rake::Hooks)
@@ -2,18 +2,19 @@
2
2
 
3
3
  require "rake"
4
4
  require_relative "task_helpers/compose_taskhelper"
5
- require "rake/hooks"
5
+ require_relative "../rake/hooks"
6
6
 
7
7
  def tasks_names
8
- @tasks_names = %w[install build up down restart clean_all clean_volumes clean_orphans clean_images clean_networks clean_stopped]
8
+ @tasks_names = %w[install build up down restart clean_all clean_volumes clean_orphans clean_images clean_networks
9
+ clean_stopped]
9
10
  end
10
11
 
11
12
  def namesp
12
- @namesp = 'compose'
13
+ @namesp = "compose"
13
14
  end
14
15
 
15
16
  def dev_compose_file
16
- @dev_compose_file ||= 'docker-compose.yml'
17
+ @dev_compose_file ||= "docker-compose.yml"
17
18
  end
18
19
 
19
20
  def task_helper
@@ -99,6 +100,18 @@ namespace :compose do
99
100
  puts "Restarting Compose... Done!"
100
101
  end
101
102
 
103
+ task :status do
104
+ puts "Status Compose..."
105
+ system "sudo #{compose_command} ps"
106
+ puts "Status Compose... Done!"
107
+ end
108
+
109
+ task :shell do
110
+ puts "Running Shell..."
111
+ system "sudo #{compose_command} run --rm web bash"
112
+ puts "Running Shell... Done!"
113
+ end
114
+
102
115
  task :clean_all do
103
116
  puts "Cleaning Compose..."
104
117
  puts "Stopping Compose..."
@@ -169,7 +182,7 @@ def compose_checker
169
182
  end
170
183
 
171
184
  def dockerfile_checker
172
- !File.exist?('Dockerfile')
185
+ !File.exist?("Dockerfile")
173
186
  end
174
187
 
175
188
  tasks_names.each do |task|
@@ -178,4 +191,4 @@ tasks_names.each do |task|
178
191
  dockerfile_checker ? abort("Dockerfile not found.\nYou must have a Dockerfile file.") : nil
179
192
  compose_checker ? (abort "Compose file not found.\nFor development, you must have a #{dev_compose_file} file.") : nil
180
193
  end
181
- end
194
+ end
@@ -2,7 +2,6 @@
2
2
 
3
3
  require "rake"
4
4
  require_relative "task_helpers/compose_taskhelper"
5
- require "rake/hooks"
6
5
 
7
6
  def task_helper
8
7
  @task_helper ||= TaskHelpers::ComposeTaskhelper.new
@@ -46,19 +45,19 @@ namespace :compose_db do
46
45
  end
47
46
 
48
47
  task :migrate do
49
- puts "Running Migration..."
48
+ puts "Migrating Database..."
50
49
  system "sudo #{compose_command} run --rm web rake db:migrate"
51
- puts "Running Migration... Done!"
50
+ puts "Migrating Database... Done!"
52
51
  end
53
52
 
54
53
  task :seed do
55
- puts "Running Seed..."
54
+ puts "Seeding Database..."
56
55
  system "sudo #{compose_command} run --rm web rake db:seed"
57
- puts "Running Seed... Done!"
56
+ puts "Seeding Database... Done!"
58
57
  end
59
58
 
60
59
  task :reset_setup do
61
- puts "Resettting Database..."
60
+ puts "Resetting Database..."
62
61
  system "sudo #{compose_command} run --rm web rake db:drop"
63
62
  system "sudo #{compose_command} run --rm web rake db:setup"
64
63
  puts "Resetting up Database... Done!"
@@ -74,8 +73,9 @@ namespace :compose_db do
74
73
  end
75
74
 
76
75
  task :force_reset do
77
- puts "Running Compose Down"
76
+ puts "Force Resetting Database..."
78
77
  system "rake compose:down"
79
78
  system "rake compose_db:reset"
79
+ puts "Force Resetting Database... Done!"
80
80
  end
81
81
  end
@@ -3,7 +3,6 @@
3
3
  require "rake"
4
4
  require_relative "task_helpers/compose_taskhelper"
5
5
 
6
-
7
6
  def task_helper
8
7
  @task_helper ||= TaskHelpers::ComposeTaskhelper.new
9
8
  end
@@ -72,34 +71,4 @@ namespace :compose_logs do
72
71
  system "sudo #{compose_command} logs -f"
73
72
  puts "Tailing All Logs... Done!"
74
73
  end
75
-
76
- task :follow_web do
77
- puts "Following Web Logs..."
78
- system "sudo #{compose_command} logs -f web"
79
- puts "Following Web Logs... Done!"
80
- end
81
-
82
- task :follow_db do
83
- puts "Following Database Logs..."
84
- system "sudo #{compose_command} logs -f db"
85
- puts "Following Database Logs... Done!"
86
- end
87
-
88
- task :follow_redis do
89
- puts "Following Redis Logs..."
90
- system "sudo #{compose_command} logs -f redis"
91
- puts "Following Redis Logs... Done!"
92
- end
93
-
94
- task :follow_sidekiq do
95
- puts "Following Sidekiq Logs..."
96
- system "sudo #{compose_command} logs -f sidekiq"
97
- puts "Following Sidekiq Logs... Done!"
98
- end
99
-
100
- task :follow_all do
101
- puts "Following All Logs..."
102
- system "sudo #{compose_command} logs -f"
103
- puts "Following All Logs... Done!"
104
- end
105
74
  end
@@ -1,19 +1,19 @@
1
1
  # frozen_string_literal:true
2
2
 
3
- require 'rake'
4
- require_relative 'task_helpers/compose_taskhelper'
5
-
3
+ require "rake"
4
+ require_relative "task_helpers/compose_taskhelper"
6
5
 
7
6
  def tasks_names
8
- @tasks_names = %w[install build up down restart clean_all clean_volumes clean_orphans clean_images clean_networks clean_stopped]
7
+ @tasks_names = %w[install build up down restart clean_all clean_volumes clean_orphans clean_images clean_networks
8
+ clean_stopped]
9
9
  end
10
10
 
11
11
  def namesp
12
- @namesp = 'compose_prod'
12
+ @namesp = "compose_prod"
13
13
  end
14
14
 
15
15
  def compose_file
16
- @compose_file ||= 'docker-compose.prod.yml'
16
+ @compose_file ||= "docker-compose.prod.yml"
17
17
  end
18
18
 
19
19
  def task_helper
@@ -26,179 +26,208 @@ end
26
26
 
27
27
  def ask(question)
28
28
  puts question
29
- STDIN.gets.chomp
29
+ $stdin.gets.chomp
30
30
  end
31
31
 
32
32
  namespace :compose_prod do
33
33
  task :check_if_file_exists do
34
34
  puts "Checking if docker-compose.prod.yml exists"
35
35
  raise ComposeError unless File.exist?(file)
36
+
36
37
  puts "Checking if docker-compose.prod.yml exists... Done!"
37
38
  end
38
39
 
39
40
  task :install do
40
41
  puts "Installing Blockchain and Database Containers \nWARNING: This will delete all your data, and you are running this in production"
41
42
  # ask in terminal if you want to continue
42
- choice = ask('Are you sure you want to continue? (y/n)')
43
- if choice == 'y'
44
- puts 'Installing Blockchain and Database Containers'
43
+ choice = ask("Are you sure you want to continue? (y/n)")
44
+ if choice == "y"
45
+ puts "Installing Blockchain and Database Containers"
45
46
  system "sudo #{compose_command} -f docker-compose.prod.yml build"
46
- puts 'Creating Database'
47
+ puts "Creating Database"
47
48
  system "sudo #{compose_command} -f docker-compose.prod.yml run --rm web rails db:create"
48
- puts 'Migrating Database'
49
+ puts "Migrating Database"
49
50
  system "sudo #{compose_command} -f docker-compose.prod.yml run --rm web rails db:migrate"
50
- puts 'Seeding Database'
51
+ puts "Seeding Database"
51
52
  system "sudo #{compose_command} -f docker-compose.prod.yml run --rm web rails db:seed"
52
- puts 'Stopping Containers'
53
+ puts "Stopping Containers"
53
54
  system "sudo #{compose_command} -f docker-compose.prod.yml down"
54
- puts 'Installing Blockchain and Database Containers... Done!'
55
- puts 'This already setup your database with some initial values'
56
- puts 'Start the containers with command: rake compose_prod:up'
57
- puts 'Stop the containers with command: rake compose_prod:down'
58
- puts 'Restart the containers with command: rake compose_prod:restart'
59
- puts 'Clean up the containers with command: rake compose_prod:clean_all'
60
- puts 'Build the containers againg with command: rake compose_prod:build'
61
- puts 'rake compose_db_prod command documentation at README.md to see database commands usage examples'
62
- puts 'See the production log files in Rails default logs folder when using compose_prod:up'
63
- puts 'Alternatively, you can use rake compose_prod_logs:all to see all logs'
64
- puts 'Read documentation for more compose_db_prod, compose_prod_logs, and compose_prod commands'
65
- puts '-----------------------------------------------------------------------------------'
66
- puts 'Access the web server on port 80.'
67
- puts 'http://localhost'
68
- puts 'Look at README.md for more details.'
55
+ puts "Installing Blockchain and Database Containers... Done!"
56
+ puts "This already setup your database with some initial values"
57
+ puts "Start the containers with command: rake compose_prod:up"
58
+ puts "Stop the containers with command: rake compose_prod:down"
59
+ puts "Restart the containers with command: rake compose_prod:restart"
60
+ puts "Clean up the containers with command: rake compose_prod:clean_all"
61
+ puts "Build the containers againg with command: rake compose_prod:build"
62
+ puts "rake compose_db_prod command documentation at README.md to see database commands usage examples"
63
+ puts "See the production log files in Rails default logs folder when using compose_prod:up"
64
+ puts "Alternatively, you can use rake compose_prod_logs:all to see all logs"
65
+ puts "Read documentation for more compose_db_prod, compose_prod_logs, and compose_prod commands"
66
+ puts "-----------------------------------------------------------------------------------"
67
+ puts "Access the web server on port 80."
68
+ puts "http://localhost"
69
+ puts "Look at README.md for more details."
69
70
  else
70
- puts 'Installation cancelled'
71
+ puts "Installation cancelled"
71
72
  end
72
- puts '-----------------------------------------------------------------------------------'
73
+ puts "-----------------------------------------------------------------------------------"
73
74
  end
74
75
 
75
76
  task :build do
76
77
  puts "Building Compose... WARNING: you are running this in production"
77
78
  # ask in terminal if you want to continue
78
- choice = ask('Are you sure you want to continue? (y/n)')
79
- if choice == 'y'
80
- puts 'Building Compose...'
79
+ choice = ask("Are you sure you want to continue? (y/n)")
80
+ if choice == "y"
81
+ puts "Building Compose..."
81
82
  system "sudo #{compose_command} -f docker-compose.prod.yml build"
82
- puts 'Building Compose... Done!'
83
+ puts "Building Compose... Done!"
83
84
  else
84
- puts 'Build cancelled'
85
+ puts "Build cancelled"
85
86
  end
86
- puts '-----------------------------------------------------------------------------------'
87
+ puts "-----------------------------------------------------------------------------------"
87
88
  end
88
89
 
89
90
  task :up do
90
- puts 'Running Compose... WARNING: you are running this in production'
91
+ puts "Running Compose... WARNING: you are running this in production"
91
92
  # ask in terminal if you want to continue
92
- choice = ask('Are you sure you want to continue? (y/n)')
93
- if choice == 'y'
94
- puts 'Running Compose...'
93
+ choice = ask("Are you sure you want to continue? (y/n)")
94
+ if choice == "y"
95
+ puts "Running Compose..."
95
96
  system "sudo #{compose_command} -f docker-compose.prod.yml up -d --remove-orphans"
96
- puts 'Running Compose... Done!'
97
+ puts "Running Compose... Done!"
97
98
  else
98
- puts 'Running cancelled'
99
+ puts "Running cancelled"
99
100
  end
100
- puts '-----------------------------------------------------------------------------------'
101
+ puts "-----------------------------------------------------------------------------------"
101
102
  end
102
103
 
103
104
  task :down do
104
- puts 'Stopping Compose... WARNING: you are running this in production'
105
+ puts "Stopping Compose... WARNING: you are running this in production"
105
106
  # ask in terminal if you want to continue
106
- choice = ask('Are you sure you want to continue? (y/n)')
107
- if choice == 'y'
108
- puts 'Stopping Compose...'
107
+ choice = ask("Are you sure you want to continue? (y/n)")
108
+ if choice == "y"
109
+ puts "Stopping Compose..."
109
110
  system "sudo #{compose_command} -f docker-compose.prod.yml down"
110
- puts 'Stopping Compose... Done!'
111
+ puts "Stopping Compose... Done!"
111
112
  else
112
- puts 'Stopping cancelled'
113
+ puts "Stopping cancelled"
113
114
  end
114
- puts '-----------------------------------------------------------------------------------'
115
+ puts "-----------------------------------------------------------------------------------"
115
116
  end
116
117
 
117
118
  task :restart do
118
- puts 'Restarting Compose... WARNING: you are running this in production'
119
+ puts "Restarting Compose... WARNING: you are running this in production"
119
120
  # ask in terminal if you want to continue
120
- choice = ask('Are you sure you want to continue? (y/n)')
121
- if choice == 'y'
122
- puts 'Restarting Compose...'
121
+ choice = ask("Are you sure you want to continue? (y/n)")
122
+ if choice == "y"
123
+ puts "Restarting Compose..."
123
124
  system "sudo #{compose_command} -f docker-compose.prod.yml restart"
124
- puts 'Restarting Compose... Done!'
125
+ puts "Restarting Compose... Done!"
126
+ else
127
+ puts "Restarting cancelled"
128
+ end
129
+ puts "-----------------------------------------------------------------------------------"
130
+ end
131
+
132
+ task :status do
133
+ puts "Status of Compose... WARNING: you are running this in production"
134
+ # ask in terminal if you want to continue
135
+ choice = ask("Are you sure you want to continue? (y/n)")
136
+ if choice == "y"
137
+ puts "Status of Compose..."
138
+ system "sudo #{compose_command} -f docker-compose.prod.yml ps"
139
+ puts "Status of Compose... Done!"
125
140
  else
126
- puts 'Restarting cancelled'
141
+ puts "Status cancelled"
127
142
  end
128
- puts '-----------------------------------------------------------------------------------'
143
+ puts "-----------------------------------------------------------------------------------"
144
+ end
145
+
146
+ task :shell do
147
+ puts "Opening shell in Compose... WARNING: you are running this in production"
148
+ # ask in terminal if you want to continue
149
+ choice = ask("Are you sure you want to continue? (y/n)")
150
+ if choice == "y"
151
+ puts "Opening shell in Compose..."
152
+ system "sudo #{compose_command} -f docker-compose.prod.yml exec web bash"
153
+ puts "Opening shell in Compose... Done!"
154
+ else
155
+ puts "Opening shell cancelled"
156
+ end
157
+ puts "-----------------------------------------------------------------------------------"
129
158
  end
130
159
 
131
160
  task :clean_all do
132
- puts 'Cleaning Compose... WARNING: you are running this in production'
161
+ puts "Cleaning Compose... WARNING: you are running this in production"
133
162
  # ask in terminal if you want to continue
134
- choice = ask('Are you sure you want to continue? (y/n)')
135
- if choice == 'y'
136
- puts 'Cleaning Compose...'
163
+ choice = ask("Are you sure you want to continue? (y/n)")
164
+ if choice == "y"
165
+ puts "Cleaning Compose..."
137
166
  system "sudo #{compose_command} -f docker-compose.prod.yml down --volumes --remove-orphans"
138
- puts 'Cleaning Compose... Done!'
167
+ puts "Cleaning Compose... Done!"
139
168
  else
140
- puts 'Cleaning cancelled'
169
+ puts "Cleaning cancelled"
141
170
  end
142
- puts '-----------------------------------------------------------------------------------'
171
+ puts "-----------------------------------------------------------------------------------"
143
172
  end
144
173
 
145
174
  task :clean_containers do
146
175
  puts "Cleaning Containers... WARNING: you are running this in production"
147
176
  # ask in terminal if you want to continue
148
- choice = ask('Are you sure you want to continue? (y/n)')
149
- if choice == 'y'
150
- puts 'Stopping Containers'
177
+ choice = ask("Are you sure you want to continue? (y/n)")
178
+ if choice == "y"
179
+ puts "Stopping Containers"
151
180
  system "sudo #{compose_command} -f docker-compose.prod.yml down"
152
- puts 'Stopping Containers... Done!'
153
- puts 'Cleaning Containers...'
181
+ puts "Stopping Containers... Done!"
182
+ puts "Cleaning Containers..."
154
183
  system "sudo #{compose_command} -f docker-compose.prod.yml rm -f"
155
- puts 'Cleaning Containers... Done!'
184
+ puts "Cleaning Containers... Done!"
156
185
  else
157
- puts 'Cleaning cancelled'
186
+ puts "Cleaning cancelled"
158
187
  end
159
- puts '-----------------------------------------------------------------------------------'
188
+ puts "-----------------------------------------------------------------------------------"
160
189
  end
161
190
 
162
191
  task :clean_images do
163
192
  puts "Cleaning Images... WARNING: you are running this in production"
164
193
  # ask in terminal if you want to continue
165
- choice = ask('Are you sure you want to continue? (y/n)')
166
- if choice == 'y'
167
- puts 'Cleaning Images...'
194
+ choice = ask("Are you sure you want to continue? (y/n)")
195
+ if choice == "y"
196
+ puts "Cleaning Images..."
168
197
  system "sudo #{compose_command} -f docker-compose.prod.yml rmi -f"
169
- puts 'Cleaning Images... Done!'
198
+ puts "Cleaning Images... Done!"
170
199
  else
171
- puts 'Cleaning cancelled'
200
+ puts "Cleaning cancelled"
172
201
  end
173
- puts '-----------------------------------------------------------------------------------'
202
+ puts "-----------------------------------------------------------------------------------"
174
203
  end
175
-
204
+
176
205
  task :clean_volumes do
177
206
  puts "Cleaning Volumes... WARNING: you are running this in production"
178
207
  # ask in terminal if you want to continue
179
- choice = ask('Are you sure you want to continue? (y/n)')
180
- if choice == 'y'
181
- puts 'Cleaning Volumes...'
208
+ choice = ask("Are you sure you want to continue? (y/n)")
209
+ if choice == "y"
210
+ puts "Cleaning Volumes..."
182
211
  system "sudo #{compose_command} -f docker-compose.prod.yml down --volumes"
183
- puts 'Cleaning Volumes... Done!'
212
+ puts "Cleaning Volumes... Done!"
184
213
  else
185
- puts 'Cleaning cancelled'
214
+ puts "Cleaning cancelled"
186
215
  end
187
- puts '-----------------------------------------------------------------------------------'
216
+ puts "-----------------------------------------------------------------------------------"
188
217
  end
189
218
 
190
219
  task :clean_orphans do
191
220
  puts "Cleaning Orphans... WARNING: you are running this in production"
192
221
  # ask in terminal if you want to continue
193
- choice = ask('Are you sure you want to continue? (y/n)')
194
- if choice == 'y'
195
- puts 'Cleaning Orphans...'
222
+ choice = ask("Are you sure you want to continue? (y/n)")
223
+ if choice == "y"
224
+ puts "Cleaning Orphans..."
196
225
  system "sudo #{compose_command} -f docker-compose.prod.yml down --remove-orphans"
197
- puts 'Cleaning Orphans... Done!'
226
+ puts "Cleaning Orphans... Done!"
198
227
  else
199
- puts 'Cleaning cancelled'
228
+ puts "Cleaning cancelled"
200
229
  end
201
- puts '-----------------------------------------------------------------------------------'
230
+ puts "-----------------------------------------------------------------------------------"
202
231
  end
203
232
  end
204
233
 
@@ -207,7 +236,7 @@ def compose_checker
207
236
  end
208
237
 
209
238
  def dockerfile_checker
210
- !File.exist?('Dockerfile')
239
+ !File.exist?("Dockerfile")
211
240
  end
212
241
 
213
242
  tasks_names.each do |task|
@@ -217,5 +246,3 @@ tasks_names.each do |task|
217
246
  compose_checker ? (abort "Compose file not found.\nFor development, you must have a #{compose_file} file.") : nil
218
247
  end
219
248
  end
220
-
221
-
@@ -3,7 +3,6 @@
3
3
  require "rake"
4
4
  require_relative "task_helpers/compose_taskhelper"
5
5
 
6
-
7
6
  def task_helper
8
7
  @task_helper ||= TaskHelpers::ComposeTaskhelper.new
9
8
  end
@@ -1,21 +1,25 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "English"
3
4
  require_relative "taskhelper"
4
5
 
6
+ module TaskHelpers
7
+ class ComposeTaskhelper < TaskHelpers::Taskhelper
8
+ def compose_command
9
+ @compose_comand ||= compose_command_finder
10
+ end
5
11
 
6
- class TaskHelpers::ComposeTaskhelper < TaskHelpers::Taskhelper
7
- def compose_command
8
- @compose_comand ||= compose_command_finder
9
- end
12
+ private
10
13
 
11
- private
12
14
  def compose_command_finder
13
15
  @command = ["docker compose", "docker-compose"]
14
16
  @command.each do |command|
15
17
  system "#{command} --version > /dev/null 2>&1"
16
- return command if $?.success?
17
- command = false unless $?.success?
18
+ return command if $CHILD_STATUS.success?
19
+
20
+ command = false unless $CHILD_STATUS.success?
18
21
  end
19
22
  raise ComposeError unless command == false
20
23
  end
24
+ end
21
25
  end
@@ -9,15 +9,16 @@ module TaskHelpers
9
9
  end
10
10
 
11
11
  private
12
- def dev_error(e)
13
- if env_acceptable?
14
- puts "#{e.class}: #{e.message}"
15
- puts e.backtrace
16
- end
17
- end
18
12
 
19
- def env_acceptable?
20
- Rails.env.development? || Rails.env.test?
21
- end
13
+ def dev_error(e)
14
+ return unless env_acceptable?
15
+
16
+ puts "#{e.class}: #{e.message}"
17
+ puts e.backtrace
18
+ end
19
+
20
+ def env_acceptable?
21
+ Rails.env.development? || Rails.env.test?
22
+ end
22
23
  end
23
24
  end
metadata CHANGED
@@ -1,32 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lucy_dockerunner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - JesusGautamah
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-02-12 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: rake-hooks
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
- description: "This gem is a tool to run docker containers with rake commands, good
28
- for CI/CD and Rails projects. \n It's a wrapper for docker-compose commands and
29
- original code was developed \n by me in the project https://github.com/JesusGautamah/outerspace-blockchain"
11
+ date: 2023-02-13 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: |-
14
+ This gem is a tool to run docker containers with rake commands, good for CI/CD and Rails projects.
15
+ It's a wrapper for docker-compose commands and original code was developed
16
+ by me in the project https://github.com/JesusGautamah/outerspace-blockchain
30
17
  email:
31
18
  - lima.jesuscc@gmail.com
32
19
  executables: []
@@ -39,11 +26,13 @@ files:
39
26
  - CODE_OF_CONDUCT.md
40
27
  - Gemfile
41
28
  - Gemfile.lock
29
+ - LICENSE.md
42
30
  - LICENSE.txt
43
31
  - README.md
44
32
  - Rakefile
45
33
  - lib/lucy_dockerunner.rb
46
34
  - lib/lucy_dockerunner/version.rb
35
+ - lib/rake/hooks.rb
47
36
  - lib/tasks/.keep
48
37
  - lib/tasks/compose.rake
49
38
  - lib/tasks/compose_db.rake
@@ -76,7 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
76
65
  - !ruby/object:Gem::Version
77
66
  version: '0'
78
67
  requirements: []
79
- rubygems_version: 3.4.1
68
+ rubygems_version: 3.3.26
80
69
  signing_key:
81
70
  specification_version: 4
82
71
  summary: This gem is a tool to run docker containers with rake commands, good for