cloud-sh 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b779b9ffb09de3a990d1f15dcadfb8dbd18c958c86836866b0ff417a20759907
4
+ data.tar.gz: ad1200c5af739ed5d7a0e0b21a010f5f6309b528e4e0c46a9519d12b547dda07
5
+ SHA512:
6
+ metadata.gz: 8923664d58e8f4ac6794b9a2195f33d37d1ce191d1b8aa66f3791edbeff4a45e625ff8f5fa11063326322ef5ece9f5e509b091d5fb7cd767a35a646ae422cef4
7
+ data.tar.gz: ac512fa615a6ace8b00f8f50aabeed62a6bdf2c6af29d0e95cabcd92e9b35f1372b7bd0381edd7fdfa0722cb852d80a5226a2845ba59ded1897a6accc23661be
@@ -0,0 +1,32 @@
1
+ name: Ruby Gem
2
+
3
+ on:
4
+ pull_request:
5
+ branches:
6
+ - master
7
+ push:
8
+ branches:
9
+ - master
10
+
11
+ jobs:
12
+ build:
13
+ name: Build + Publish
14
+ runs-on: ubuntu-latest
15
+
16
+ steps:
17
+ - uses: actions/checkout@master
18
+ - name: Set up Ruby 2.6
19
+ uses: actions/setup-ruby@v1
20
+ with:
21
+ version: 2.6.x
22
+
23
+ - name: Publish to RubyGems
24
+ run: |
25
+ mkdir -p $HOME/.gem
26
+ touch $HOME/.gem/credentials
27
+ chmod 0600 $HOME/.gem/credentials
28
+ printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
29
+ gem build *.gemspec
30
+ gem push *.gem
31
+ env:
32
+ GEM_HOST_API_KEY: ${{secrets.RUBYGEMS_AUTH_TOKEN}}
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.rubocop.yml ADDED
@@ -0,0 +1,5 @@
1
+ Style/StringLiterals:
2
+ EnforcedStyle: double_quotes
3
+
4
+ Metrics/LineLength:
5
+ Max: 120
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.1
7
+ before_install: gem install bundler -v 1.17.2
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ gemspec
8
+
9
+ gem "pry"
data/Gemfile.lock ADDED
@@ -0,0 +1,30 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ cloud-sh (1.0.0)
5
+ gli
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ coderay (1.1.2)
11
+ gli (2.18.2)
12
+ method_source (0.9.2)
13
+ minitest (5.11.3)
14
+ pry (0.12.2)
15
+ coderay (~> 1.1.0)
16
+ method_source (~> 0.9.0)
17
+ rake (10.5.0)
18
+
19
+ PLATFORMS
20
+ ruby
21
+
22
+ DEPENDENCIES
23
+ bundler (~> 1.17)
24
+ cloud-sh!
25
+ minitest (~> 5.0)
26
+ pry
27
+ rake (~> 10.0)
28
+
29
+ BUNDLED WITH
30
+ 1.17.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Cristian Bica
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 ADDED
@@ -0,0 +1,126 @@
1
+ # Cloud shell helpers
2
+
3
+ Wrapper around `doctl`, `kubectl` to build aliases for easier access to cloud server, services. Special mention to [kubetail](https://github.com/johanhaleby/kubetail) which does the multiple kubernetes containers tailing.
4
+
5
+ ## Features
6
+
7
+ - DigitalOcean aliases for ssh-ing to droplets
8
+ - DigitalOcean aliases for connecting to your databases (MySQL, Postgres, Redis)
9
+ - Refreshes DigitalOcean certificate for kubernetes
10
+ - Kubernetes aliases for tailing single or multiple pods and opening a shell inside a pod
11
+
12
+ ## Installation
13
+
14
+ ### Requirements
15
+
16
+ - recent version of ruby (2.6+)
17
+ - kubectl
18
+ - doctl
19
+ - A MySQL client (mysql - version 8 needed for TLS, mycli)
20
+ - A Postgres client (psql, pgcli)
21
+ - Redis client (you'll need redli as it needs TLS support)
22
+
23
+ ### Install
24
+
25
+ Install the `cloud-sh` gem
26
+
27
+ ```sh
28
+ gem install cloud-sh
29
+ ```
30
+
31
+ ## Usage
32
+
33
+ Login to your DigitalOcean account(s) using `doctl auth init --context context-name`.
34
+
35
+ Write a YAML file to `~/.config/cloud-sh.yml`
36
+
37
+ ```
38
+ - name: personal # name of the account; will be used to prefix aliases
39
+ kind: do # cloud kind (do - digitalocean support for now)
40
+ default: true # if true don't use the name for aliases (default: false)
41
+ context: default # doctl context
42
+ clusters: # customize K8S clusters aliases
43
+ - name: k8s-01 # name as it is at DigitalOcean
44
+ alias: staging # alias name to be used in aliases (defaults to name)
45
+ default: true # if true don't use the name / alias (default: false)
46
+ ignore: true # don't create aliases for this (default: false)
47
+ databases: # customize databases aliases
48
+ - name: pg-01 # name as it is at DigitalOcean
49
+ alias: staging # alias name to be used in aliases (defaults to name)
50
+ default: true # if true don't use the name / alias (default: false)
51
+ ignore: true # don't create aliases for this (default: false)
52
+ ```
53
+
54
+ After that you can run `cloud-sh refresh` you'll get the aliases written to `~/.cloud_sh_aliases`.
55
+
56
+ ### Shell Integration
57
+
58
+ 1. Manual Integration
59
+
60
+ Run `cloud-sh refresh` to generate the aliases in `~/cloud_sh_aliases` and load the aliases. Or run `cloud-sh help` to see the available options.
61
+
62
+
63
+ 2. Automatic Integration
64
+ Setup a cron job for it:
65
+
66
+ ```
67
+ * * * * * ~/.cloud-sh/bin/cloud-sh refresh 2>&1 | logger -t cloud-sh
68
+ ```
69
+
70
+ And load the aliases using for shell. For `zsh` I'm adding to `.zshrc`:
71
+
72
+ ```
73
+ reload_cloud_sh() {
74
+ source ~/.cloud_sh_aliases
75
+ }
76
+ add-zsh-hook precmd reload_cloud_sh
77
+ ```
78
+
79
+ ### Digital Ocean aliases
80
+ ```
81
+ do-ssh-[account-name]-[dashed-droplet-name]
82
+ do-psql-[account-name]-[db-cluster-name]-[db-name]
83
+ do-pgcli-[account-name]-[db-cluster-name]-[db-name]
84
+ do-mysql-[account-name]-[db-cluster-name]-[db-name]
85
+ do-mycli-[account-name]-[db-cluster-name]-[db-name]
86
+ do-redis-[account-name]-[db-cluster-name]-[db-name]
87
+ ```
88
+
89
+ ### K8S aliases
90
+
91
+ Cloud-sh will write a `~/.kube/cloud_sh_config` with the clusters configuration for `kubectl`. If you don't have a different `kubectl` config you can make a symbolic link from `~/.kube/config` to `~/.kube/cloud_sh_config` or you pass `--kubeconfig='~/.kube/cloud_sh_config'` to `kubectl`.
92
+
93
+ Note: For K8S it will try to guess a pod name by removing the groups or random groups of chars from the end (5 random alpa numeric or 8-10 hexa)
94
+
95
+ ```
96
+ # Switch current kubectl context
97
+ k8s-switch-to-[account-name]-[cluster-name]
98
+ k8s-switch-to-personal-k8s-01 # switch to cluster k8s-01 of the account
99
+ k8s-switch-to-k8s-01 # switch to cluster k8s-01 of the default account
100
+
101
+ # Tail all pods in a namespace
102
+ k8s-[account-name]-[cluster-name]-[namespace]-tail-all
103
+
104
+ # Tail by pod name (prefix). Supported arguments:
105
+ # -p - pod index (default: 1)
106
+ # -c - container name (default: first found)
107
+ # -n - number of initial lines (default: 10)
108
+ k8s-[account-name]-[cluster-name]-[namespace]-tail-[pod-name]
109
+
110
+ # Exec a shell in a specific pod. Supported arguments:
111
+ # -p - pod index (default: 1)
112
+ # -c - container name (default: first found)
113
+ # -x - command to be executed (default: bash)
114
+ k8s-[account-name]-[cluster-name]-[namespace]-exec-[-pod-name]
115
+
116
+ # if there's a pod named console then it will run bundle exec rails console in that pod
117
+ k8s-[account-name]-[cluster-name]-[namespace]-rails-console
118
+ ```
119
+
120
+ ## Contributing
121
+
122
+ Bug reports and pull requests are welcome on GitHub at https://github.com/cristianbica/cloud-sh.
123
+
124
+ ## License
125
+
126
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/*_test.rb"]
10
+ end
11
+
12
+ task default: :test
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "cloud/sh"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -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
data/cloud-sh.gemspec ADDED
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path("lib", __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require "cloud/sh/version"
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "cloud-sh"
9
+ spec.version = Cloud::Sh::VERSION
10
+ spec.authors = ["Cristian Bica"]
11
+ spec.email = ["cristian.bica@gmail.com"]
12
+
13
+ spec.summary = "Cloud shell helpers."
14
+ spec.description = "Cloud shell helpers."
15
+ spec.homepage = "https://github.com/cristianbica/cloud-sh"
16
+ spec.license = "MIT"
17
+
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+ spec.metadata["source_code_uri"] = "https://github.com/cristianbica/cloud-sh"
21
+ end
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
26
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_dependency "gli"
33
+
34
+ spec.add_development_dependency "bundler", "~> 1.17"
35
+ spec.add_development_dependency "minitest", "~> 5.0"
36
+ spec.add_development_dependency "rake", "~> 10.0"
37
+ end
data/exe/cloud-sh ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "cloud/sh"
5
+ require "cloud/sh/cli"
6
+
7
+ exit Cloud::Sh::Cli.run(ARGV)