ci-killer 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
+ SHA1:
3
+ metadata.gz: 3dcb27211f9aa71dd3e3f6d7291ad76e3050d6dd
4
+ data.tar.gz: ae63035ade254d8649c76009673c77cc31fad185
5
+ SHA512:
6
+ metadata.gz: d2ae71356ae1300aef408b7b2753933e76733234d38549d49a3c706a99c3b3f6fafd5ce598e2c2c8801930add95a4bb66bc1f3b5b428acff27f84425ffc92f33
7
+ data.tar.gz: 6268adaee96f3d5e8a776b95ba1846e974b66f23a3cb4d2526ebccd299036b40199190b2d08ae1fdc5b30ce6fb538d242705acd24e9b6d6b27d2c1b3b48a5925
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,6 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0 - 2017-07-14
4
+
5
+ * Initial setup.
6
+ * Allows Digital Ocean droplets to be killed after a given amount of time.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in ci-killer.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Jeroen Jacobs
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,41 @@
1
+ # Ci::Killer
2
+
3
+ This kills CI instances if they have been running for too long. Currently only [Digital Ocean](https://www.digitalocean.com) instances are supported.
4
+
5
+ ## Installation
6
+
7
+ ```
8
+ $ gem install ci-killer
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ### Digital Ocean
14
+
15
+ You'll need to set your access token as an environment variable:
16
+
17
+ ```
18
+ DIGITAL_OCEAN_ACCESS_TOKEN = "<token>"
19
+ ```
20
+
21
+ Droplets that have been running for longer than the time passed in minutes will be deleted:
22
+
23
+ ```
24
+ ci-killer digital_ocean 60
25
+ ```
26
+
27
+ This will kill all instances that have been running for 60 minutes or more.
28
+
29
+ ## Development
30
+
31
+ 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.
32
+
33
+ To install this gem onto your local machine, run `bin/rake install`. To release a new version, update the version number in `version.rb`, and then run `bin/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).
34
+
35
+ ## Contributing
36
+
37
+ Bug reports and pull requests are welcome on GitHub at https://github.com/jeroenj/ci-killer.
38
+
39
+ ## License
40
+
41
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ci/killer"
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
+ require "pry"
10
+ Pry.start
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require 'rake'
5
+
6
+ Rake.application.run
@@ -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,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "ci/killer/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ci-killer"
8
+ spec.version = Ci::Killer::VERSION
9
+ spec.authors = ["Jeroen Jacobs"]
10
+ spec.email = ["gems@jeroenj.be"]
11
+
12
+ spec.summary = "Kills CI nodes if they have been running for too long."
13
+ spec.description = "Kills CI nodes if they have been running for too long."
14
+ spec.homepage = "https://github.com/jeroenj/ci-killer"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_dependency "droplet_kit", "~> 2.2"
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.15"
27
+ spec.add_development_dependency "rake", "~> 10"
28
+ spec.add_development_dependency "pry"
29
+ end
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH.unshift "lib"
3
+
4
+ require "thor"
5
+ require "ci/killer"
6
+
7
+ class CiKillerCLI < Thor
8
+ desc "digital_ocean TIME_IN_MINUTES", "Kills nodes that have been running for TIME_IN_MINUTES or more"
9
+ def digital_ocean(time_in_minutes = 0)
10
+ if ENV["DIGITAL_OCEAN_ACCESS_TOKEN"].to_s == ""
11
+ $stderr.puts("ERROR: DIGITAL_OCEAN_ACCESS_TOKEN needs to be set")
12
+ exit 1
13
+ end
14
+
15
+ Ci::Killer::DigitalOcean.kill(time_in_minutes)
16
+ end
17
+
18
+ map %w[--version -v] => :version
19
+
20
+ desc "--version, -v", "Print the version"
21
+ def version
22
+ puts Ci::Killer::VERSION
23
+ end
24
+ end
25
+
26
+ CiKillerCLI.start
@@ -0,0 +1,8 @@
1
+ require "ci/killer/version"
2
+
3
+ require "ci/killer/digital_ocean"
4
+
5
+ module Ci
6
+ module Killer
7
+ end
8
+ end
@@ -0,0 +1,38 @@
1
+ require "droplet_kit"
2
+
3
+ module Ci::Killer
4
+ class DigitalOcean
5
+ attr_reader :time_in_minutes
6
+
7
+ def self.kill(time_in_minutes)
8
+ new(time_in_minutes).kill
9
+ end
10
+
11
+ def initialize(time_in_minutes)
12
+ @time_in_minutes = time_in_minutes.to_i
13
+ end
14
+
15
+ def kill
16
+ droplets_to_kill.each do |droplet|
17
+ running_time = ((Time.now.utc - DateTime.parse(droplet.created_at).utc) / 60).round
18
+ print "* Droplet #{droplet.name} (#{droplet.id}) has been running for #{running_time} minute(s)."
19
+ client.droplets.delete(id: droplet.id)
20
+ puts " [KILLED]"
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ def droplets_to_kill
27
+ maximum_age = Time.now.utc - (60 * time_in_minutes)
28
+
29
+ client.droplets.all.select do |droplet|
30
+ DateTime.parse(droplet.created_at).utc < maximum_age
31
+ end
32
+ end
33
+
34
+ def client
35
+ @client ||= DropletKit::Client.new(access_token: ENV['DIGITAL_OCEAN_ACCESS_TOKEN'])
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,5 @@
1
+ module Ci
2
+ module Killer
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ci-killer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jeroen Jacobs
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-07-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: droplet_kit
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.15'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.15'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Kills CI nodes if they have been running for too long.
70
+ email:
71
+ - gems@jeroenj.be
72
+ executables:
73
+ - ci-killer
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - Changelog.md
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - bin/console
84
+ - bin/rake
85
+ - bin/setup
86
+ - ci-killer.gemspec
87
+ - exe/ci-killer
88
+ - lib/ci/killer.rb
89
+ - lib/ci/killer/digital_ocean.rb
90
+ - lib/ci/killer/version.rb
91
+ homepage: https://github.com/jeroenj/ci-killer
92
+ licenses:
93
+ - MIT
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.6.11
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: Kills CI nodes if they have been running for too long.
115
+ test_files: []