lucy_dockerunner 0.1.9 → 0.2.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: c5982619210e56d52470c5a60eb936282f0e37f958c993c0511c25c546b25004
4
- data.tar.gz: b6a090ac20f0d81b44c2a78c1488ba354ab43d5f261945fb053c43d182d17058
3
+ metadata.gz: 610002a6bab234d3f6d5cbd870b8f395c43113d48dcb67d26110b80b93bb28d9
4
+ data.tar.gz: 79aaece9d75114a6452c2ec02915f9b29e4d1b9e47e7e6fe500627d51277117c
5
5
  SHA512:
6
- metadata.gz: f08537f76a386d8c07cbe474a3297d56851984103a07e8dae69f64585687088b607e2e6ed260e5cf01903462546e5ecec13a4320f0f704bf8f2fd4939b63ae07
7
- data.tar.gz: 253c9000552f954a2522c8104a69e7474b2c88b80691fd713216dbea5cecdd97043956e0a1c3032f9e43999ed9e9805f1b9fcd8174960f7fc53cc1bc3e1806e3
6
+ metadata.gz: 848c449a790e0c97a220210efd39d44b4dbbb495ab713b8f71b5a71578580426465952d33531541e977386ada1d5448007e18c3fd836085c49fe3fbc7826ea86
7
+ data.tar.gz: 070b812c4cdea6fcc8c8ce4239cf0fb3818fe93b69b00aecc36bf531ca3cc48dd99395baa0591c47e899ddf57018399aa2f418c85bb604b934ba4b98d8731ccb
data/CHANGELOG.md CHANGED
@@ -3,3 +3,12 @@
3
3
  ## [0.1.0] - 2023-02-11
4
4
 
5
5
  - Initial release
6
+
7
+ ## [0.2.0] - 2023-06-18
8
+
9
+ - Add support to .env file in tests
10
+ - Set default file to docker-compose.yml and add support to LUCY_FILE environment variable
11
+ - Add support to LUCY_SU environment variable to set superuser command
12
+ - Remove support to docker-compose.prod.yml file
13
+
14
+
data/Gemfile CHANGED
@@ -14,4 +14,6 @@ group :test, :development do
14
14
  gem "rubocop-rake", "~> 0.5"
15
15
  gem "rubocop-rspec", "~> 2.4"
16
16
  gem "simplecov", "~> 0.21"
