minos 0.3.1 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f3edf8ef19ced58587308297037a6e8b97f52bc7c8ac7b3860103f75590ce1ee
4
- data.tar.gz: 0eae29c964734492960f12f895bcd6427a682bf7072bbffc19c40af64ae1dd02
3
+ metadata.gz: ed42480e69026ee8407a729c8448ab478dda30a41df536fd33dbf54ab34b14da
4
+ data.tar.gz: c28143cbd6fbe7a9b66bcb70b8efd15d0b1e2e14402ce3546a5de2258b3a63df
5
5
  SHA512:
6
- metadata.gz: 80205457db0bd8e437564c0327bcea5ce5f1c103e2366d51169256068579326c92899291a13e4d2f4dc2f97d57a6799fd6dab2936f15b269c2117cf2e086f454
7
- data.tar.gz: ed251dbd5fbf9e06495afe41d16127b7115f0ea5474f8d45ea8f9c963f015b80ab7fb8ef2b3c69f39bf3b84783cb1dfe6b4ccbc03e89ae8dc17b142319db8506
6
+ metadata.gz: '019fcfb42de45eeb468ffbc16258c65f9ed5cf26f58c74ff7ab6c5d3b25de055b47793eefe417968d68641b1c8976980b835e0cd4eee4a3b501b4c2fcd8b3455'
7
+ data.tar.gz: 9d86167b076b6d232e3c3d67e90b4b261cb95be76db440f3ea35f60a31d76cc9bd517b2eaa28b01d3c1bb270ef90642af7d314a4baf45718961a7da8087e34c2
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.5.3
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- minos (0.3.1)
4
+ minos (0.3.3)
5
5
  activesupport (~> 5.2)
6
6
  dry-matcher (~> 0.7)
7
7
  dry-monads (~> 1.2)
@@ -15,6 +15,7 @@ GEM
15
15
  i18n (>= 0.7, < 2)
16
16
  minitest (~> 5.1)
17
17
  tzinfo (~> 1.1)
18
+ coderay (1.1.2)
18
19
  concurrent-ruby (1.1.4)
19
20
  dry-core (0.4.7)
20
21
  concurrent-ruby (~> 1.0)
@@ -26,7 +27,11 @@ GEM
26
27
  dry-equalizer
27
28
  i18n (1.5.3)
28
29
  concurrent-ruby (~> 1.0)
30
+ method_source (0.9.2)
29
31
  minitest (5.11.3)
32
+ pry (0.12.2)
33
+ coderay (~> 1.1.0)
34
+ method_source (~> 0.9.0)
30
35
  rake (10.5.0)
31
36
  thor (0.20.3)
32
37
  thread_safe (0.3.6)
@@ -39,6 +44,7 @@ PLATFORMS
39
44
  DEPENDENCIES
40
45
  bundler (~> 1.17)
41
46
  minos!
47
+ pry
42
48
  rake (~> 10.0)
43
49
 
44
50
  BUNDLED WITH
data/examples/Dockerfile CHANGED
@@ -1,6 +1,6 @@
1
1
  ######################
2
2
  # Stage: builder
3
- FROM busybox as builder
3
+ FROM nginx as builder
4
4
 
5
5
  ENV HOME /home/app
6
6
  WORKDIR $HOME
@@ -11,7 +11,7 @@ CMD ["ls", "-l"]
11
11
 
12
12
  ###############################
13
13
  # Stage release
14
- FROM busybox as release
14
+ FROM nginx as release
15
15
 
16
16
  ENV HOME /home/app
17
17
  WORKDIR $HOME
data/examples/minos.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  build:
2
2
  artifacts:
3
3
  - name: builder
4
- image: textmasterapps/busybox
4
+ image: textmasterapps/nginx
5
5
  tags:
6
6
  - "$TARGET-$REVISION"
7
7
  - "$TARGET-latest"
