ci-scripts 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.editorconfig +17 -0
- data/.gitignore +1 -0
- data/README.md +89 -2
- data/bin/ci-scripts +6 -1
- data/bin/document +180 -0
- data/ci-scripts.gemspec +3 -0
- data/lib/ci_scripts.rb +32 -17
- data/lib/ci_scripts/helpers.rb +11 -4
- data/lib/ci_scripts/version.rb +1 -1
- data/lib/scripts/demo/test.rb +3 -3
- data/lib/scripts/docker/build.rb +26 -11
- data/lib/scripts/docker/herokuish.rb +17 -16
- data/lib/scripts/docker/login.rb +13 -11
- data/lib/scripts/docker/push_branch.rb +12 -10
- data/lib/scripts/docker/push_latest.rb +14 -12
- data/lib/scripts/files/sha_firebase.rb +73 -0
- data/lib/scripts/files/tarball.rb +0 -0
- data/lib/scripts/git/ssh_keys.rb +5 -4
- data/lib/scripts/go/build.rb +43 -0
- data/lib/scripts/ruby/bundler.rb +9 -8
- data/lib/scripts/ruby/publish_gem.rb +16 -0
- data/lib/scripts/ruby/rake_test.rb +16 -7
- data/lib/scripts/ruby/rubocop.rb +9 -8
- metadata +36 -3
- data/LICENSE.txt +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bed99c8505ea0b8e5fd987d8dc3908ab5077f315
|
4
|
+
data.tar.gz: 9e97dc28a22958d6096c808ac0d18e8b1af248f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4741cad527006c2f5378f4a1e395780a34f858edd210d0dddad14542ef1c0aa4b5f10ca6031ff7a654446819f5cf506eda040add86c50c6016bb83741a7640ca
|
7
|
+
data.tar.gz: 79f6708f4a1f2459ff07e0efa02b41fdf6a55262bbf6ac7e083e62d092944cffc246376d1a827f1faf97cf6856f687faa0db14c1698d13d19c01a3d55bd88aba
|
data/.editorconfig
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# EditorConfig is awesome: http://EditorConfig.org
|
2
|
+
|
3
|
+
# top-most EditorConfig file
|
4
|
+
root = true
|
5
|
+
|
6
|
+
# Unix-style newlines with a newline ending every file
|
7
|
+
[*]
|
8
|
+
end_of_line = lf
|
9
|
+
insert_final_newline = true
|
10
|
+
trim_trailing_whitespace = true
|
11
|
+
charset = utf-8
|
12
|
+
indent_style = space
|
13
|
+
indent_size = 2
|
14
|
+
|
15
|
+
[*.go]
|
16
|
+
indent_style = tab
|
17
|
+
indent_size = 1
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -2,10 +2,97 @@
|
|
2
2
|
|
3
3
|
A collection of modular scripts that are commonly run in CI. The goal of this project is to reduce the number of CI configuration files that have duplicate code. Environment variables are used to configure the scripts. To include a script add the following to the CI config:
|
4
4
|
|
5
|
-
|
5
|
+
## Installation
|
6
6
|
```
|
7
7
|
gem install ci-scripts
|
8
8
|
ci-scripts SCRIPT_NAME
|
9
9
|
```
|
10
10
|
|
11
|
-
|
11
|
+
## Scripts
|
12
|
+
|
13
|
+
### demo/test
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
### docker/build
|
18
|
+
Uses docker to build the docker image for the current project.
|
19
|
+
|
20
|
+
This script assumes the following binaries are installed:
|
21
|
+
- docker
|
22
|
+
|
23
|
+
#### Environment Variables
|
24
|
+
|
25
|
+
| Variable | Default | Required | Description |
|
26
|
+
|:---|:---|:---:|:---|
|
27
|
+
| DOCKER_IMAGE | | ✔ | |
|
28
|
+
| IMAGE_TAG | git tag | | My favoruite thing|
|
29
|
+
| BUILD_DOCKERFILE | Dockerfile | | |
|
30
|
+
|
31
|
+
### docker/herokuish
|
32
|
+
|
33
|
+
|
34
|
+
This script depends on and will run the following other scripts:
|
35
|
+
- [docker/build](#docker/build)
|
36
|
+
|
37
|
+
### docker/login
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
#### Environment Variables
|
42
|
+
|
43
|
+
| Variable | Default | Required | Description |
|
44
|
+
|:---|:---|:---:|:---|
|
45
|
+
| DOCKER_USERNAME | | ✔ | |
|
46
|
+
| DOCKER_PASSWORD | | ✔ | |
|
47
|
+
| DOCKER_EMAIL | ci@ci-runner.com | | |
|
48
|
+
| DOCKER_REGISTRY | hub.docker.com | | |
|
49
|
+
|
50
|
+
### docker/push_branch
|
51
|
+
|
52
|
+
|
53
|
+
|
54
|
+
#### Environment Variables
|
55
|
+
|
56
|
+
| Variable | Default | Required | Description |
|
57
|
+
|:---|:---|:---:|:---|
|
58
|
+
| DOCKER_IMAGE | | ✔ | |
|
59
|
+
| IMAGE_TAG | current git hash | | |
|
60
|
+
|
61
|
+
### docker/push_latest
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
#### Environment Variables
|
66
|
+
|
67
|
+
| Variable | Default | Required | Description |
|
68
|
+
|:---|:---|:---:|:---|
|
69
|
+
| DOCKER_LATEST_BRANCH | master | | |
|
70
|
+
| DOCKER_IMAGE | | ✔ | |
|
71
|
+
| IMAGE_TAG | current git hash | | |
|
72
|
+
|
73
|
+
### git/ssh_keys
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
### ruby/bundler
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
#### Environment Variables
|
82
|
+
|
83
|
+
| Variable | Default | Required | Description |
|
84
|
+
|:---|:---|:---:|:---|
|
85
|
+
| BUNDLER_INSTALL_PATH | vendor | | |
|
86
|
+
|
87
|
+
### ruby/publish_gem
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
### ruby/rake_test
|
92
|
+
Runs ruby tests by executing the `rake test` command. Uses bundler if bundler is installed.
|
93
|
+
|
94
|
+
|
95
|
+
### ruby/rubocop
|
96
|
+
|
97
|
+
|
98
|
+
|
data/bin/ci-scripts
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
+
require "bundler/setup"
|
4
|
+
|
5
|
+
lib = File.expand_path('../lib', __FILE__)
|
6
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
7
|
+
|
3
8
|
require "ci_scripts"
|
4
9
|
|
5
10
|
if ARGV.count <= 0
|
@@ -13,5 +18,5 @@ if ARGV == ["version"]
|
|
13
18
|
end
|
14
19
|
|
15
20
|
ARGV.each do |script_name|
|
16
|
-
CIScripts.
|
21
|
+
CIScripts::Script.new(script_name).run
|
17
22
|
end
|
data/bin/document
ADDED
@@ -0,0 +1,180 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# rubocop:disable Style/ClassVars
|
3
|
+
|
4
|
+
require 'ripper'
|
5
|
+
require 'erb'
|
6
|
+
require 'pathname'
|
7
|
+
|
8
|
+
require "ci_scripts"
|
9
|
+
require "byebug"
|
10
|
+
|
11
|
+
class FileParser
|
12
|
+
@@function_names = %w(env_require env_check env_fetch run_script)
|
13
|
+
@@base_path = File.absolute_path(File.join(File.dirname(__FILE__), "../lib/scripts"))
|
14
|
+
|
15
|
+
def self.base_path
|
16
|
+
@@base_path
|
17
|
+
end
|
18
|
+
|
19
|
+
def initialize(file)
|
20
|
+
@file = file
|
21
|
+
|
22
|
+
@data = {
|
23
|
+
"environment_variables" => {},
|
24
|
+
"dependencies" => []
|
25
|
+
}
|
26
|
+
|
27
|
+
@contents = File.read(@file)
|
28
|
+
@lines = @contents.lines
|
29
|
+
end
|
30
|
+
|
31
|
+
def parse
|
32
|
+
ast = Ripper.sexp(@contents)
|
33
|
+
|
34
|
+
tree_search(ast, @@function_names)
|
35
|
+
@data
|
36
|
+
end
|
37
|
+
|
38
|
+
def script_name
|
39
|
+
Pathname(@file).relative_path_from(Pathname(@@base_path)).to_s.split(".").first
|
40
|
+
end
|
41
|
+
|
42
|
+
def markdown
|
43
|
+
text = <<-MARKDOWN
|
44
|
+
### <%= script_name %>
|
45
|
+
<%= unindent(script_class_obj.description.strip) if script_class_obj.respond_to? :description %>
|
46
|
+
|
47
|
+
<% if script_class_obj.respond_to? :bin_dependencies -%>
|
48
|
+
This script assumes the following binaries are installed:
|
49
|
+
<% script_class_obj.bin_dependencies.each do |bin| -%>
|
50
|
+
- <%= bin %>
|
51
|
+
<% end -%>
|
52
|
+
<% end -%>
|
53
|
+
<% if @data["dependencies"].any? -%>
|
54
|
+
This script depends on and will run the following other scripts:
|
55
|
+
<% @data["dependencies"].each do |bin| -%>
|
56
|
+
- [<%= bin %>](#<%= bin %>)
|
57
|
+
<% end -%>
|
58
|
+
<% end -%>
|
59
|
+
|
60
|
+
<% if @data["environment_variables"].any? -%>
|
61
|
+
#### Environment Variables
|
62
|
+
|
63
|
+
| Variable | Default | Required | Description |
|
64
|
+
|:---|:---|:---:|:---|
|
65
|
+
<% @data["environment_variables"].each do |key, val| -%>
|
66
|
+
| <%= key %> | <%= val[:default] %> | <%= val[:required] %> | <%= val[:description] %>|
|
67
|
+
<% end -%>
|
68
|
+
|
69
|
+
<% end -%>
|
70
|
+
MARKDOWN
|
71
|
+
|
72
|
+
text = unindent(text)
|
73
|
+
|
74
|
+
ERB.new(text, nil, '-').result(binding)
|
75
|
+
end
|
76
|
+
|
77
|
+
private
|
78
|
+
|
79
|
+
def script_class_obj
|
80
|
+
return @script_class if @script_class
|
81
|
+
class_name = CIScripts::Script.new(script_name).instance_variable_get(:@class_name)
|
82
|
+
@script_class = Object.const_get(class_name)
|
83
|
+
end
|
84
|
+
|
85
|
+
# [:method_add_arg,
|
86
|
+
# [:fcall, [:@ident, "env_require", [4, 6]]],
|
87
|
+
# [:arg_paren,
|
88
|
+
# [:args_add_block,
|
89
|
+
# [[:string_literal,
|
90
|
+
# [:string_content, [:@tstring_content, "DOCKER_IMAGE", [4, 20]]]]],
|
91
|
+
# false]]]
|
92
|
+
def get_function_argument(ast, n)
|
93
|
+
ast[2][1][1][n][1][1][1]
|
94
|
+
end
|
95
|
+
|
96
|
+
def comment_value(ast, regex, lines)
|
97
|
+
line_number = ast[1][1][2][0]
|
98
|
+
lines.times do |i|
|
99
|
+
comment_line = @lines[line_number - 2 - i].strip
|
100
|
+
match = comment_line.match(regex)
|
101
|
+
return match.captures if match
|
102
|
+
end
|
103
|
+
nil
|
104
|
+
end
|
105
|
+
|
106
|
+
def comment_default(ast, lines = 2)
|
107
|
+
val = comment_value(ast, /^# Default: (.*)$/i, lines)
|
108
|
+
val.first if val
|
109
|
+
end
|
110
|
+
|
111
|
+
def comment_description(ast, lines = 2)
|
112
|
+
val = comment_value(ast, /^# Description: (.*)$/i, lines)
|
113
|
+
val.first if val
|
114
|
+
end
|
115
|
+
|
116
|
+
def parse_env_require(ast)
|
117
|
+
@data["environment_variables"][get_function_argument(ast, 0)] = {
|
118
|
+
required: "✔",
|
119
|
+
description: comment_description(ast)
|
120
|
+
}
|
121
|
+
end
|
122
|
+
|
123
|
+
def parse_env_check(ast)
|
124
|
+
default_value = comment_default(ast)
|
125
|
+
@data["environment_variables"][get_function_argument(ast, 0)] = {
|
126
|
+
default: default_value || get_function_argument(ast, 1),
|
127
|
+
description: comment_description(ast)
|
128
|
+
}
|
129
|
+
end
|
130
|
+
|
131
|
+
def parse_env_fetch(ast)
|
132
|
+
default_value = comment_default(ast)
|
133
|
+
@data["environment_variables"][get_function_argument(ast, 0)] = {
|
134
|
+
default: default_value || get_function_argument(ast, 1),
|
135
|
+
description: comment_description(ast)
|
136
|
+
}
|
137
|
+
end
|
138
|
+
|
139
|
+
def parse_run_script(ast)
|
140
|
+
@data["dependencies"].push(get_function_argument(ast, 0))
|
141
|
+
end
|
142
|
+
|
143
|
+
def tree_search(ast, methods)
|
144
|
+
return unless ast.is_a? Array
|
145
|
+
if ast[0] == :method_add_arg && ast[1][0] == :fcall
|
146
|
+
methods.each do |method|
|
147
|
+
if ast[1][1].include? method
|
148
|
+
send("parse_#{method}", ast)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
ast.each { |node| tree_search(node, methods) }
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
readme_text = <<-MARKDOWN
|
157
|
+
# CI Scripts
|
158
|
+
|
159
|
+
A collection of modular scripts that are commonly run in CI. The goal of this project is to reduce the number of CI configuration files that have duplicate code. Environment variables are used to configure the scripts. To include a script add the following to the CI config:
|
160
|
+
|
161
|
+
## Installation
|
162
|
+
```
|
163
|
+
gem install ci-scripts
|
164
|
+
ci-scripts SCRIPT_NAME
|
165
|
+
```
|
166
|
+
|
167
|
+
## Scripts
|
168
|
+
|
169
|
+
MARKDOWN
|
170
|
+
|
171
|
+
readme_text = unindent(readme_text)
|
172
|
+
|
173
|
+
Dir.glob("#{FileParser.base_path}/**/*.rb") do |file|
|
174
|
+
a = FileParser.new(file)
|
175
|
+
a.parse
|
176
|
+
readme_text += a.markdown
|
177
|
+
end
|
178
|
+
|
179
|
+
readme = File.join(File.dirname(__FILE__), "../README.md")
|
180
|
+
File.write(readme, readme_text)
|
data/ci-scripts.gemspec
CHANGED
@@ -21,8 +21,11 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.executables = ["ci-scripts"]
|
22
22
|
spec.require_paths = ["lib"]
|
23
23
|
|
24
|
+
spec.add_dependency "firebase", "~> 0.2.6"
|
25
|
+
|
24
26
|
spec.add_development_dependency "bundler", "~> 1.15"
|
25
27
|
spec.add_development_dependency "rake", "~> 10.0"
|
26
28
|
spec.add_development_dependency "minitest", "~> 5.0"
|
27
29
|
spec.add_development_dependency "rubocop", "~> 0.49.0"
|
30
|
+
spec.add_development_dependency "byebug"
|
28
31
|
end
|
data/lib/ci_scripts.rb
CHANGED
@@ -7,28 +7,43 @@ require "ci_scripts/helpers"
|
|
7
7
|
require "English"
|
8
8
|
|
9
9
|
module CIScripts
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
class Script
|
11
|
+
def initialize(script_name)
|
12
|
+
script_name = script_name.strip
|
13
|
+
full_path = File.join(File.dirname(__FILE__), "scripts", script_name)
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
unless File.exist?("#{full_path}.rb")
|
16
|
+
log_error "#{script_name} does not exists"
|
17
|
+
return
|
18
|
+
end
|
19
|
+
|
20
|
+
require full_path
|
18
21
|
|
19
|
-
|
22
|
+
@class_name = parse_script_name(script_name)
|
23
|
+
end
|
20
24
|
|
21
|
-
|
22
|
-
|
23
|
-
module_name = ""
|
25
|
+
def run
|
26
|
+
return false unless @class_name
|
24
27
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
+
result = Object.const_get(@class_name).new.send("run")
|
29
|
+
return true if result.nil?
|
30
|
+
result
|
28
31
|
end
|
29
32
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
+
private
|
34
|
+
|
35
|
+
def parse_script_name(script)
|
36
|
+
module_name = ""
|
37
|
+
|
38
|
+
script_parts = script.split("/")
|
39
|
+
# function_name = script_parts.pop
|
40
|
+
|
41
|
+
script_parts.each do |part|
|
42
|
+
module_name += "::" unless module_name.empty?
|
43
|
+
module_name += classify(part)
|
44
|
+
end
|
45
|
+
|
46
|
+
module_name
|
47
|
+
end
|
33
48
|
end
|
34
49
|
end
|
data/lib/ci_scripts/helpers.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# #!/usr/bin/ruby
|
2
|
+
require 'open3'
|
2
3
|
|
3
4
|
# Logging
|
4
5
|
def log_info(s)
|
@@ -13,7 +14,7 @@ def log_error(s)
|
|
13
14
|
puts("\x1b[31m#{s}\x1b[0m")
|
14
15
|
end
|
15
16
|
|
16
|
-
def nice_exit(code, msg="Something happened")
|
17
|
+
def nice_exit(code, msg = "Something happened")
|
17
18
|
log_error(msg)
|
18
19
|
exit code
|
19
20
|
end
|
@@ -34,6 +35,10 @@ def timed_run(name)
|
|
34
35
|
log_success("#{(Time.now - t).round(2)}s\n ")
|
35
36
|
end
|
36
37
|
|
38
|
+
def capture_command(*options)
|
39
|
+
Open3.capture2(*options)
|
40
|
+
end
|
41
|
+
|
37
42
|
# system helpers
|
38
43
|
def test_command?(*options)
|
39
44
|
system(*options, out: File::NULL)
|
@@ -52,14 +57,16 @@ def env_check(key, value)
|
|
52
57
|
end
|
53
58
|
end
|
54
59
|
|
55
|
-
def
|
56
|
-
|
60
|
+
def env_require(key)
|
61
|
+
val = ENV[key]
|
62
|
+
if val.nil?
|
57
63
|
log_error "Required environment variable #{key} not set"
|
58
64
|
exit 1
|
59
65
|
end
|
66
|
+
val
|
60
67
|
end
|
61
68
|
|
62
|
-
def env_fetch(key, default =
|
69
|
+
def env_fetch(key, default = nil)
|
63
70
|
if ENV[key]
|
64
71
|
ENV[key]
|
65
72
|
else
|
data/lib/ci_scripts/version.rb
CHANGED
data/lib/scripts/demo/test.rb
CHANGED
data/lib/scripts/docker/build.rb
CHANGED
@@ -1,18 +1,33 @@
|
|
1
1
|
module Docker
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
class Build
|
3
|
+
class << self
|
4
|
+
def description
|
5
|
+
<<-MARKDOWN
|
6
|
+
Uses docker to build the docker image for the current project.
|
7
|
+
MARKDOWN
|
8
|
+
end
|
5
9
|
|
6
|
-
|
7
|
-
|
10
|
+
def bin_dependencies
|
11
|
+
["docker"]
|
12
|
+
end
|
13
|
+
end
|
8
14
|
|
9
|
-
|
10
|
-
|
15
|
+
def run
|
16
|
+
env_require("DOCKER_IMAGE")
|
11
17
|
|
12
|
-
|
13
|
-
|
18
|
+
# set image tag if it hasnt been set
|
19
|
+
# Default: git tag
|
20
|
+
# Description: My favoruite thing
|
21
|
+
env_check("IMAGE_TAG", `git rev-parse HEAD`.strip)
|
14
22
|
|
15
|
-
|
16
|
-
|
23
|
+
dockerfile = env_fetch("BUILD_DOCKERFILE", "Dockerfile")
|
24
|
+
# project_folder = env_fetch("DOCKER_FOLDER", ".")
|
25
|
+
|
26
|
+
# build docker image
|
27
|
+
command("docker build --pull -t \"$DOCKER_IMAGE:$IMAGE_TAG\" -f #{dockerfile} .")
|
28
|
+
|
29
|
+
# push docker image
|
30
|
+
command('docker push "$DOCKER_IMAGE:$IMAGE_TAG"')
|
31
|
+
end
|
17
32
|
end
|
18
33
|
end
|
@@ -1,26 +1,27 @@
|
|
1
1
|
module Docker
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
2
|
+
class Herokuish
|
3
|
+
def run
|
4
|
+
# set image tag if it hasnt been set
|
5
|
+
# also has to support old ruby versions
|
6
|
+
dockerfile_contents = <<-DOCKERFILE
|
7
|
+
FROM gliderlabs/herokuish
|
8
8
|
|
9
|
-
|
9
|
+
COPY . /app
|
10
10
|
|
11
|
-
|
11
|
+
RUN /bin/herokuish buildpack build
|
12
12
|
|
13
|
-
|
14
|
-
|
13
|
+
CMD ["/start", "web"]
|
14
|
+
DOCKERFILE
|
15
15
|
|
16
|
-
|
16
|
+
dockerfile_contents = unindent(dockerfile_contents)
|
17
17
|
|
18
|
-
|
19
|
-
|
18
|
+
timed_run "Creating herokuish dockerfile" do
|
19
|
+
File.write("Dockerfile.herokuish", dockerfile_contents)
|
20
20
|
|
21
|
-
|
22
|
-
|
21
|
+
ENV["BUILD_DOCKERFILE"] = "Dockerfile.herokuish"
|
22
|
+
end
|
23
23
|
|
24
|
-
|
24
|
+
run_script("docker/build")
|
25
|
+
end
|
25
26
|
end
|
26
27
|
end
|
data/lib/scripts/docker/login.rb
CHANGED
@@ -1,17 +1,19 @@
|
|
1
1
|
module Docker
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
2
|
+
class Login
|
3
|
+
def run
|
4
|
+
# set image tag if it hasnt been set
|
5
|
+
env_require("DOCKER_USERNAME")
|
6
|
+
env_require("DOCKER_PASSWORD")
|
7
7
|
|
8
|
-
|
8
|
+
env_check("DOCKER_EMAIL", "ci@ci-runner.com")
|
9
9
|
|
10
|
-
|
10
|
+
# Default: hub.docker.com
|
11
|
+
docker_registry = env_fetch("DOCKER_REGISTRY", nil)
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
# login to docker hub
|
14
|
+
login_command = 'docker login -u "$DOCKER_USERNAME" -p "$DOCKER_PASSWORD" -e "$DOCKER_EMAIL"'
|
15
|
+
login_command += " #{docker_registry}" if docker_registry
|
16
|
+
command(login_command)
|
17
|
+
end
|
16
18
|
end
|
17
19
|
end
|
@@ -1,17 +1,19 @@
|
|
1
1
|
module Docker
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
class PushBranch
|
3
|
+
def run
|
4
|
+
env_require("DOCKER_IMAGE")
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
# set image tag if it hasnt been set
|
7
|
+
# Default: current git hash
|
8
|
+
env_check("IMAGE_TAG", `git rev-parse HEAD`.strip)
|
8
9
|
|
9
|
-
|
10
|
+
branch = `git rev-parse --abbrev-ref HEAD`.strip
|
10
11
|
|
11
|
-
|
12
|
-
|
12
|
+
# tag image
|
13
|
+
command("docker tag \"$DOCKER_IMAGE:$IMAGE_TAG\" \"$DOCKER_IMAGE:#{branch}\"")
|
13
14
|
|
14
|
-
|
15
|
-
|
15
|
+
# push docker image
|
16
|
+
command("docker push \"$DOCKER_IMAGE:#{branch}\"")
|
17
|
+
end
|
16
18
|
end
|
17
19
|
end
|
@@ -1,20 +1,22 @@
|
|
1
1
|
module Docker
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
class PushLatest
|
3
|
+
def run
|
4
|
+
latest_branch = env_fetch("DOCKER_LATEST_BRANCH", "master")
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
branch = `git rev-parse --abbrev-ref HEAD`.strip
|
7
|
+
return if branch != latest_branch
|
8
8
|
|
9
|
-
|
9
|
+
env_require("DOCKER_IMAGE")
|
10
10
|
|
11
|
-
|
12
|
-
|
11
|
+
# set image tag if it hasnt been set
|
12
|
+
# Default: current git hash
|
13
|
+
env_check("IMAGE_TAG", `git rev-parse HEAD`.strip)
|
13
14
|
|
14
|
-
|
15
|
-
|
15
|
+
# tag latest image
|
16
|
+
command('docker tag "$DOCKER_IMAGE:$IMAGE_TAG" "$DOCKER_IMAGE:latest"')
|
16
17
|
|
17
|
-
|
18
|
-
|
18
|
+
# push docker image
|
19
|
+
command('docker push "$DOCKER_IMAGE:latest"')
|
20
|
+
end
|
19
21
|
end
|
20
22
|
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'firebase'
|
2
|
+
require 'digest'
|
3
|
+
|
4
|
+
module Files
|
5
|
+
class ShaFirebase
|
6
|
+
class << self
|
7
|
+
def description
|
8
|
+
<<-MARKDOWN
|
9
|
+
Calculates the sha of specified files and uploads the result to firebase
|
10
|
+
MARKDOWN
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def run
|
15
|
+
firebase_uri = env_require("FIREBASE_URI")
|
16
|
+
firebase_api_key = env_require("FIREBASE_API_KEY")
|
17
|
+
|
18
|
+
sha_version = env_require("SHA_VERSION")
|
19
|
+
sha_folder = env_require("SHA_FOLDER")
|
20
|
+
|
21
|
+
shas = {
|
22
|
+
created: Firebase::ServerValue::TIMESTAMP
|
23
|
+
}
|
24
|
+
|
25
|
+
timed_run "Generating SHA256" do
|
26
|
+
sha256 = Digest::SHA256.new
|
27
|
+
|
28
|
+
return puts "#{sha_folder} does not exist" unless File.exists?(sha_folder)
|
29
|
+
|
30
|
+
Dir.foreach(sha_folder) do |file|
|
31
|
+
next if File.directory?(file)
|
32
|
+
escaped_filename = firebase_escape(file.to_s)
|
33
|
+
shas[escaped_filename.to_sym] = sha256.file(file).hexdigest
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
timed_run "Uploading to firebase" do
|
38
|
+
firebase = Firebase::Client.new(firebase_uri, firebase_api_key)
|
39
|
+
|
40
|
+
url = File.join(git_url, sha_version)
|
41
|
+
latest_url = File.join(git_url, "latest")
|
42
|
+
url = firebase_escape(url)
|
43
|
+
latest_url = firebase_escape(latest_url)
|
44
|
+
|
45
|
+
response = firebase.set(url, shas)
|
46
|
+
unless response.code == 200
|
47
|
+
log_error("Failed to upload to Firebase")
|
48
|
+
nice_exit(0, response.body)
|
49
|
+
end
|
50
|
+
|
51
|
+
response = firebase.set(latest_url, {
|
52
|
+
version: sha_version,
|
53
|
+
}.merge!(shas))
|
54
|
+
unless response.code == 200
|
55
|
+
log_error("Failed to upload to Firebase")
|
56
|
+
nice_exit(0, response.body)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def git_url
|
64
|
+
git_remotes = capture_command("git", "remote", "-v").first
|
65
|
+
url = /(?:git@|https:\/\/)([^\s]+)/.match(git_remotes)[1]
|
66
|
+
url.gsub(":", "/")
|
67
|
+
end
|
68
|
+
|
69
|
+
def firebase_escape(s)
|
70
|
+
s.gsub(".", "_")
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
File without changes
|
data/lib/scripts/git/ssh_keys.rb
CHANGED
@@ -0,0 +1,43 @@
|
|
1
|
+
module Go
|
2
|
+
class Build
|
3
|
+
class << self
|
4
|
+
def description
|
5
|
+
<<-MARKDOWN
|
6
|
+
Builds go binary using gox which enables parallel builds
|
7
|
+
MARKDOWN
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def run
|
12
|
+
command("go", "get", "github.com/mitchellh/gox")
|
13
|
+
|
14
|
+
build_command = ["gox"]
|
15
|
+
|
16
|
+
build_command = add_option("ldflags", build_command)
|
17
|
+
|
18
|
+
parallel = env_fetch("GO_BUILD_PARALLEL", "2")
|
19
|
+
build_command.push("-parallel")
|
20
|
+
build_command.push(parallel)
|
21
|
+
|
22
|
+
build_command = add_option("osarch", build_command)
|
23
|
+
build_command = add_option("output", build_command)
|
24
|
+
|
25
|
+
if gox_args = env_fetch("GO_BUILD_ARGS")
|
26
|
+
build_command.concat(gox_args.split)
|
27
|
+
end
|
28
|
+
|
29
|
+
command(*build_command)
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def add_option(name, build_command)
|
35
|
+
env_name = "GO_BUILD_#{name.upcase}"
|
36
|
+
if val = env_fetch(env_name)
|
37
|
+
build_command.push("-#{name}")
|
38
|
+
build_command.push("\"#{val}\"")
|
39
|
+
end
|
40
|
+
build_command
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/scripts/ruby/bundler.rb
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
module Ruby
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
2
|
+
class Bundler
|
3
|
+
def run
|
4
|
+
unless installed?("bundler")
|
5
|
+
command("gem", "install", "bundler", "--no-ri", "--no-rdoc")
|
6
|
+
end
|
7
7
|
|
8
|
-
|
8
|
+
install_path = env_fetch("BUNDLER_INSTALL_PATH", "vendor")
|
9
9
|
|
10
|
-
|
11
|
-
|
10
|
+
unless test_command?("bundler", "check")
|
11
|
+
command("bundler", "install", "--path", install_path)
|
12
|
+
end
|
12
13
|
end
|
13
14
|
end
|
14
15
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Ruby
|
2
|
+
class PublishGem
|
3
|
+
def run
|
4
|
+
# Bundler release scripts
|
5
|
+
# https://github.com/bundler/bundler/blob/master/lib/bundler/gem_helper.rb
|
6
|
+
# also gemspec loading https://github.com/bundler/bundler/blob/ff4a522e8e75eb4ce5675a99698fb3df23b680be/lib/bundler.rb#L406
|
7
|
+
out, stat = capture_command("bundle", "exec", "rake", "-T")
|
8
|
+
|
9
|
+
if stat && out.include?("rake release[remote]")
|
10
|
+
command("bundle", "exec", "rake", "release")
|
11
|
+
else
|
12
|
+
log_error("bundler/gem_tasks is required to use this script")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -1,13 +1,22 @@
|
|
1
1
|
module Ruby
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
class RakeTest
|
3
|
+
class << self
|
4
|
+
def description
|
5
|
+
<<-MARKDOWN
|
6
|
+
Runs ruby tests by executing the `rake test` command. Uses bundler if bundler is installed.
|
7
|
+
MARKDOWN
|
8
|
+
end
|
6
9
|
end
|
7
10
|
|
8
|
-
|
9
|
-
|
11
|
+
def run
|
12
|
+
if test_command?("bundler", "exec", "rake", "-V")
|
13
|
+
return command("bundler", "exec", "rake", "test")
|
14
|
+
end
|
15
|
+
|
16
|
+
unless installed?("rake")
|
17
|
+
command("gem", "install", "rake")
|
18
|
+
end
|
19
|
+
command("rake", "test")
|
10
20
|
end
|
11
|
-
command("rake", "test")
|
12
21
|
end
|
13
22
|
end
|
data/lib/scripts/ruby/rubocop.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
module Ruby
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
2
|
+
class Rubocop
|
3
|
+
def run
|
4
|
+
unless installed?("rubocop")
|
5
|
+
command("gem", "install", "rubocop")
|
6
|
+
end
|
7
|
+
# ugh check bundle rubocop as well
|
8
|
+
# puts test_command?("bundle exec rubocop")
|
9
9
|
|
10
|
-
|
10
|
+
command("rubocop")
|
11
|
+
end
|
11
12
|
end
|
12
13
|
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ci-scripts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benjamin Caldwell
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: firebase
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.2.6
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.2.6
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,6 +80,20 @@ dependencies:
|
|
66
80
|
- - "~>"
|
67
81
|
- !ruby/object:Gem::Version
|
68
82
|
version: 0.49.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: byebug
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
69
97
|
description:
|
70
98
|
email:
|
71
99
|
- caldwellbenjamin8@gmail.com
|
@@ -74,17 +102,18 @@ executables:
|
|
74
102
|
extensions: []
|
75
103
|
extra_rdoc_files: []
|
76
104
|
files:
|
105
|
+
- ".editorconfig"
|
77
106
|
- ".gitignore"
|
78
107
|
- ".gitlab-ci.yml"
|
79
108
|
- ".rubocop.yml"
|
80
109
|
- CODE_OF_CONDUCT.md
|
81
110
|
- Gemfile
|
82
111
|
- LICENSE
|
83
|
-
- LICENSE.txt
|
84
112
|
- README.md
|
85
113
|
- Rakefile
|
86
114
|
- bin/ci-scripts
|
87
115
|
- bin/console
|
116
|
+
- bin/document
|
88
117
|
- bin/setup
|
89
118
|
- ci-scripts.gemspec
|
90
119
|
- lib/ci_scripts.rb
|
@@ -96,11 +125,15 @@ files:
|
|
96
125
|
- lib/scripts/docker/login.rb
|
97
126
|
- lib/scripts/docker/push_branch.rb
|
98
127
|
- lib/scripts/docker/push_latest.rb
|
128
|
+
- lib/scripts/files/sha_firebase.rb
|
129
|
+
- lib/scripts/files/tarball.rb
|
99
130
|
- lib/scripts/git/ssh_keys.rb
|
131
|
+
- lib/scripts/go/build.rb
|
100
132
|
- lib/scripts/go/glide
|
101
133
|
- lib/scripts/go/install
|
102
134
|
- lib/scripts/go/test
|
103
135
|
- lib/scripts/ruby/bundler.rb
|
136
|
+
- lib/scripts/ruby/publish_gem.rb
|
104
137
|
- lib/scripts/ruby/rake_test.rb
|
105
138
|
- lib/scripts/ruby/rubocop.rb
|
106
139
|
homepage: http://github.com/benjamincaldwell/ci-scripts
|
data/LICENSE.txt
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
3
|
-
Copyright (c) 2017 Benjamin Caldwell
|
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.
|