kite 1.0.2 → 1.0.4
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 +4 -4
- data/.ruby-version +1 -0
- data/.travis.yml +12 -3
- data/README.md +11 -8
- data/ci/bump.rb +207 -0
- data/kite.gemspec +2 -2
- data/lib/kite/module.rb +28 -7
- data/lib/kite/version.rb +1 -1
- metadata +9 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c516eab6deb826e2384b1002dc82846361159e87682d83f34cff582f32968e6
|
4
|
+
data.tar.gz: d69f8de21c4b59897277b3663467cb044119504528832b6d4a7e85157974bc08
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e3e3ae732aa5096870ab5ebfb3c42c868a0f0ef98a677ce743cd6d5e74eaa775af27173ca9fea21786de05854d3c3328a2ec2b63f07aef53513045b9776ae735
|
7
|
+
data.tar.gz: dd16d0d5991befdbe1659af7677879cbcb075ce3a5e913c8df9024661ddeb5a049a3db61d47e7b7edcea8e62207f2808cecc860b52d481685784f2656636729c
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.5.0
|
data/.travis.yml
CHANGED
@@ -1,7 +1,16 @@
|
|
1
|
-
|
1
|
+
dist: trusty
|
2
|
+
|
3
|
+
sudo: required
|
4
|
+
|
2
5
|
language: ruby
|
3
|
-
|
4
|
-
|
6
|
+
|
7
|
+
cache: bundler
|
8
|
+
|
9
|
+
|
5
10
|
before_install: gem install bundler -v 1.14.6
|
11
|
+
|
6
12
|
env:
|
7
13
|
COVERAGE: true
|
14
|
+
|
15
|
+
# Execute all of the commands which need to be executed after the build passed.
|
16
|
+
after_success: ruby ci/bump.rb
|
data/README.md
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
# Kite
|
2
2
|
|
3
|
-
](https://codecov.io/gh/helios-technologies/kite)
|
3
|
+
[](https://badge.fury.io/rb/kite)
|
4
|
+
[](https://github.com/rubykube/kite/blob/master/LICENSE.md)
|
6
5
|
|
6
|
+
[](https://travis-ci.org/rubykube/kite)
|
7
|
+
[](https://codecov.io/gh/rubykube/kite)
|
7
8
|
|
8
9
|
Kite is a CLI for scaffolding and managing devops modules
|
9
|
-
The main purpose is templating of various tools for devops around terraform, bosh, ansible
|
10
|
+
The main purpose is templating of various tools for devops around terraform, bosh, ansible.
|
10
11
|
Currently Kite supports modular stacks(Kite modules) on both AWS and GCP.
|
11
12
|
|
12
13
|
We plan in adding community stack using a simple template repository structure.
|
@@ -31,7 +32,7 @@ Or install it yourself as:
|
|
31
32
|
|
32
33
|
To start using kite for bootstraping your infrastructure
|
33
34
|
follow the steps below.
|
34
|
-
[Note] Most kite commands can be referred by their first letter(for example kite generate environment test
|
35
|
+
[Note] Most kite commands can be referred by their first letter(for example `kite generate environment test` is the same as `kite g e test`)
|
35
36
|
|
36
37
|
### Create your Infrastructure as Code base repository
|
37
38
|
|
@@ -57,10 +58,11 @@ Now the environment should be generated at `config/environments/*env_name*`
|
|
57
58
|
|
58
59
|
### Add a module to your environment
|
59
60
|
|
60
|
-
To add a Kite module to your environment, you should first initialize it
|
61
|
+
To add a Kite module to your environment, you should first initialize it.
|
62
|
+
It's recommended to use specific module versions/tags(master branch would be used by default):
|
61
63
|
|
62
64
|
```
|
63
|
-
kite module init https://url.for/your/module --env *env_name*
|
65
|
+
kite module init https://url.for/your/module --env *env_name* --version *x.y.z/x-y-stable*
|
64
66
|
```
|
65
67
|
|
66
68
|
This should clone module's source files into `modules/*module_name*` and create a `vars.*module_name*.yml` file with all variables needed by the module.
|
@@ -80,6 +82,7 @@ Set your default gcloud credentials using
|
|
80
82
|
```
|
81
83
|
|
82
84
|
```
|
85
|
+
kite terraform init
|
83
86
|
kite terraform apply --env *env_name*
|
84
87
|
```
|
85
88
|
|
@@ -107,4 +110,4 @@ $ ruby -Ilib ./bin/concourse/in
|
|
107
110
|
|
108
111
|
## Contributing
|
109
112
|
|
110
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
113
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/rubykube/kite.
|
data/ci/bump.rb
ADDED
@@ -0,0 +1,207 @@
|
|
1
|
+
require "rubygems/version"
|
2
|
+
require "net/http"
|
3
|
+
require "json"
|
4
|
+
require "uri"
|
5
|
+
|
6
|
+
#
|
7
|
+
# Returns bot's username in GitHub.
|
8
|
+
#
|
9
|
+
# @return [String]
|
10
|
+
def bot_username
|
11
|
+
ENV.fetch("BOT_USERNAME", "kite-bot")
|
12
|
+
end
|
13
|
+
|
14
|
+
#
|
15
|
+
# Returns bot's displayed name in commits.
|
16
|
+
#
|
17
|
+
# @return [String]
|
18
|
+
def bot_name
|
19
|
+
ENV.fetch("BOT_NAME", "Kite Bot")
|
20
|
+
end
|
21
|
+
|
22
|
+
#
|
23
|
+
# Returns bot's displayed email in commits.
|
24
|
+
#
|
25
|
+
# @return [String]
|
26
|
+
def bot_email
|
27
|
+
ENV.fetch("BOT_EMAIL", "kite-bot@heliostech.fr")
|
28
|
+
end
|
29
|
+
|
30
|
+
#
|
31
|
+
# Returns GitHub repository slug in form of :user|:organization/:repository.
|
32
|
+
#
|
33
|
+
# @return [String]
|
34
|
+
def repository_slug
|
35
|
+
ENV.fetch("REPOSITORY_SLUG", "rubykube/kite")
|
36
|
+
end
|
37
|
+
|
38
|
+
#
|
39
|
+
# Increments the newest available version which is in stage of development (master),
|
40
|
+
# and publishes it on the GitHub.
|
41
|
+
#
|
42
|
+
# The requirements for this to work are:
|
43
|
+
# 1) Repository has some tagged versions.
|
44
|
+
# 2) The latest version is not released yet (e.g. there is no version-specific branch like "1-3-stable").
|
45
|
+
#
|
46
|
+
# If you are on 1.1 and you want to start developing 1.2 do the following:
|
47
|
+
# 1) Create branch "1-1-stable", and push up-to-date source to it.
|
48
|
+
# 2) Push the same to master branch.
|
49
|
+
# 3) Push new commit(s) to master, and tag master as 1.2.0.
|
50
|
+
# 4) Future pushes to master will be treated as new patch version number.
|
51
|
+
#
|
52
|
+
def bump_from_master_branch
|
53
|
+
# Get latest version of Kite.
|
54
|
+
return unless (latest_version = versions.last)
|
55
|
+
|
56
|
+
# Find a branch which is specific the version.
|
57
|
+
# Comparision is based only on major and minor version numbers since
|
58
|
+
# these type of branches are named with a convention like: "1-0-stable", "2-4-stable", and so on.
|
59
|
+
linked_branch = version_specific_branches.find { |b| b[:version].segments == latest_version.segments[0...2] }
|
60
|
+
# If branch exists it means that version has been already released.
|
61
|
+
return if linked_branch
|
62
|
+
|
63
|
+
# Increment patch version number, tag, and push.
|
64
|
+
candidate_version = Gem::Version.new(latest_version.segments.dup.tap { |s| s[2] += 1 }.join("."))
|
65
|
+
tag_n_push(candidate_version.to_s, name: 'master') unless versions.include?(candidate_version)
|
66
|
+
end
|
67
|
+
|
68
|
+
#
|
69
|
+
# Increments the version which is in stage of support (version-specific branches only),
|
70
|
+
# and publishes it on the GitHub.
|
71
|
+
#
|
72
|
+
# The method expects branch name in form of "X-Y-stable", like "2-0-stable".
|
73
|
+
# It tags the current Git commit to the next patch number version, and pushes it to Git repository.
|
74
|
+
#
|
75
|
+
# @param name [String]
|
76
|
+
# Branch name.
|
77
|
+
|
78
|
+
def bump_from_version_specific_branch(name)
|
79
|
+
# This helps to ensure branch does exist.
|
80
|
+
branch = version_specific_branches.find { |b| b[:name] == name }
|
81
|
+
return unless branch
|
82
|
+
|
83
|
+
# Find latest version for the branch (compare by major and minor).
|
84
|
+
# We use find here since versions are sorted in descending order.
|
85
|
+
latest_version = versions.reverse.find { |v| v.segments[0...2] == branch[:version].segments }
|
86
|
+
return unless latest_version
|
87
|
+
|
88
|
+
# Increment patch version number, tag, and push.
|
89
|
+
candidate_version = Gem::Version.new(latest_version.segments.dup.tap { |s| s[2] += 1 }.join("."))
|
90
|
+
tag_n_push(candidate_version.to_s, branch) unless versions.include?(candidate_version)
|
91
|
+
end
|
92
|
+
|
93
|
+
#
|
94
|
+
# Configures Git user name & email,
|
95
|
+
# updates version at lib/kite/version.rb,
|
96
|
+
# creates Git tag, and pushes all the changes made to repository.
|
97
|
+
#
|
98
|
+
# @param tag [String]
|
99
|
+
def tag_n_push(tag, branch)
|
100
|
+
File.open "lib/kite/version.rb", "w" do |f|
|
101
|
+
f.write <<-RUBY
|
102
|
+
module Kite
|
103
|
+
VERSION = '#{tag}'
|
104
|
+
end
|
105
|
+
RUBY
|
106
|
+
end
|
107
|
+
|
108
|
+
[
|
109
|
+
%( git config --global user.email "#{bot_email}" ),
|
110
|
+
%( git config --global user.name "#{bot_name}" ),
|
111
|
+
%( git remote add authenticated-origin https://#{bot_username}:#{ENV.fetch("GITHUB_API_KEY")}@github.com/#{repository_slug} ),
|
112
|
+
%( git checkout -b release ),
|
113
|
+
%( git add lib/kite/version.rb ),
|
114
|
+
%( git commit -m "[ci skip] Bump #{tag}." ),
|
115
|
+
%( git push authenticated-origin release:#{branch.fetch(:name)} ),
|
116
|
+
%( git tag v#{tag} -a -m "Automatically generated tag from TravisCI build #{ENV.fetch("TRAVIS_BUILD_NUMBER")}." ),
|
117
|
+
%( git push authenticated-origin v#{tag} )
|
118
|
+
].each do |command|
|
119
|
+
command.strip!
|
120
|
+
unless Kernel.system(command)
|
121
|
+
# Prevent GitHub API key from being published.
|
122
|
+
command.gsub!(ENV["GITHUB_API_KEY"], "(secret)")
|
123
|
+
raise %(Command "#{command}" exited with status #{$?.exitstatus || "(unavailable)"}.)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
#
|
129
|
+
# Loads all Kite tags, and returns them in ascending order.
|
130
|
+
#
|
131
|
+
# @return [Array<Gem::Version>]
|
132
|
+
def versions
|
133
|
+
@versions ||= github_api_authenticated_get("/repos/#{repository_slug}/tags").map do |x|
|
134
|
+
Gem::Version.new(x.fetch("name")[/\d+\.\d+\.\d+/])
|
135
|
+
end.sort
|
136
|
+
end
|
137
|
+
|
138
|
+
#
|
139
|
+
# Returns hash with all tagged commits as keys (SHA-1) and versions as values.
|
140
|
+
#
|
141
|
+
# @return [Hash]
|
142
|
+
# Key is commit's SHA-1 hash, value is instance of Gem::Version.
|
143
|
+
def tagged_commits_mapping
|
144
|
+
@commits ||= github_api_authenticated_get("/repos/#{repository_slug}/tags").each_with_object({}) do |x, memo|
|
145
|
+
memo[x.fetch("commit").fetch("sha")] = Gem::Version.new(x.fetch("name")[/\d+\.\d+\.\d+/])
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
#
|
150
|
+
# Loads all Kite branches, selects only version-specific, and returns them.
|
151
|
+
#
|
152
|
+
# @return [Array<Hash>]
|
153
|
+
# Array of hashes each containing "name" & "version" keys.
|
154
|
+
def version_specific_branches
|
155
|
+
@branches ||= github_api_authenticated_get("/repos/#{repository_slug}/branches").map do |x|
|
156
|
+
if x.fetch("name") =~ /\A(\d)-(\d)-\w+\z/
|
157
|
+
{ name: x["name"], version: Gem::Version.new($1 + "." + $2) }
|
158
|
+
end
|
159
|
+
end.compact
|
160
|
+
end
|
161
|
+
|
162
|
+
#
|
163
|
+
# Performs call to GitHub API and returns the response. Raises in case of non-200 status.
|
164
|
+
#
|
165
|
+
# @param path [String]
|
166
|
+
# Request path.
|
167
|
+
# @return [Hash]
|
168
|
+
def github_api_authenticated_get(path)
|
169
|
+
http = Net::HTTP.new("api.github.com", 443)
|
170
|
+
http.use_ssl = true
|
171
|
+
response = http.get path, "Authorization" => %[token #{ENV.fetch("GITHUB_API_KEY")}]
|
172
|
+
if response.code.to_i == 200
|
173
|
+
JSON.load(response.body)
|
174
|
+
else
|
175
|
+
raise StandardError, %[HTTP #{response.code}: "#{response.body}".]
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
#
|
180
|
+
# Returns true if version has exactly 3 version segments (major, minor, patch), and all are integers.
|
181
|
+
#
|
182
|
+
# @param version [Gem::Version]
|
183
|
+
# @return [true, false]
|
184
|
+
def generic_semver?(version)
|
185
|
+
version.segments.count == 3 && version.segments.all? { |segment| segment.match?(/\A[0-9]+\z/) }
|
186
|
+
end
|
187
|
+
|
188
|
+
# Build must not run on a fork.
|
189
|
+
bump = ENV["TRAVIS_REPO_SLUG"] == repository_slug
|
190
|
+
# Skip PRs.
|
191
|
+
bump &&= ENV["TRAVIS_PULL_REQUEST"] == "false"
|
192
|
+
# Build must run on branch.
|
193
|
+
bump &&= !ENV["TRAVIS_BRANCH"].to_s.empty?
|
194
|
+
# GitHub API key must be available.
|
195
|
+
bump &&= !ENV["GITHUB_API_KEY"].to_s.empty?
|
196
|
+
# Build must not run on tag.
|
197
|
+
bump &&= ENV["TRAVIS_TAG"].to_s.empty?
|
198
|
+
# Ensure this commit is not tagged.
|
199
|
+
bump &&= !tagged_commits_mapping.key?(ENV["TRAVIS_COMMIT"])
|
200
|
+
|
201
|
+
if bump
|
202
|
+
if ENV["TRAVIS_BRANCH"] == "master"
|
203
|
+
bump_from_master_branch
|
204
|
+
else
|
205
|
+
bump_from_version_specific_branch(ENV["TRAVIS_BRANCH"])
|
206
|
+
end
|
207
|
+
end
|
data/kite.gemspec
CHANGED
@@ -23,9 +23,9 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_dependency "thor"
|
24
24
|
spec.add_dependency "git"
|
25
25
|
|
26
|
-
spec.add_development_dependency "bundler", "~> 1.
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
27
27
|
spec.add_development_dependency "rake", "~> 10.0"
|
28
|
-
spec.add_development_dependency "rspec", "~> 3.
|
28
|
+
spec.add_development_dependency "rspec", "~> 3.7"
|
29
29
|
spec.add_development_dependency "git"
|
30
30
|
spec.add_development_dependency "simplecov"
|
31
31
|
spec.add_development_dependency "codecov"
|
data/lib/kite/module.rb
CHANGED
@@ -2,19 +2,25 @@ module Kite
|
|
2
2
|
class Module < Base
|
3
3
|
include Kite::Helpers
|
4
4
|
|
5
|
-
method_option :env,
|
5
|
+
method_option :env, type: :string, desc: "Environment", required: true, default: ENV['KITE_ENV']
|
6
|
+
method_option :version, type: :string, desc: "Version", required: false
|
6
7
|
desc 'init https://github.com/foo/bar-module', 'Initialize a kite module and render its vars.module.yml'
|
7
8
|
def init(path)
|
8
|
-
@env
|
9
|
-
@path
|
10
|
-
@name
|
9
|
+
@env = options[:env]
|
10
|
+
@path = path
|
11
|
+
@name = path.gsub(/(.*:|.git)/, '').split('/').last
|
12
|
+
@cloud = parse_cloud_config[@env]
|
13
|
+
@version = options[:version]
|
11
14
|
|
12
15
|
unless File.exist? path
|
13
16
|
@uri = path
|
14
17
|
@path = "modules/#{@name}"
|
15
18
|
|
16
|
-
say "Cloning the module"
|
17
19
|
clone_module
|
20
|
+
unless @version.nil?
|
21
|
+
checkout_version
|
22
|
+
end
|
23
|
+
|
18
24
|
say "Use git submodule add #{@path} to be able to commit this module as a submodule", :yellow
|
19
25
|
end
|
20
26
|
|
@@ -42,6 +48,8 @@ module Kite
|
|
42
48
|
end
|
43
49
|
|
44
50
|
def clone_module
|
51
|
+
say "Cloning the module"
|
52
|
+
|
45
53
|
if File.exist? @path
|
46
54
|
overwrite = ask "#{@path} already contains a module! Overwrite? (y/N)"
|
47
55
|
|
@@ -50,13 +58,26 @@ module Kite
|
|
50
58
|
Git.clone(@uri, @path)
|
51
59
|
say "Successfully cloned the fresh #{@name}!", :green
|
52
60
|
else
|
53
|
-
say "Keeping the current module
|
61
|
+
say "Keeping the current module revision"
|
54
62
|
end
|
55
63
|
else
|
56
64
|
Git.clone(@uri, @path)
|
57
65
|
end
|
58
66
|
end
|
59
67
|
|
68
|
+
def checkout_version
|
69
|
+
module_git = Git.open(@path)
|
70
|
+
|
71
|
+
say "Switching to #{@version}"
|
72
|
+
if @version =~ /\d+\.\d+\.\d+/ && module_git.tags.any? { |t| t.name == @version }
|
73
|
+
module_git.checkout("tags/#{@version}")
|
74
|
+
elsif module_git.is_remote_branch? @version
|
75
|
+
module_git.checkout("origin/#{@version}")
|
76
|
+
else
|
77
|
+
say "#{@version} tag/branch was not found in the module, keeping the current one", :red
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
60
81
|
def render_vars
|
61
82
|
create_file "config/environments/#{@env}/vars.#{@name}.yml", YAML.dump(manifest['variables'])
|
62
83
|
end
|
@@ -71,7 +92,7 @@ module Kite
|
|
71
92
|
end
|
72
93
|
|
73
94
|
def manifest
|
74
|
-
YAML.load(File.
|
95
|
+
YAML.load(ERB.new(File.read("#{@path}/manifest.yml.tt")).result(binding))
|
75
96
|
end
|
76
97
|
end
|
77
98
|
|
data/lib/kite/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Louis Bellet
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-04-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '1.
|
47
|
+
version: '1.16'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '1.
|
54
|
+
version: '1.16'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,14 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '3.
|
75
|
+
version: '3.7'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '3.
|
82
|
+
version: '3.7'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: git
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -132,6 +132,7 @@ extra_rdoc_files: []
|
|
132
132
|
files:
|
133
133
|
- ".gitignore"
|
134
134
|
- ".rspec"
|
135
|
+
- ".ruby-version"
|
135
136
|
- ".travis.yml"
|
136
137
|
- CHANGELOG.md
|
137
138
|
- Dockerfile
|
@@ -146,6 +147,7 @@ files:
|
|
146
147
|
- bin/kite
|
147
148
|
- bin/kite-config
|
148
149
|
- bin/kite-console
|
150
|
+
- ci/bump.rb
|
149
151
|
- config/pipelines/review.yml
|
150
152
|
- config/pipelines/tasks/create-pull-requests-tag.yml
|
151
153
|
- config/pipelines/tasks/create-repository-tag.yml
|
@@ -213,7 +215,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
213
215
|
version: '0'
|
214
216
|
requirements: []
|
215
217
|
rubyforge_project:
|
216
|
-
rubygems_version: 2.7.
|
218
|
+
rubygems_version: 2.7.6
|
217
219
|
signing_key:
|
218
220
|
specification_version: 4
|
219
221
|
summary: Command line tool for devops scaffolding.
|