@@ -10,11 +10,11 @@ build:
10
10
  tag: "$IMAGE:$TARGET" # $IMAGE and $TARGET are automatically populated as env vars for you
11
11
  target: builder
12
12
  cacheFrom:
13
- - textmasterapps/busybox:builder
14
- - textmasterapps/busybox:builder-$REVISION
15
- - textmasterapps/busybox:builder-latest
13
+ - textmasterapps/nginx:builder
14
+ - textmasterapps/nginx:builder-$REVISION
15
+ - textmasterapps/nginx:builder-latest
16
16
  - name: release
17
- image: textmasterapps/busybox
17
+ image: textmasterapps/nginx
18
18
  tags:
19
19
  - "$REVISION" # you can reference ENV variables from your shell
20
20
  - "latest"
@@ -26,7 +26,7 @@ build:
26
26
  ENV: "production"
27
27
  REVISION: "$REVISION"
28
28
  cacheFrom:
29
- - textmasterapps/busybox:builder
30
- - textmasterapps/busybox:release
31
- - textmasterapps/busybox:$REVISION
32
- - textmasterapps/busybox:latest
29
+ - textmasterapps/nginx:builder
30
+ - textmasterapps/nginx:release
31
+ - textmasterapps/nginx:$REVISION
32
+ - textmasterapps/nginx:latest
@@ -1,8 +1,13 @@
1
+ require 'open3'
2
+ require 'minos/utils'
1
3
  require 'active_support/core_ext/string/inflections'
2
4
 
3
5
  module Minos
4
6
  class Artifact
5
- include Dry::Monads::Result::Mixin
7
+ include Dry::Monads::Task::Mixin
8
+ include Dry::Monads::List::Mixin
9
+ include Dry::Monads::Do.for(:build, :push)
10
+ include Thor::Shell
6
11
 
7
12
  attr_reader :artifact, :options
8
13
 
@@ -15,63 +20,108 @@ module Minos
15
20
  artifact['name']
16
21
  end
17
22
 
18
- def pull
19
- caches.map do |cache|
20
- docker_pull(cache)
21
- end
22
- end
23
-
24
23
  def build
25
- docker_build
24
+ yield List::Task[
25
+ *caches.map.each_with_index { |cache, i| docker_pull(i, cache) }
26
+ ]
27
+ .traverse
28
+ .bind { |_| docker_build }
29
+ .to_result
26
30
  end
27
31
 
28
32
  def push
29
- docker_push
33
+ yield List::Task[
34
+ *tags.map.each_with_index { |tag, i| docker_push(i, tag) }
35
+ ]
36
+ .traverse
37
+ .to_result
30
38
  end
31
39
 
32
40
  private
33
41
 
34
- def docker_pull(cache)
35
- if run "docker inspect #{cache} -f '{{json .ID}}' > /dev/null 2>&1 || docker pull #{cache} 2> /dev/null"
36
- Success(cache)
37
- else
38
- Failure(cache)
39
- end
42
+ def docker_pull(i, cache)
43
+ Task[:io, &-> {
44
+ color = select_color(i)
45
+ print "Pulling #{cache}...", color: color
46
+ if run "docker inspect #{cache} -f '{{json .ID}}' > /dev/null 2>&1 || docker pull #{cache} 2> /dev/null", color: color
47
+ print "Using #{cache}", color: color
48
+ else
49
+ # noop
50
+ end
51
+ }]
40
52
  end
41
53
 
42
54
  def docker_build
43
- if run "docker build #{to_args(docker)} ."
44
- Success(name)
45
- else
46
- Failure(name)
47
- end
55
+ Task[:io, &-> {
56
+ color = :green
57
+ print "Building #{target}...", color: color
58
+ if run "docker build --rm #{Minos::Utils.to_args(docker)} .", color: color
59
+ print "Successfully built #{target}", color: color
60
+ else
61
+ print "Failed building #{target}", :red
62
+ raise StandardError.new($?)
63
+ end
64
+ }]
48
65
  end
