dokkustrano 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f6aa8fa86d37528f383f054151ede08d2ed7ee843ef4b2d4dedbf9df569ce70f
4
+ data.tar.gz: 6e6778de1eada6782248bd23865d48c2ce4261a267f7107eb68b929551bfb3b5
5
+ SHA512:
6
+ metadata.gz: 8331bbefa273f54ae550013b8ac135f4676ac847e14d838f3f9f044e766d0d1968962b9c41edb1592235d4e29966b264106f0ef42b8c0a28502f82d9bfda1e8f
7
+ data.tar.gz: 301f2781c3e8b281fbe93225fafc933ed6904183d971356e46a1ab0009b51620f4f783f3813a4026ff847468b4aa9c311978c95989d72d2fe0cc6f1b7306e625
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ *.gem
2
+ *.swp
3
+ .bundle
4
+ .ruby-version
5
+ Gemfile.lock
6
+ tmp/
7
+ vendor/
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ # Latest versions of rake don't support Ruby < 2.2
6
+ if Gem::Requirement.new("< 2.2").satisfied_by?(Gem::Version.new(RUBY_VERSION))
7
+ gem 'rake', '< 13.0.0'
8
+ end
data/README.md ADDED
@@ -0,0 +1,124 @@
1
+ # Dokkustrano: A deployment tool built on Ruby, Rake, and SSH to connect with Dokku servers
2
+
3
+ Dokkustrano is a library for connecting with Dokku servers which run Ruby on Rails applications.
4
+
5
+ Once installed on a Rails project, Capistrano gives you rake tasks to perform several operations from your command line.
6
+
7
+ ```
8
+ $ cd my-dokkustrano-enabled-rails-project
9
+ $ rails dokku:console[APP_NAME]
10
+ ```
11
+
12
+ When you run [Rake](https://github.com/ruby/rake) tasks tasks from the `dokku` namespace, Dokkustrano dutifully connects to your server via SSH and executes the necessary actions.
13
+
14
+ ## Installation
15
+
16
+ ### Requirements
17
+
18
+ * Ruby version 2.0 or higher on your local machine.
19
+ * [Bundler](http://bundler.io), along with a Gemfile for your project.
20
+
21
+ ### Setup
22
+
23
+ Add the gem to your project's Gemfile:
24
+
25
+ ```ruby
26
+ gem 'dokkustrano'
27
+ ```
28
+
29
+ Then run Bundler to ensure Capistrano is downloaded and installed:
30
+
31
+ ``` sh
32
+ bundle install
33
+ ```
34
+
35
+ Dokkustrano requires you to have configured a SHH host with the server in which Dokku will be running. By default, the host `dokku` will be used, but it can be changed using an initializer (`config/initializers/dokkustrano.rb`):
36
+
37
+ ```ruby
38
+ require 'dokkustrano'
39
+
40
+ Dokkustrano.configure do |configuration|
41
+ configuration.host_name = 'dokku-server'
42
+ end
43
+ ```
44
+
45
+ ## Available commands
46
+
47
+ These are all the Rake tasks which are provided by this gem:
48
+ ```ruby
49
+ rails dokku:console[app] # Connect with Dokku app and open a Rails console
50
+ rails dokku:data:export[app] # Download dump from Dokku given app
51
+ rails dokku:data:import[app,path] # Import dump to given Dokku app
52
+ rails dokku:postgres:change_version[service,version] # Change PostgreSQL version for given Dokku database service
53
+ rails dokku:postgres:console[service] # Connect with PostgreSQL console for given Dokku database service
54
+ rails dokku:ssl:cleanup[app] # Cleanup SSL for given Dokku app
55
+ rails dokku:ssl:enable[app] # Enable SSL for given Dokku app
56
+ rails dokku:ssl:renew[app] # Auto-renew SSL for given Dokku app
57
+ ```
58
+
59
+ ## Custom commands
60
+
61
+ You can define new actions yourself by writing Rake tasks, which are really simple to make. Here're some examples:
62
+
63
+ ```ruby
64
+ namespace :dokku do
65
+ desc 'Enter into container for given Dokku app'
66
+ task :enter, [:app] => :environment do |t, args|
67
+ include Dokkustrano::Validations
68
+
69
+ validate_argument!(args, :app)
70
+
71
+ sh "ssh -t #{Dokkustrano.configuration.host_name} 'dokku config:show #{args[:app]}'"
72
+ end
73
+ end
74
+ ```
75
+
76
+ ```ruby
77
+ namespace :dokku do
78
+ namespace :postgres do
79
+ desc 'Restart PostgreSQL for given Dokku service'
80
+ task :restart, [:service] => :environment do |t, args|
81
+ include Dokkustrano::Validations
82
+
83
+ validate_argument!(args, :service)
84
+
85
+ sh "ssh -t #{Dokkustrano.configuration.host_name} 'dokku postgres:restart #{args[:service]}'"
86
+ end
87
+ end
88
+ end
89
+ ```
90
+
91
+ As it can be seen in the previous examples, if you include the `Dokkustrano::Validations` module, you can use the `validate_argument!` method to validate arguments presence.
92
+
93
+ ```ruby
94
+ validate_argument!(args, :app)
95
+ validate_argument!(args, :version, :second) # => indicates that the second argument is missing if that's the case
96
+ ```
97
+
98
+ ## Bugs report
99
+
100
+ Please, fill an issue with a reproduction of the error in order to report a bug.
101
+
102
+ If you think you may have discovered a security vulnerability in Dokkustrano, do not open a GitHub issue. Instead, please send a report to <info@unagi.com.ar>.
103
+
104
+ ## License
105
+
106
+ MIT License (MIT)
107
+
108
+ Permission is hereby granted, free of charge, to any person obtaining a copy
109
+ of this software and associated documentation files (the "Software"), to deal
110
+ in the Software without restriction, including without limitation the rights
111
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
112
+ copies of the Software, and to permit persons to whom the Software is
113
+ furnished to do so, subject to the following conditions:
114
+
115
+ The above copyright notice and this permission notice shall be included in
116
+ all copies or substantial portions of the Software.
117
+
118
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
119
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
120
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
121
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
122
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
123
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
124
+ THE SOFTWARE.
@@ -0,0 +1,27 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ require 'dokkustrano/version'
6
+
7
+ Gem::Specification.new do |gem|
8
+ gem.name = 'dokkustrano'
9
+ gem.version = Dokkustrano::VERSION
10
+ gem.authors = ['Lucas Hourquebie']
11
+ gem.email = ['lucas.hourquebie@unagi.com.ar']
12
+ gem.description = 'Dokkustrano is a utility and framework for executing commands via SSH on remote Dokku applications.'
13
+ gem.summary = 'Dokkustrano - Easy Dokku deployment with Ruby over SSH'
14
+ gem.homepage = 'https://github.com/unagisoftware/dokkustrano'
15
+ gem.metadata = {
16
+ 'bug_tracker_uri' => 'https://github.com/unagisoftware/dokkustrano/issues',
17
+ 'changelog_uri' => 'https://github.com/unagisoftware/dokkustrano/releases',
18
+ 'source_code_uri' => 'https://github.com/unagisoftware/dokkustrano',
19
+ 'homepage_uri' => 'https://github.com/unagisoftware/dokkustrano',
20
+ 'homepage' => 'https://github.com/unagisoftware/dokkustrano',
21
+ }
22
+ gem.files = `git ls-files -z`.split("\x0").reject { |f| f =~ /^docs/ }
23
+ gem.require_paths = ['lib']
24
+ gem.licenses = ['MIT']
25
+ gem.required_ruby_version = '>= 2.0'
26
+ gem.add_dependency 'rake', '>= 10.0.0'
27
+ end
@@ -0,0 +1,11 @@
1
+ module Dokkustrano
2
+ class Configuration
3
+ DEFAULT_HOST_NAME = 'dokku'.freeze
4
+
5
+ attr_writer :host_name
6
+
7
+ def host_name
8
+ @host_name || DEFAULT_HOST_NAME
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,15 @@
1
+ require 'rails'
2
+ require 'dokkustrano/validations'
3
+
4
+ module Dokkustrano
5
+ class Railtie < Rails::Railtie
6
+ railtie_name :dokku
7
+
8
+ rake_tasks do
9
+ namespace :dokku do
10
+ path = File.expand_path(__dir__)
11
+ Dir.glob("#{path}/tasks/**/*.rake").each { |file| load file }
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,8 @@
1
+ desc 'Connect with Dokku app and open a Rails console'
2
+ task :console, [:app] => :environment do |t, args|
3
+ include Dokkustrano::Validations
4
+
5
+ validate_app_argument!(args)
6
+
7
+ sh "ssh -t #{Dokkustrano.configuration.host_name} 'dokku run #{args[:app]} rails console -e production'"
8
+ end
@@ -0,0 +1,22 @@
1
+ namespace :data do
2
+ desc 'Download dump from Dokku given app'
3
+ task :export, [:app] => :environment do |t, args|
4
+ include Dokkustrano::Validations
5
+
6
+ validate_app_argument!(args)
7
+
8
+ sh "ssh -t #{Dokkustrano.configuration.host_name} 'dokku postgres:export #{args[:app]}' > dump.sql"
9
+ puts "Dump exported to 'dump.sql'"
10
+ end
11
+
12
+ desc 'Import dump to given Dokku app'
13
+ task :import, [:app, :path] => :environment do |t, args|
14
+ include Dokkustrano::Validations
15
+
16
+ validate_app_argument!(args)
17
+ validate_path_argument!(args)
18
+
19
+ sh "scp #{args[:path]} #{Dokkustrano.configuration.host_name}:/tmp/dump.sql"
20
+ sh "ssh -t #{Dokkustrano.configuration.host_name} 'dokku postgres:import #{args[:app]} < /tmp/dump.sql'"
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ namespace :postgres do
2
+ desc 'Connect with PostgreSQL console for given Dokku database service'
3
+ task :console, [:service] => :environment do |t, args|
4
+ include Dokkustrano::Validations
5
+
6
+ validate_database_service_argument!(args)
7
+
8
+ sh "ssh -t #{Dokkustrano.configuration.host_name} 'dokku postgres:connect #{args[:service]}'"
9
+ end
10
+
11
+ desc 'Change PostgreSQL version for given Dokku database service'
12
+ task :change_version, [:service, :version] => :environment do |t, args|
13
+ include Dokkustrano::Validations
14
+
15
+ validate_database_service_argument!(args)
16
+ validate_version_argument!(args)
17
+
18
+ sh "ssh -t #{Dokkustrano.configuration.host_name} 'dokku postgres:stop #{args[:service]}'"
19
+ sh "ssh -t #{Dokkustrano.configuration.host_name} 'dokku postgres:upgrade #{args[:service]} -I #{args[:version]}'"
20
+ sh "ssh -t #{Dokkustrano.configuration.host_name} 'dokku postgres:start #{args[:service]}'"
21
+ end
22
+ end
@@ -0,0 +1,28 @@
1
+ namespace :ssl do
2
+ desc 'Enable SSL for given Dokku app'
3
+ task :enable, [:app] => :environment do |t, args|
4
+ include Dokkustrano::Validations
5
+
6
+ validate_app_argument!(args)
7
+
8
+ sh "ssh -t #{Dokkustrano.configuration.host_name} 'dokku letsencrypt:enable #{args[:app]}'"
9
+ end
10
+
11
+ desc 'Auto-renew SSL for given Dokku app'
12
+ task :renew, [:app] => :environment do |t, args|
13
+ include Dokkustrano::Validations
14
+
15
+ validate_app_argument!(args)
16
+
17
+ sh "ssh -t #{Dokkustrano.configuration.host_name} 'dokku letsencrypt:auto-renew #{args[:app]}'"
18
+ end
19
+
20
+ desc 'Cleanup SSL for given Dokku app'
21
+ task :cleanup, [:app] => :environment do |t, args|
22
+ include Dokkustrano::Validations
23
+
24
+ validate_app_argument!(args)
25
+
26
+ sh "ssh -t #{Dokkustrano.configuration.host_name} 'dokku letsencrypt:cleanup #{args[:app]}'"
27
+ end
28
+ end
@@ -0,0 +1,25 @@
1
+ module Dokkustrano
2
+ module Validations
3
+ def validate_argument!(args, argument, position = :first)
4
+ return if args[argument].present?
5
+
6
+ abort ":#{argument} argument missing (#{position} argument)"
7
+ end
8
+
9
+ def validate_app_argument!(args)
10
+ validate_argument!(args, :app)
11
+ end
12
+
13
+ def validate_database_service_argument!(args)
14
+ validate_argument!(args, :service)
15
+ end
16
+
17
+ def validate_version_argument!(args)
18
+ validate_argument!(args, :version, :second)
19
+ end
20
+
21
+ def validate_path_argument!(args)
22
+ validate_argument!(args, :path, :second)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,3 @@
1
+ module Dokkustrano
2
+ VERSION = '0.0.1'.freeze
3
+ end
@@ -0,0 +1,16 @@
1
+ require 'dokkustrano/configuration'
2
+ require 'dokkustrano/railtie'
3
+
4
+ module Dokkustrano
5
+ def self.configure
6
+ @configuration ||= Configuration.new
7
+
8
+ yield @configuration if block_given?
9
+ end
10
+
11
+ def self.configuration
12
+ @configuration
13
+ end
14
+
15
+ configure
16
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dokkustrano
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Lucas Hourquebie
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-10-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 10.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 10.0.0
27
+ description: Dokkustrano is a utility and framework for executing commands via SSH
28
+ on remote Dokku applications.
29
+ email:
30
+ - lucas.hourquebie@unagi.com.ar
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - ".gitignore"
36
+ - Gemfile
37
+ - README.md
38
+ - dokkustrano.gemspec
39
+ - lib/dokkustrano.rb
40
+ - lib/dokkustrano/configuration.rb
41
+ - lib/dokkustrano/railtie.rb
42
+ - lib/dokkustrano/tasks/console.rake
43
+ - lib/dokkustrano/tasks/data.rake
44
+ - lib/dokkustrano/tasks/postgres.rake
45
+ - lib/dokkustrano/tasks/ssl.rake
46
+ - lib/dokkustrano/validations.rb
47
+ - lib/dokkustrano/version.rb
48
+ homepage: https://github.com/unagisoftware/dokkustrano
49
+ licenses:
50
+ - MIT
51
+ metadata:
52
+ bug_tracker_uri: https://github.com/unagisoftware/dokkustrano/issues
53
+ changelog_uri: https://github.com/unagisoftware/dokkustrano/releases
54
+ source_code_uri: https://github.com/unagisoftware/dokkustrano
55
+ homepage_uri: https://github.com/unagisoftware/dokkustrano
56
+ homepage: https://github.com/unagisoftware/dokkustrano
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '2.0'
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ requirements: []
72
+ rubygems_version: 3.1.6
73
+ signing_key:
74
+ specification_version: 4
75
+ summary: Dokkustrano - Easy Dokku deployment with Ruby over SSH
76
+ test_files: []