dokku-ruby 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d2c1c3ba24f4e2e7cb273efb5f0da3be07790e636aa0f0c7494f0947d1797688
4
+ data.tar.gz: df3ea07a87442ed43a0eb3aa91f3dd679a4d757431055f7392a8e9087e525f54
5
+ SHA512:
6
+ metadata.gz: 26f4956de70aba19cc7527535065d8eb3012f20f3640ed9fdfc148f1a625d3be291c7b646ae4f497abbc5c1dab3cd3f89c976772a98fb3b7e94584993ec73c69
7
+ data.tar.gz: d5829309b50407a0590b0d704e9227c1009e66a145b207fa543f1039e10fc61358da95a73750716578dc4607509c0aed6544d6a036aa06f12f63dfb6061e1153
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in dokku-ruby.gemspec
6
+ gemspec
7
+
8
+ gem 'rake', '~> 12.0'
9
+ gem 'rspec', '~> 3.9'
10
+
11
+ # net-ssh
12
+ gem 'bcrypt_pbkdf', '~> 1.0.1'
13
+ gem 'ed25519', '~> 1.2.4'
14
+ gem 'net-ssh', '~> 5.2.0'
@@ -0,0 +1,40 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ dokku-ruby (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ bcrypt_pbkdf (1.0.1)
10
+ diff-lcs (1.4.4)
11
+ ed25519 (1.2.4)
12
+ net-ssh (5.2.0)
13
+ rake (12.3.3)
14
+ rspec (3.9.0)
15
+ rspec-core (~> 3.9.0)
16
+ rspec-expectations (~> 3.9.0)
17
+ rspec-mocks (~> 3.9.0)
18
+ rspec-core (3.9.2)
19
+ rspec-support (~> 3.9.3)
20
+ rspec-expectations (3.9.2)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.9.0)
23
+ rspec-mocks (3.9.1)
24
+ diff-lcs (>= 1.2.0, < 2.0)
25
+ rspec-support (~> 3.9.0)
26
+ rspec-support (3.9.3)
27
+
28
+ PLATFORMS
29
+ ruby
30
+
31
+ DEPENDENCIES
32
+ bcrypt_pbkdf (~> 1.0.1)
33
+ dokku-ruby!
34
+ ed25519 (~> 1.2.4)
35
+ net-ssh (~> 5.2.0)
36
+ rake (~> 12.0)
37
+ rspec (~> 3.9)
38
+
39
+ BUNDLED WITH
40
+ 2.1.2
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 robertsimoes
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.
@@ -0,0 +1,54 @@
1
+ # Dokku::Ruby
2
+
3
+ Small [Dokku](https://github.com/dokku/dokku) API for Ruby over SSH
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'dokku-ruby'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install dokku-ruby
20
+
21
+ ## Usage
22
+
23
+ Start a Dokku Session:
24
+ ```
25
+ ssh = Dokku::SSH.new(
26
+ host: 'http://example.com',
27
+ user: 'deploy-user',
28
+ key_file: '~/.ssh/id_dokku'
29
+ )
30
+ ```
31
+
32
+ Use that session to create apps on server:
33
+
34
+ ```
35
+ ssh.start do |session|
36
+ env = { env_var_one: '123', env_var_two: '456' }
37
+
38
+ # Create a new Dokku application on the server
39
+ session.create(app_name: 'my-dokku-app')
40
+
41
+ # Set the environment config for that application
42
+ session.set_env_vars(app_name: app_name, env_vars: env)
43
+ end
44
+ ```
45
+
46
+ ## Development
47
+
48
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
49
+
50
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
51
+
52
+ ## License
53
+
54
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "dokku"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/dokku/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'dokku-ruby'
7
+ spec.version = Dokku::VERSION
8
+ spec.authors = ['robertsimoes']
9
+ spec.email = ['robertsimoes@users.noreply.github.com']
10
+
11
+ spec.summary = 'Simple Dokku SSH wrapper in ruby'
12
+ spec.description = 'Simple Dokku SSH wrapper in ruby'
13
+ spec.license = 'MIT'
14
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
15
+
16
+ spec.metadata['homepage_uri'] = 'https://github.com/robertsimoes/dokku-ruby'
17
+ spec.metadata['source_code_uri'] = 'https://github.com/robertsimoes/dokku-ruby'
18
+ spec.metadata['changelog_uri'] = 'https://github.com/robertsimoes/dokku-ruby/releases'
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ end
25
+
26
+ spec.bindir = 'exe'
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ['lib']
29
+
30
+ # Dev
31
+ spec.add_development_dependency 'rspec', '~> 3.9'
32
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dokku/version'
4
+ require 'dokku/session'
5
+ require 'dokku/ssh'
6
+
7
+ module Dokku
8
+ class Error < StandardError; end
9
+ # Your code goes here...
10
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'logger'
4
+
5
+ module Dokku
6
+ class Session
7
+ def initialize(session, logger = Logger.new(STDOUT))
8
+ @session = session
9
+ @logger = logger
10
+ end
11
+
12
+ def create(app_name:)
13
+ command = "dokku apps:create #{app_name}"
14
+ @logger.info command
15
+ @logger.info @session.exec!(command)
16
+ end
17
+
18
+ def set_env_vars(app_name:, env_vars:)
19
+ env = hash_to_env_vars(env_vars)
20
+
21
+ command = "dokku config:set #{app_name} #{env}"
22
+
23
+ stdout = ''
24
+ @logger.info "dokku config:set #{app_name}"
25
+ @session.exec!(command) do |_channel, stream, data|
26
+ stdout << redact_sensitive(data) if stream == :stdout
27
+ end
28
+
29
+ @logger.info stdout
30
+ end
31
+
32
+ def destroy(app_name:)
33
+ command = "dokku --force apps:destroy #{app_name}"
34
+ @logger.info command
35
+ @logger.info @session.exec!(command)
36
+ end
37
+
38
+ private
39
+
40
+ def hash_to_env_vars(hash)
41
+ hash.map do |k, v|
42
+ "#{k.upcase}=#{v}"
43
+ end.join(' ')
44
+ end
45
+
46
+ def redact_sensitive(s)
47
+ redactable = s.scan(/KEY|SECRET|TOKEN|PASSPHRASE/)
48
+
49
+ if redactable&.empty?
50
+ s
51
+ else
52
+ delimiter = '=' * 25
53
+ "\n#{delimiter}\n\nOUTPUT REDACTED\n\n#{delimiter}\n"
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'net/ssh'
4
+
5
+ module Dokku
6
+ class SSH
7
+ def initialize(**params)
8
+ @host = params[:host]
9
+ @user = params[:user]
10
+ @key_file = params[:key_file]
11
+ @keys_only = params[:keys_only] ||= true
12
+ @key_type = params[:key_type] ||= 'ssh-rsa'
13
+ end
14
+
15
+ def start
16
+ Net::SSH.start(
17
+ @host,
18
+ @user,
19
+ host_key: @key_type,
20
+ keys_only: @keys_only,
21
+ keys: @key_file,
22
+ verbose: :error
23
+ ) do |s|
24
+ yield Dokku::Session.new(s)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dokku
4
+ VERSION = '0.1.0'
5
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dokku-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - robertsimoes
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-08-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.9'
27
+ description: Simple Dokku SSH wrapper in ruby
28
+ email:
29
+ - robertsimoes@users.noreply.github.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - ".rspec"
36
+ - Gemfile
37
+ - Gemfile.lock
38
+ - LICENSE.txt
39
+ - README.md
40
+ - Rakefile
41
+ - bin/console
42
+ - bin/setup
43
+ - dokku-ruby.gemspec
44
+ - lib/dokku.rb
45
+ - lib/dokku/session.rb
46
+ - lib/dokku/ssh.rb
47
+ - lib/dokku/version.rb
48
+ homepage:
49
+ licenses:
50
+ - MIT
51
+ metadata:
52
+ homepage_uri: https://github.com/robertsimoes/dokku-ruby
53
+ source_code_uri: https://github.com/robertsimoes/dokku-ruby
54
+ changelog_uri: https://github.com/robertsimoes/dokku-ruby/releases
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: 2.3.0
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubygems_version: 3.1.2
71
+ signing_key:
72
+ specification_version: 4
73
+ summary: Simple Dokku SSH wrapper in ruby
74
+ test_files: []