49
66
 
50
- def docker_push
51
- tags.map do |tag|
52
- if run "docker tag #{image}:#{target} #{image}:#{tag} && docker push #{image}:#{tag}"
53
- Success("#{image}:#{tag}")
67
+ def docker_push(i, tag)
68
+ Task[:io, &-> {
69
+ color = select_color(i)
70
+ print "Pushing #{image}:#{tag}...", color: color
71
+ if run "docker tag #{image}:#{target} #{image}:#{tag} && docker push #{image}:#{tag}", color: color
72
+ print "Successfully pushed #{image}:#{tag}", color: color
54
73
  else
55
- Failure("#{image}:#{tag}")
74
+ print "Failed pushing #{image}:#{tag}", :red
75
+ raise StandardError.new($?)
76
+ end
77
+ }]
78
+ end
79
+
80
+ def run(cmd, color: colors.first)
81
+ Open3.popen3("#{Minos::Utils.to_envs(env)} ; #{cmd}") do |stdin, stdout, stderr, wait_thr|
82
+ t_out = Thread.new do
83
+ while line = stdout.gets do
84
+ print(line, color: color)
85
+ end
86
+ end
87
+
88
+ t_err = Thread.new do
89
+ while line = stderr.gets do
90
+ print(line, color: :red)
91
+ end
56
92
  end
93
+
94
+ wait_thr.join
95
+ t_err.join
96
+ t_out.join
97
+
98
+ stdin.close
99
+ stdout.close
100
+ stderr.close
101
+
102
+ wait_thr.value.success?
57
103
  end
58
104
  end
59
105
 
60
- def run(cmd)
61
- system("#{envs_as_cmd} && #{cmd}")
106
+ def print(msg, color: colors.first)
107
+ say_status(name, msg, color)
108
+ end
109
+
110
+ def select_color(i)
111
+ colors[i % colors.count + 1]
112
+ end
113
+
114
+ def colors
115
+ %i(blue cyan yellow magenta)
62
116
  end
63
117
 
64
- def envs
118
+ def env
65
119
  {
66
120
  'IMAGE' => image,
67
121
  'TARGET' => target,
68
122
  }
69
123
  end
70
124
 
71
- def envs_as_cmd
72
- envs.map { |k, v| "#{k}=\"#{v}\"" }.join(' ')
73
- end
74
-
75
125
  def docker
76
126
  artifact['docker']
77
127
  end
@@ -91,22 +141,5 @@ module Minos
91
141
  def tags
92
142
  artifact['tags'].to_a
93
143
  end
94
-
95
- def to_args(args)
96
- args.map do |key, value|
97
- case value
98
- when Array
99
- value.map do |v|
100
- "--#{key.underscore.gsub('_', '-')} #{v}"
101
- end
102
- when Hash
103
- value.map do |k, v|
104
- "--#{key.underscore.gsub('_', '-')} #{k}=#{v}"
105
- end
106
- else
107
- "--#{key.underscore.gsub('_', '-')} #{value}"
108
- end
109
- end.flatten.join(' ')
110
- end
111
144
  end
112
145
  end
data/lib/minos/cli.rb CHANGED
@@ -1,27 +1,49 @@
1
1
  module Minos
2
2
  class CLI < Thor
3
- class_option :manifest, default: "./minos.yaml", desc: "Manifest config file describing docker artifacts"
4
- class_option :only, type: :array, default: [], desc: "Process only given artifacts"
5
- class_option :except, type: :array, default: [], desc: "Process all but given artifacts"
3
+ include Thor::Shell
6
4
 
7
5
  desc "build", "Build docker artifacts specified in the manifest"
6
+ option :manifest, default: "./minos.yaml", desc: "Manifest config file describing docker artifacts"
7
+ option :only, type: :array, default: [], desc: "Process only given artifacts"
8
+ option :except, type: :array, default: [], desc: "Process all but given artifacts"
8
9
  def build