17
+
18
+ gem "dotenv", "~> 2.7"
17
19
  end
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lucy_dockerunner (0.1.9)
4
+ lucy_dockerunner (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -9,6 +9,7 @@ GEM
9
9
  ast (2.4.2)
10
10
  diff-lcs (1.5.0)
11
11
  docile (1.4.0)
12
+ dotenv (2.8.1)
12
13
  json (2.6.3)
13
14
  parallel (1.22.1)
14
15
  parser (3.2.1.0)
@@ -65,6 +66,7 @@ PLATFORMS
65
66
  x86_64-linux
66
67
 
67
68
  DEPENDENCIES
69
+ dotenv (~> 2.7)
68
70
  lucy_dockerunner!
69
71
  rake
70
72
  rspec (~> 3.0)
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Lucy Dockerunner
2
2
 
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 On Rails projects.
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 projects.
4
4
 
5
5
  [![Gem Version](https://badge.fury.io/rb/lucy_dockerunner.svg)](https://badge.fury.io/rb/lucy_dockerunner)
6
6
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
@@ -8,36 +8,19 @@ Lucy Dockerunner is a Ruby gem that provides a simple wrapper around the Docker
8
8
 
9
9
  Ruby version: >= 2.6.0
10
10
 
11
- This gem version: 0.1.7
11
+ This gem version: 0.2.0
12
12
 
13
13
  ## Dependencies
14
14
 
15
15
  * [Docker](https://www.docker.com/)
16
16
  * [Docker Compose](https://docs.docker.com/compose/)
17
- * [Ruby On Rails](https://rubyonrails.org/) - or any other Ruby project that uses Docker Compose to run the project with specific services.
18
17
 
19
18
  ## Files
20
- This gem uses the following files to run the docker compose services:
21
-
22
- - Dockerfile
23
- - docker-compose.yml - development
24
- - docker-compose.prod.yml - production
25
-
26
- It's important to have .env files separated by environment, for example:
27
- - .env.development
28
- - .env.production
29
-
30
- And remember to add the .env files to the .gitignore file and reference them in the docker-compose.yml and docker-compose.prod.yml files.
19
+ The default file is set to `docker-compose.yml`, but you can change it setting the `LUCY_FILE` environment variable.
31
20
 
32
21
  ## Services
33
- This gem requires the following services names to be included in the docker-compose.yml and docker-compose.prod.yml files:
34
- <!-- db - redis - web - sidekiq -->
35
- * db
36
- * redis
37
- * web
38
- * sidekiq
39
-
40
- ##### more services will be added in the future, for example: mailcatcher, elasticsearch, webpack, etc.
22
+ Check services in `compose.rake` file.
23
+
41
24
  ## Installation
42
25
 
43
26
  You can install the gem by executing:
@@ -49,7 +32,12 @@ Or add it to your Gemfile:
49
32
  gem 'lucy_dockerunner'
50
33
 
51
34
  ## Usage
35
+ If you want to use superuser privileges, you can set the `LUCY_SU` with your superuser command, for example:
36
+
37
+ $ export LUCY_SU="sudo"
38
+ Or use .env file:
52
39
 
40
+ LUCY_SU="sudo"
53
41
  ### Add the following code to your Rakefile to load the tasks
54
42
  ````ruby
55
43
  require 'lucy_dockerunner'
@@ -57,7 +45,7 @@ require 'lucy_dockerunner'
57
45
  LucyDockerunner.load_tasks
58
46
  ````
59
47
 
60
- ## Docker actions
48
+ ## Docker actions(more services in compose.rake file)
61
49
  * `rake compose:install` - build docker compose and migrate the database
62
50
  * `rake compose:build` - build docker compose services
63
51
  * `rake compose:up` - start the docker compose services
@@ -74,24 +62,6 @@ LucyDockerunner.load_tasks
74
62
  * `rake compose:clean_orphans` - clean all docker compose orphans
75
63
  * `rake compose:clean_containers` - clean all docker compose containers
76
64
 
77
- ## Docker Production actions
78
-
79
- * `rake compose_prod:install` - build docker compose and migrate the database
80
- * `rake compose_prod:build` - build docker compose services
81
- * `rake compose_prod:up` - start the docker compose services
82
- * `rake compose_prod:down` - stop the docker compose services
83
- * `rake compose_prod:status` - show the status of the docker compose services
84
- * `rake compose_prod:shell` - open a shell in the web service
85
- * `rake compose_prod:db_detach` - detach the database from the docker compose services
86
- * `rake compose_prod:redis_detach` - detach the redis from the docker compose services
87
- * `rake compose_prod:back_detach` - detach the backend(redis, sidekiq, db) from the docker compose services
88
- * `rake compose_prod:restart` - restart the docker compose services
89
- * `rake compose_prod:clean_all` - clean all docker compose services
90
- * `rake compose_prod:clean_images` - clean all docker compose images
91
- * `rake compose_prod:clean_volumes` - clean all docker compose volumes
92
- * `rake compose_prod:clean_orphans` - clean all docker compose orphans
93
- * `rake compose_prod:clean_containers` - clean all docker compose containers
94
-
95
65
  ## Database actions
96
66
  * `rake compose_db:migrate` - migrate the database
97
67
  * `rake compose_db:reset` - reset the database
@@ -156,4 +126,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
156
126
 
157
127
  ## Code of Conduct
158
128
 
159
- 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).
129
+ 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).
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LucyDockerunner
4
+ class Railtie < ::Rails::Railtie
5
+ rake_tasks do
6
+ Dir[File.join(__dir__, "../tasks", "*.rake")].each { |r| load r }
7
+ end
8
+ end
9
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LucyDockerunner
4
- VERSION = "0.1.9"
4
+ VERSION = "0.2.0"
5
5
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "lucy_dockerunner/version"
4
+ require "lucy_dockerunner/railtie" if defined?(Rails::Railtie)
4
5
 
5
6
  # Main module
6
7
  module LucyDockerunner
@@ -11,8 +11,8 @@ def namesp
11
11
  @namesp = "compose"
12
12
  end
13
13
 
14
- def dev_compose_file
15
- @dev_compose_file ||= "docker-compose.yml"
14
+ def compose_file
15
+ @compose_file ||= ENV.fetch("LUCY_FILE", "docker-compose.yml")
16
16
  end
17
17
 
18
18
  def task_helper
@@ -26,15 +26,15 @@ end
26
26
  namespace :compose do
27
27
  task :install do
28
28
  puts "Installing Blockchain and Database Containers"
29
- system "sudo #{compose_command} build"
29
+ system "#{compose_command} -f #{compose_file} build"
30
30
  puts "Creating Database"
31
- system "sudo #{compose_command} run --rm web rails db:create"
31
+ system "#{compose_command} -f #{compose_file} run --rm web rails db:create"
32
32
  puts "Migrating Database"
33
- system "sudo #{compose_command} run --rm web rails db:migrate"
33
+ system "#{compose_command} -f #{compose_file} run --rm web rails db:migrate"
34
34
  puts "Seeding Database"
35
- system "sudo #{compose_command} run --rm web rails db:seed"
35
+ system "#{compose_command} -f #{compose_file} run --rm web rails db:seed"
36
36
  puts "Stopping Containers"
37
- system "sudo #{compose_command} down"
37
+ system "#{compose_command} -f #{compose_file} down"
38
38
  puts "Installing Blockchain and Database Containers... Done!"
39
39
  puts "This already setup your database with some initial values"
40
40
  puts "Start the containers with command: rake compose:up"
@@ -46,91 +46,85 @@ namespace :compose do
46
46
  puts "rake compose_db command documentation at README.md to see database commands usage examples"
47
47
  puts "See the development and test log files in Rails default logs folder when using compose:up"
48
48
  puts "-----------------------------------------------------------------------------------"
49
- puts "Access the web server on port 80."
50
- puts "http://localhost"
49
+ puts "Access the web server on port docker configured port"
50
+ puts "http://localhost:PORT"
51
51
  puts "Look at README.md for more details."
52
52
  end
53
53
 
54
54
  task :build do
55
55
  puts "Building Compose..."
56
- system "sudo #{compose_command} build"
56
+ system "#{compose_command} -f #{compose_file} build"
57
57
  puts "Building Compose... Done!"
58
58
  end
59
59
 
60
60
  task :up do
61
61
  puts compose_command
62
62
  puts "Running Compose..."
63
- system "sudo #{compose_command} up -d --remove-orphans"
63
+ system "#{compose_command} -f #{compose_file} up -d --remove-orphans"
64
64
  puts "Running Compose... Done!"
65
65
  end
66
66
 
67
67
  task :down do
68
68
  puts "Stopping Compose..."
69
- system "sudo #{compose_command} down"
69
+ system "#{compose_command} -f #{compose_file} down"
70
70
  puts "Stopping Compose... Done!"
71
71
  end
72
-
72
+
73
73
  task :bot_detach do
74
74
  puts "Running Bot Detached..."
75
- system "sudo #{compose_command} up -d bot"
75
+ system "#{compose_command} -f #{compose_file} up -d bot"
76
76
  puts "Running Bot Detached... Done!"
77
77
  end
78
78
 
79
79
  task :telegram_detach do
80
80
  puts "Running Telegram Detached..."
81
- system "sudo #{compose_command} up -d telegram"
81
+ system "#{compose_command} -f #{compose_file} up -d telegram"
82
82
  puts "Running Telegram Detached... Done!"
83
83
  end
84
84
 
85
85
  task :discord_detach do
86
86
  puts "Running Discord Detached..."
87
- system "sudo #{compose_command} up -d discord"
87
+ system "#{compose_command} -f #{compose_file} up -d discord"
88
88
  puts "Running Discord Detached... Done!"
89
89
  end
90
90
 
91
91
  task :nginx_detach do
92
92
  puts "Running Nginx Detached..."
93
- system "sudo #{compose_command} up -d nginx"
93
+ system "#{compose_command} -f #{compose_file} up -d nginx"
94
94
  puts "Running Nginx Detached... Done!"
95
95
  end
96
96
 
97
97
  task :db_detach do
98
98
  puts "Running Database Detached..."
99
- system "sudo #{compose_command} up -d db"
99
+ system "#{compose_command} -f #{compose_file} up -d db"
100
100
  puts "Running Database Detached... Done!"
101
101
  end
102
102
 
103
103
  task :redis_detach do
104
104
  puts "Running Redis Detached..."
105
- system "sudo #{compose_command} up -d redis"
105
+ system "#{compose_command} -f #{compose_file} up -d redis"
106
106
  puts "Running Redis Detached... Done!"
107
107
  end
108
108
 
109
- # task :back_detach do
110
- # puts "Running Backend Detached..."
111
- # system "sudo #{compose_command} up -d --remove-orphans db redis sidekiq"
112
- # puts "Running Backend Detached... Done!"
113
- # end
114
-
115
109
  task :restart do
116
110
  puts "Restarting Compose..."
117
111
  puts "Stopping Compose..."
118
- system "sudo #{compose_command} down"
112
+ system "#{compose_command} -f #{compose_file} down"
119
113
  puts "Stopping Compose... Done!"
120
114
  puts "Running Compose..."
121
- system "sudo #{compose_command} up -d --remove-orphans"
115
+ system "#{compose_command} -f #{compose_file} up -d --remove-orphans"
122
116
  puts "Restarting Compose... Done!"
123
117
  end
124
118
 
125
119
  task :status do
126
120
  puts "Status Compose..."
127
- system "sudo #{compose_command} ps"
121
+ system "#{compose_command} -f #{compose_file} ps"
128
122
  puts "Status Compose... Done!"
129
123
  end
130
124
 
131
125
  task :shell do
132
126
  puts "Running Shell..."
133
- system "sudo #{compose_command} run --rm web bash"
127
+ system "#{compose_command} -f #{compose_file} run --rm web bash"
134
128
  puts "Running Shell... Done!"
135
129
  end
136
130
 
@@ -143,10 +137,10 @@ namespace :compose do
143
137
  task :clean_containers do
144
138
  puts "Cleaning Containers..."
145
139
  puts "Stopping Compose..."
146
- system "sudo #{compose_command} down"
140
+ system "#{compose_command} -f #{compose_file} down"
147
141
  puts "Stopping Compose... Done!"
148
142
  puts "Removing Containers..."
149
- system "sudo #{compose_command} rm -f"
143
+ system "#{compose_command} -f #{compose_file} rm -f"
150
144
  puts "Removing Containers... Done!"
151
145
  puts "Cleaning Containers... Done!"
152
146
  end
@@ -154,10 +148,10 @@ namespace :compose do
154
148
  task :clean_images do
155
149
  puts "Cleaning Images..."
156
150
  puts "Stopping Compose..."
157
- system "sudo #{compose_command} down"
151
+ system "#{compose_command} -f #{compose_file} down"
158
152
  puts "Stopping Compose... Done!"
159
153
  puts "Removing Images..."
160
- system "sudo #{compose_command} rmi -f"
154
+ system "#{compose_command} -f #{compose_file} rmi -f"
161
155
  puts "Removing Images... Done!"
162
156
  puts "Cleaning Images... Done!"
163
157
  end
@@ -165,10 +159,10 @@ namespace :compose do
165
159
  task :clean_volumes do
166
160
  puts "Cleaning Volumes..."
167
161
  puts "Stopping Compose..."
168
- system "sudo #{compose_command} down"
162
+ system "#{compose_command} -f #{compose_file} down"
169
163
  puts "Stopping Compose... Done!"
170
164
  puts "Removing Volumes..."
171
- system "sudo #{compose_command} down -v"
165
+ system "#{compose_command} -f #{compose_file} down -v"
172
166
  puts "Removing Volumes... Done!"
173
167
  puts "Cleaning Volumes... Done!"
174
168
  end
@@ -176,10 +170,10 @@ namespace :compose do
176
170
  task :clean_orphans do
177
171
  puts "Cleaning Networks..."
178
172
  puts "Stopping Compose..."
179
- system "sudo #{compose_command} down"
173
+ system "#{compose_command} -f #{compose_file} down"
180
174
  puts "Stopping Compose... Done!"
181
175
  puts "Removing Networks..."
182
- system "sudo #{compose_command} down --remove-orphans"
176
+ system "#{compose_command} -f #{compose_file} down --remove-orphans"
183
177
  puts "Removing Networks... Done!"
184
178
  puts "Cleaning Networks... Done!"
185
179
  end
@@ -189,16 +183,10 @@ def compose_exist?
189
183
  File.exist?(compose_file)
190
184
  end
191
185
 
192
- def dockerfile_exist?
193
- File.exist?("Dockerfile")
194
- end
195
-
196
186
  tasks_names.each do |task|
197
187
  before_action = "#{namesp}:#{task}"
198
188
  Rake::Task[before_action].enhance do
199
- docker_abort_error = "Dockerfile not found.\nYou must have a Dockerfile file."
200
- compose_abort_error = "Compose file not found.\nYou must have a docker-compose.yml file."
201
- abort(docker_abort_error) unless dockerfile_exist?
189
+ compose_abort_error = "Compose file not found.\nYou must have a #{compose_file} file.\nYou can change the compose file name by setting LUCY_FILE environment variable."
202
190
  abort(compose_abort_error) unless compose_exist?
203
191
  end
204
192
  end
@@ -14,19 +14,19 @@ end
14
14
  namespace :compose_assets do
15
15
  task :precompile do
16
16
  puts "Precompiling Assets..."
17
- system "sudo #{compose_command} run web rake assets:precompile"
17
+ system "#{compose_command} -f #{compose_file} run web rake assets:precompile"
18
18
  puts "Precompiling Assets... Done!"
19
19
  end
20
20
 
21
21
  task :clean do
22
22
  puts "Cleaning Assets..."
23
- system "sudo #{compose_command} run web rake assets:clean"
23
+ system "#{compose_command} -f #{compose_file} run web rake assets:clean"
24
24
  puts "Cleaning Assets... Done!"
25
25
  end
26
26
 
27
27
  task :clobber do
28
28
  puts "Clobbering Assets..."
29
- system "sudo #{compose_command} run web rake assets:clobber"
29
+ system "#{compose_command} -f #{compose_file} run web rake assets:clobber"
30
30
  puts "Clobbering Assets... Done!"
31
31
  end
32
32
  end
@@ -14,61 +14,61 @@ end
14
14
  namespace :compose_db do
15
15
  task :drop do
16
16
  puts "Dropping Database..."
17
- system "sudo #{compose_command} run --rm web rake db:drop"
17
+ system "#{compose_command} -f #{compose_file} run --rm web rake db:drop"
18
18
  puts "Dropping Database... Done!"
19
19
  end
20
20
 
21
21
  task :rollback do
22
22
  puts "Rolling Back Database..."
23
- system "sudo #{compose_command} run --rm web rails db:rollback"
23
+ system "#{compose_command} -f #{compose_file} run --rm web rails db:rollback"
24
24
  puts "Rolling Back Database... Done!"
25
25
  end
26
26
 
27
27
  task :complete_setup do
28
28
  puts "Setting up Database..."
29
- system "sudo #{compose_command} run --rm web rake db:create"
30
- system "sudo #{compose_command} run --rm web rake db:migrate"
31
- system "sudo #{compose_command} run --rm web rake db:seed"
29
+ system "#{compose_command} -f #{compose_file} run --rm web rake db:create"
30
+ system "#{compose_command} -f #{compose_file} run --rm web rake db:migrate"
31
+ system "#{compose_command} -f #{compose_file} run --rm web rake db:seed"
32
32
  puts "Setting up Database... Done!"
33
33
  end
34
34
 
35
35
  task :setup do
36
36
  puts "Setting up and seeding Database..."
37
- system "sudo #{compose_command} run --rm web rake db:setup"
37
+ system "#{compose_command} -f #{compose_file} run --rm web rake db:setup"
38
38
  puts "Setting up and seeding Database... Done!"
39
39
  end
40
40
 
41
41
  task :create do
42
42
  puts "Creating Database..."
43
- system "sudo #{compose_command} run --rm web rake db:create"
43
+ system "#{compose_command} -f #{compose_file} run --rm web rake db:create"
44
44
  puts "Creating Database... Done!"
45
45
  end
46
46
 
47
47
  task :migrate do
48
48
  puts "Migrating Database..."
49
- system "sudo #{compose_command} run --rm web rake db:migrate"
49
+ system "#{compose_command} -f #{compose_file} run --rm web rake db:migrate"
50
50
  puts "Migrating Database... Done!"
51
51
  end
52
52
 
53
53
  task :seed do
54
54
  puts "Seeding Database..."
55
- system "sudo #{compose_command} run --rm web rake db:seed"
55
+ system "#{compose_command} -f #{compose_file} run --rm web rake db:seed"
56
56
  puts "Seeding Database... Done!"
57
57
  end
58
58
 
59
59
  task :reset_setup do
60
60
  puts "Resetting Database..."
61
- system "sudo #{compose_command} run --rm web rake db:drop"
62
- system "sudo #{compose_command} run --rm web rake db:setup"
61
+ system "#{compose_command} -f #{compose_file} run --rm web rake db:drop"
62
+ system "#{compose_command} -f #{compose_file} run --rm web rake db:setup"
63
63
  puts "Resetting up Database... Done!"
64
64
  end
65
65
 
66
66
  task :reset do
67
67
  puts "Resetting Database..."
68
- system "sudo #{compose_command} run --rm web rake db:drop"
69
- system "sudo #{compose_command} run --rm web rake db:create"
70
- system "sudo #{compose_command} run --rm web rake db:migrate"
71
- system "sudo #{compose_command} run --rm web rake db:seed"
68
+ system "#{compose_command} -f #{compose_file} run --rm web rake db:drop"
69
+ system "#{compose_command} -f #{compose_file} run --rm web rake db:create"
70
+ system "#{compose_command} -f #{compose_file} run --rm web rake db:migrate"
71
+ system "#{compose_command} -f #{compose_file} run --rm web rake db:seed"
72
72
  puts "Resetting Compose... Done!"
73
73
  end
74
74
 
@@ -14,109 +14,109 @@ end
14
14
  namespace :compose_logs do
15
15
  task :discord do
16
16
  puts "Showing Discord Logs..."
17
- system "sudo #{compose_command} logs discord"
17
+ system "#{compose_command} -f #{compose_file} logs discord"
18
18
  puts "Showing Discord Logs... Done!"
19
19
  end
20
-
20
+
21
21
  task :telegram do
22
22
  puts "Showing Telegram Logs..."
23
- system "sudo #{compose_command} logs telegram"
23
+ system "#{compose_command} -f #{compose_file} logs telegram"
24
24
  puts "Showing Telegram Logs... Done!"
25
25
  end
26
26
 
27
27
  task :bot do
28
28
  puts "Showing Bot Logs..."
29
- system "sudo #{compose_command} logs bot"
29
+ system "#{compose_command} -f #{compose_file} logs bot"
30
30
  puts "Showing Bot Logs... Done!"
31
31
  end
32
32
 
33
33
  task :nginx do
34
34
  puts "Showing Nginx Logs..."
35
- system "sudo #{compose_command} logs nginx"
35
+ system "#{compose_command} -f #{compose_file} logs nginx"
36
36
  puts "Showing Nginx Logs... Done!"
37
37
  end
38
38
 
39
39
  task :web do
40
40
  puts "Showing Web Logs..."
41
- system "sudo #{compose_command} logs web"
41
+ system "#{compose_command} -f #{compose_file} logs web"
42
42
  puts "Showing Web Logs... Done!"
43
43
  end
44
44
 
45
45
  task :db do
46
46
  puts "Showing Database Logs..."
47
- system "sudo #{compose_command} logs db"
47
+ system "#{compose_command} -f #{compose_file} logs db"
48
48
  puts "Showing Database Logs... Done!"
49
49
  end
50
50
 
51
51
  task :redis do
52
52
  puts "Showing Redis Logs..."
53
- system "sudo #{compose_command} logs redis"
53
+ system "#{compose_command} -f #{compose_file} logs redis"
54
54
  puts "Showing Redis Logs... Done!"
55
55
  end
56
56
 
57
57
  task :sidekiq do
58
58
  puts "Showing Sidekiq Logs..."
59
- system "sudo #{compose_command} logs sidekiq"
59
+ system "#{compose_command} -f #{compose_file} logs sidekiq"
60
60
  puts "Showing Sidekiq Logs... Done!"
61
61
  end
62
62
 
63
63
  task :all do
64
64
  puts "Showing All Logs..."
65
- system "sudo #{compose_command} logs"
65
+ system "#{compose_command} -f #{compose_file} logs"
66
66
  puts "Showing All Logs... Done!"
67
67
  end
68
68
 
69
69
  task :tail_discord do
70
70
  puts "Tailing Discord Logs..."
71
- system "sudo #{compose_command} logs -f discord"
71
+ system "#{compose_command} -f #{compose_file} logs -f discord"
72
72
  puts "Tailing Discord Logs... Done!"
73
73
  end
74
74
 
75
75
  task :tail_telegram do
76
76
  puts "Tailing Telegram Logs..."
77
- system "sudo #{compose_command} logs -f telegram"
77
+ system "#{compose_command} -f #{compose_file} logs -f telegram"
78
78
  puts "Tailing Telegram Logs... Done!"
79
79
  end
80
80
 
81
81
  task :tail_bot do
82
82
  puts "Tailing Bot Logs..."
83
- system "sudo #{compose_command} logs -f bot"
83
+ system "#{compose_command} -f #{compose_file} logs -f bot"
84
84
  puts "Tailing Bot Logs... Done!"
85
85
  end
86
86
 
87
87
  task :tail_nginx do
88
88
  puts "Tailing Nginx Logs..."
89
- system "sudo #{compose_command} logs -f nginx"
89
+ system "#{compose_command} -f #{compose_file} logs -f nginx"
90
90
  puts "Tailing Nginx Logs... Done!"
91
91
  end
92
92
 
93
93
  task :tail_web do
94
94
  puts "Tailing Web Logs..."
95
- system "sudo #{compose_command} logs -f web"
95
+ system "#{compose_command} -f #{compose_file} logs -f web"
96
96
  puts "Tailing Web Logs... Done!"
97
97
  end
98
98
 
99
99
  task :tail_db do
100
100
  puts "Tailing Database Logs..."
101
- system "sudo #{compose_command} logs -f db"
101
+ system "#{compose_command} -f #{compose_file} logs -f db"
102
102
  puts "Tailing Database Logs... Done!"
103
103
  end
104
104
 
105
105
  task :tail_redis do
106
106
  puts "Tailing Redis Logs..."
107
- system "sudo #{compose_command} logs -f redis"
107
+ system "#{compose_command} -f #{compose_file} logs -f redis"
108
108
  puts "Tailing Redis Logs... Done!"
109
109
  end
110
110
 
111
111
  task :tail_sidekiq do
112
112
  puts "Tailing Sidekiq Logs..."
113
- system "sudo #{compose_command} logs -f sidekiq"
113
+ system "#{compose_command} -f #{compose_file} logs -f sidekiq"
114
114
  puts "Tailing Sidekiq Logs... Done!"
115
115
  end
116
116
 
117
117
  task :tail_all do
118
118
  puts "Tailing All Logs..."
119
- system "sudo #{compose_command} logs -f"
119
+ system "#{compose_command} -f #{compose_file} logs -f"
120
120
  puts "Tailing All Logs... Done!"
121
121
  end
122
122
  end
@@ -14,7 +14,7 @@ end
14
14
  namespace :compose_test do
15
15
  task :all do
16
16
  puts "Running Test..."
17
- system "sudo #{compose_command} run --rm web bundle exec rspec"
17
+ system "#{compose_command} -f #{compose_file} run --rm web bundle exec rspec"
18
18
  puts "Running Test... Done!"
19
19
  end
20
20
 
@@ -23,49 +23,49 @@ namespace :compose_test do
23
23
  system "rake compose:clean_all"
24
24
  puts "Cleaning Compose Images... Done!"
25
25
  puts "Running Tests ..."
26
- system "sudo #{compose_command} run --rm web bundle exec rspec"
26
+ system "#{compose_command} -f #{compose_file} run --rm web bundle exec rspec"
27
27
  puts "Running Clean Test... Done!"
28
28
  end
29
29
 
30
30
  task :controllers do
31
31
  puts "Running Controllers Test..."
32
- system "sudo #{compose_command} run --rm web bundle exec rspec spec/controllers"
32
+ system "#{compose_command} -f #{compose_file} run --rm web bundle exec rspec spec/controllers"
33
33
  puts "Running Controllers Test... Done!"
34
34
  end
35
35
 
36
36
  task :models do
37
37
  puts "Running Models Test..."
38
- system "sudo #{compose_command} run --rm web bundle exec rspec spec/models"
38
+ system "#{compose_command} -f #{compose_file} run --rm web bundle exec rspec spec/models"
39
39
  puts "Running Models Test... Done!"
40
40
  end
41
41
 
42
42
  task :requests do
43
43
  puts "Running Requests Test..."
44
- system "sudo #{compose_command} run --rm web bundle exec rspec spec/requests"
44
+ system "#{compose_command} -f #{compose_file} run --rm web bundle exec rspec spec/requests"
45
45
  puts "Running Requests Test... Done!"
46
46
  end
47
47
 
48
48
  task :helpers do
49
49
  puts "Running Helpers Test..."
50
- system "sudo #{compose_command} run --rm web bundle exec rspec spec/helpers"
50
+ system "#{compose_command} -f #{compose_file} run --rm web bundle exec rspec spec/helpers"
51
51
  puts "Running Helpers Test... Done!"
52
52
  end
53
53
 
54
54
  task :mailers do
55
55
  puts "Running Mailers Test..."
56
- system "sudo #{compose_command} run --rm web bundle exec rspec spec/mailers"
56
+ system "#{compose_command} -f #{compose_file} run --rm web bundle exec rspec spec/mailers"
57
57
  puts "Running Mailers Test... Done!"
58
58
  end
59
59
 
60
60
  task :routing do
61
61
  puts "Running Routing Test..."
62
- system "sudo #{compose_command} run --rm web bundle exec rspec spec/routing"
62
+ system "#{compose_command} -f #{compose_file} run --rm web bundle exec rspec spec/routing"
63
63
  puts "Running Routing Test... Done!"
64
64
  end
65
65
 
66
66
  task :views do
67
67
  puts "Running Views Test..."
68
- system "sudo #{compose_command} run --rm web bundle exec rspec spec/views"
68
+ system "#{compose_command} -f #{compose_file} run --rm web bundle exec rspec spec/views"
69
69
  puts "Running Views Test... Done!"
70
70
  end
71
71
  end
@@ -7,19 +7,23 @@ module TaskHelpers
7
7
  # ComposeTaskhelper
8
8
  class ComposeTaskhelper < TaskHelpers::Taskhelper
9
9
  def compose_command
10
- @compose_command ||= compose_command_finder
10
+ @compose_command ||= find_compose_command
11
11
  end
12
12
 
13
13
  private
14
14
 
15
- def compose_command_finder
15
+ def find_compose_command
16
+ superuser = ENV.fetch("LUCY_SU", false)
16
17
  @command = ["docker compose", "docker-compose"]
18
+ @command = ["#{superuser} docker compose", "#{superuser} docker-compose"] if @superuser != false
19
+
17
20
  @command.each do |command|
18
21
  system "#{command} --version > /dev/null 2>&1"
22
+ puts "YOU'RE USING SUPERUSER PRIVILEGES" if superuser != false
23
+ puts "Using #{command}..." if $CHILD_STATUS.success?
19
24
  return command if $CHILD_STATUS.success?
20
25
 
21
- command = false
22
- raise ComposeError if command == false
26
+ raise ComposeError
23
27
  end
24
28
  end
25
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lucy_dockerunner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - JesusGautamah
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-03-26 00:00:00.000000000 Z
11
+ date: 2023-06-18 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |-
14
14
  This gem is a tool to run docker containers with rake commands, good for CI/CD and Rails projects.
@@ -30,13 +30,13 @@ files:
30
30
  - README.md
31
31
  - Rakefile
32
32
  - lib/lucy_dockerunner.rb
33
+ - lib/lucy_dockerunner/railtie.rb
33
34
  - lib/lucy_dockerunner/version.rb
34
35
  - lib/tasks/.keep
35
36
  - lib/tasks/compose.rake
36
37
  - lib/tasks/compose_assets.rake
37
38
  - lib/tasks/compose_db.rake
38
39
  - lib/tasks/compose_logs.rake
39
- - lib/tasks/compose_prod.rake
40
40
  - lib/tasks/compose_test.rake
41
41
  - lib/tasks/task_helpers/compose_taskhelper.rb
42
42
  - lib/tasks/task_helpers/taskhelper.rb
@@ -65,7 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
65
65
  - !ruby/object:Gem::Version
66
66
  version: '0'
67
67
  requirements: []
68
- rubygems_version: 3.4.6
68
+ rubygems_version: 3.0.9
69
69
  signing_key:
70
70
  specification_version: 4
71
71
  summary: This gem is a tool to run docker containers with rake commands, good for
@@ -1,251 +0,0 @@
1
- # frozen_string_literal:true
2
-
3
- require "rake"
4
- require_relative "task_helpers/compose_taskhelper"
5
-
6
- def tasks_names
7
- @tasks_names = %w[install build up down restart clean_all clean_volumes clean_orphans clean_images]
8
- end
9
-
10
- def namesp
11
- @namesp = "compose_prod"
12
- end
13
-
14
- def compose_file
15
- @compose_file ||= "docker-compose.prod.yml"
16
- end
17
-
18
- def task_helper
19
- @task_helper ||= TaskHelpers::ComposeTaskhelper.new
20
- end
21
-
22
- def compose_command
23
- @compose_command ||= task_helper.compose_command
24
- end
25
-
26
- def ask(question)
27
- puts question
28
- $stdin.gets.chomp
29
- end
30
-
31
- namespace :compose_prod do
32
- task :check_if_file_exists do
33
- puts "Checking if docker-compose.prod.yml exists"
34
- raise ComposeError unless File.exist?(file)
35
-
36
- puts "Checking if docker-compose.prod.yml exists... Done!"
37
- end
38
-
39
- task :install do
40
- puts "Installing Blockchain and Database Containers \n
41
- WARNING: This will delete all your data, and you are running this in production"
42
- # ask in terminal if you want to continue
43
- choice = ask("Are you sure you want to continue? (y/n)")
44
- if choice == "y"
45
- puts "Installing Blockchain and Database Containers"
46
- system "sudo #{compose_command} -f docker-compose.prod.yml build"
47
- puts "Creating Database"
48
- system "sudo #{compose_command} -f docker-compose.prod.yml run --rm web rails db:create"
49
- puts "Migrating Database"
50
- system "sudo #{compose_command} -f docker-compose.prod.yml run --rm web rails db:migrate"
51
- puts "Seeding Database"
52
- system "sudo #{compose_command} -f docker-compose.prod.yml run --rm web rails db:seed"
53
- puts "Stopping Containers"
54
- system "sudo #{compose_command} -f docker-compose.prod.yml down"
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."
70
- else
71
- puts "Installation cancelled"
72
- end
73
- puts "-----------------------------------------------------------------------------------"
74
- end
75
-
76
- task :build do
77
- puts "Building Compose... WARNING: you are running this in production"
78
- # ask in terminal if you want to continue
79
- choice = ask("Are you sure you want to continue? (y/n)")
80
- if choice == "y"
81
- puts "Building Compose..."
82
- system "sudo #{compose_command} -f docker-compose.prod.yml build"
83
- puts "Building Compose... Done!"
84
- else
85
- puts "Build cancelled"
86
- end
87
- puts "-----------------------------------------------------------------------------------"
88
- end
89
-
90
- task :up do
91
- puts "Running Compose... WARNING: you are running this in production"
92
- # ask in terminal if you want to continue
93
- choice = ask("Are you sure you want to continue? (y/n)")
94
- if choice == "y"
95
- puts "Running Compose..."
96
- system "sudo #{compose_command} -f docker-compose.prod.yml up -d --remove-orphans"
97
- puts "Running Compose... Done!"
98
- else
99
- puts "Running cancelled"
100
- end
101
- puts "-----------------------------------------------------------------------------------"
102
- end
103
-
104
- task :down do
105
- puts "Stopping Compose... WARNING: you are running this in production"
106
- # ask in terminal if you want to continue
107
- choice = ask("Are you sure you want to continue? (y/n)")
108
- if choice == "y"
109
- puts "Stopping Compose..."
110
- system "sudo #{compose_command} -f docker-compose.prod.yml down"
111
- puts "Stopping Compose... Done!"
112
- else
113
- puts "Stopping cancelled"
114
- end
115
- puts "-----------------------------------------------------------------------------------"
116
- end
117
-
118
- task :restart do
119
- puts "Restarting Compose... WARNING: you are running this in production"
120
- # ask in terminal if you want to continue
121
- choice = ask("Are you sure you want to continue? (y/n)")
122
- if choice == "y"
123
- puts "Restarting Compose..."
124
- system "sudo #{compose_command} -f docker-compose.prod.yml restart"
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!"
140
- else
141
- puts "Status cancelled"
142
- end
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 "-----------------------------------------------------------------------------------"
158
- end
159
-
160
- task :clean_all do
161
- puts "Cleaning Compose... WARNING: you are running this in production"
162
- # ask in terminal if you want to continue
163
- choice = ask("Are you sure you want to continue? (y/n)")
164
- if choice == "y"
165
- puts "Cleaning Compose..."
166
- system "sudo #{compose_command} -f docker-compose.prod.yml down --volumes --remove-orphans"
167
- puts "Cleaning Compose... Done!"
168
- else
169
- puts "Cleaning cancelled"
170
- end
171
- puts "-----------------------------------------------------------------------------------"
172
- end
173
-
174
- task :clean_containers do
175
- puts "Cleaning Containers... WARNING: you are running this in production"
176
- # ask in terminal if you want to continue
177
- choice = ask("Are you sure you want to continue? (y/n)")
178
- if choice == "y"
179
- puts "Stopping Containers"
180
- system "sudo #{compose_command} -f docker-compose.prod.yml down"
181
- puts "Stopping Containers... Done!"
182
- puts "Cleaning Containers..."
183
- system "sudo #{compose_command} -f docker-compose.prod.yml rm -f"
184
- puts "Cleaning Containers... Done!"
185
- else
186
- puts "Cleaning cancelled"
187
- end
188
- puts "-----------------------------------------------------------------------------------"
189
- end
190
-
191
- task :clean_images do
192
- puts "Cleaning Images... WARNING: you are running this in production"
193
- # ask in terminal if you want to continue
194
- choice = ask("Are you sure you want to continue? (y/n)")
195
- if choice == "y"
196
- puts "Cleaning Images..."
197
- system "sudo #{compose_command} -f docker-compose.prod.yml rmi -f"
198
- puts "Cleaning Images... Done!"
199
- else
200
- puts "Cleaning cancelled"
201
- end
202
- puts "-----------------------------------------------------------------------------------"
203
- end
204
-
205
- task :clean_volumes do
206
- puts "Cleaning Volumes... WARNING: you are running this in production"
207
- # ask in terminal if you want to continue
208
- choice = ask("Are you sure you want to continue? (y/n)")
209
- if choice == "y"
210
- puts "Cleaning Volumes..."
211
- system "sudo #{compose_command} -f docker-compose.prod.yml down --volumes"
212
- puts "Cleaning Volumes... Done!"
213
- else
214
- puts "Cleaning cancelled"
215
- end
216
- puts "-----------------------------------------------------------------------------------"
217
- end
218
-
219
- task :clean_orphans do
220
- puts "Cleaning Orphans... WARNING: you are running this in production"
221
- # ask in terminal if you want to continue
222
- choice = ask("Are you sure you want to continue? (y/n)")
223
- if choice == "y"
224
- puts "Cleaning Orphans..."
225
- system "sudo #{compose_command} -f docker-compose.prod.yml down --remove-orphans"
226
- puts "Cleaning Orphans... Done!"
227
- else
228
- puts "Cleaning cancelled"
229
- end
230
- puts "-----------------------------------------------------------------------------------"
231
- end
232
- end
233
-
234
- def compose_exist?
235
- File.exist?(compose_file)
236
- end
237
-
238
- def dockerfile_exist?
239
- File.exist?("Dockerfile")
240
- end
241
-
242
- tasks_names.each do |task|
243
- before_action = "#{namesp}:#{task}"
244
- Rake::Task[before_action].enhance do
245
- docker_abort_error = "Dockerfile not found.\nYou must have a Dockerfile file."
246
- compose_abort_error = "Compose file not found.\nYou must have a docker-compose.prod.yml file."
247
- abort(docker_abort_error) unless dockerfile_exist?
248
- abort(compose_abort_error) unless compose_exist?
249
- end
250
- end
251
-