9
- invoke 'minos:docker:build', []
10
+ artifacts.each do |a|
11
+ artifact = Artifact.new(a, options: options)
12
+ artifact.build
13
+ end
10
14
  end
11
15
 
12
16
  desc "push", "Publish docker artifacts specified in the manifest"
17
+ option :manifest, default: "./minos.yaml", desc: "Manifest config file describing docker artifacts"
18
+ option :only, type: :array, default: [], desc: "Process only given artifacts"
19
+ option :except, type: :array, default: [], desc: "Process all but given artifacts"
13
20
  def push
14
- invoke 'minos:docker:push', []
15
- end
16
-
17
- desc "deploy", "Deploy docker artifacts specified in the manifest"
18
- def deploy
19
- invoke 'minos:k8s:deploy', []
21
+ artifacts.each do |a|
22
+ artifact = Artifact.new(a, options: options)
23
+ artifact.push
24
+ end
20
25
  end
21
26
 
22
27
  desc "version", "Display Minos version"
23
28
  def version
24
29
  puts Minos::VERSION
25
30
  end
31
+
32
+ private
33
+
34
+ def artifacts
35
+ artifacts = parse['build']['artifacts'].to_a
36
+ artifacts.reject! { |a| options[:except].include?(a['name']) } if options[:except].count > 0
37
+ artifacts.select! { |a| options[:only].include?(a['name']) } if options[:only].count > 0
38
+ artifacts
39
+ end
40
+
41
+ def parse
42
+ @parse ||= YAML.load(read)
43
+ end
44
+
45
+ def read
46
+ File.read(options[:manifest])
47
+ end
26
48
  end
27
49
  end
@@ -0,0 +1,26 @@
1
+ module Minos
2
+ class Utils
3
+ # Flatten args as an array, hash or string into CLI args.
4
+ def self.to_args(args)
5
+ args.map do |key, value|
6
+ case value
7
+ when Array
8
+ value.map do |v|
9
+ "--#{key.underscore.gsub('_', '-')} #{v}"
10
+ end
11
+ when Hash
12
+ value.map do |k, v|
13
+ "--#{key.underscore.gsub('_', '-')} #{k}=#{v}"
14
+ end
15
+ else
16
+ "--#{key.underscore.gsub('_', '-')} #{value}"
17
+ end
18
+ end.flatten.join(' ')
19
+ end
20
+
21
+ # Flatten env as hash into shell's environment variables.
22
+ def self.to_envs(env)
23
+ env.map { |k, v| "#{k}=\"#{v}\"" }.join(' ')
24
+ end
25
+ end
26
+ end
data/lib/minos/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Minos
2
- VERSION = '0.3.1'
2
+ VERSION = '0.3.3'
3
3
  end
data/lib/minos.rb CHANGED
@@ -1,11 +1,11 @@
1
1
  require 'yaml'
2
2
  require 'thor'
3
- require "dry/monads/result"
4
- require "dry/matcher/result_matcher"
3
+ require 'dry/monads/task'
4
+ require 'dry/monads/result'
5
+ require 'dry/monads/list'
6
+ require 'dry/monads/do'
5
7
 
6
8
  require 'minos/artifact'
7
- require 'minos/docker'
8
- require 'minos/k8s'
9
9
  require 'minos/cli'
10
10
  require 'minos/version'
11
11
 
data/minos.gemspec CHANGED
@@ -30,4 +30,5 @@ Gem::Specification.new do |spec|
30
30
 
31
31
  spec.add_development_dependency "bundler", "~> 1.17"
32
32
  spec.add_development_dependency "rake", "~> 10.0"
33
+ spec.add_development_dependency "pry"
33
34
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minos
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pierre-Louis Gottfrois
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-02-12 00:00:00.000000000 Z
11
+ date: 2019-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '10.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  description: Easy and repeatable Kubernetes deployment based on Docker images
98
112
  email:
99
113
  - pierre-louis@textmaster.com
@@ -103,6 +117,7 @@ extensions: []
103
117
  extra_rdoc_files: []
104
118
  files:
105
119
  - ".gitignore"
120
+ - ".ruby-version"
106
121
  - CODE_OF_CONDUCT.md
107
122
  - Gemfile
108
123
  - Gemfile.lock
@@ -117,8 +132,7 @@ files:
117
132
  - lib/minos.rb
118
133
  - lib/minos/artifact.rb
119
134
  - lib/minos/cli.rb
120
- - lib/minos/docker.rb
121
- - lib/minos/k8s.rb
135
+ - lib/minos/utils.rb
122
136
  - lib/minos/version.rb
123
137
  - minos.gemspec
124
138
  homepage: https://github.com/textmaster/minos
@@ -141,7 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
155
  version: '0'
142
156
  requirements: []
143
157
  rubyforge_project:
144
- rubygems_version: 2.7.6
158
+ rubygems_version: 2.7.8
145
159
  signing_key:
146
160
  specification_version: 4
147
161
  summary: Easy and repeatable Kubernetes deployment based on Docker images
data/lib/minos/docker.rb DELETED
@@ -1,75 +0,0 @@
1
- module Minos
2
- class Docker < Thor
3
- include Thor::Shell
4
-
5
- class_option :manifest, default: "./minos.yaml", desc: "Manifest config file describing docker artifacts"
6
- class_option :only, type: :array, default: [], desc: "Process only given artifacts"
7
- class_option :except, type: :array, default: [], desc: "Process all but given artifacts"
8
-
9
- desc "build", "Build docker artifacts specified in the manifest"
10
- def build
11
- artifacts.each do |a|
12
- artifact = Artifact.new(a, options: options)
13
-
14
- # Pull
15
- artifact.pull.each do |result|
16
- Dry::Matcher::ResultMatcher.(result) do |m|
17
- m.success do |name|
18
- say_status artifact.name, "Using #{name}"
19
- end
20
- m.failure do |name|
21
- # noop
22
- # failure here means we don't have docker image locally
23
- end
24
- end
25
- end
26
-
27
- # Build
28
- Dry::Matcher::ResultMatcher.(artifact.build) do |m|
29
- m.success do |name|
30
- say_status artifact.name, "Successfully built #{name}"
31
- end
32
- m.failure do |name|
33
- say_status artifact.name, "Failed building #{name}", :red
34
- exit 1
35
- end
36
- end
37
- end
38
- end
39
-
40
- desc "push", "Publish docker artifacts specified in the manifest"
41
- def push
42
- artifacts.each do |a|
43
- artifact = Artifact.new(a, options: options)
44
- artifact.push.each do |result|
45
- Dry::Matcher::ResultMatcher.(result) do |m|
46
- m.success do |name|
47
- say_status artifact.name, "Successfully pushed #{name}"
48
- end
49
- m.failure do |name|
50
- say_status artifact.name, "Failed pushing #{name}", :red
51
- exit 1
52
- end
53
- end
54
- end
55
- end
56
- end
57
-
58
- private
59
-
60
- def artifacts
61
- artifacts = parse['build']['artifacts'].to_a
62
- artifacts.reject! { |a| options[:except].include?(a['name']) } if options[:except].count > 0
63
- artifacts.select! { |a| options[:only].include?(a['name']) } if options[:only].count > 0
64
- artifacts
65
- end
66
-
67
- def parse
68
- @parse ||= YAML.load(read)
69
- end
70
-
71
- def read
72
- File.read(options[:manifest])
73
- end
74
- end
75
- end
data/lib/minos/k8s.rb DELETED
@@ -1,8 +0,0 @@
1
- module Minos
2
- class K8s < Thor
3
- desc "deploy", "Deploy docker artifacts specified in the manifest"
4
- def deploy
5
- puts "not implemented"
6
- end
7
- end
8
- end