mkit 0.4.1 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
data/lib/mkit.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rubygems'
2
4
  require 'bundler'
3
5
  require 'json'
@@ -10,13 +12,14 @@ require 'sinatra/base'
10
12
  require 'mkit/config/environment'
11
13
  require 'mkit/app/mkit_server'
12
14
  require 'mkit/config/load_default_configs'
13
- require_relative "mkit/version"
15
+ require_relative 'mkit/version'
14
16
  require_relative 'mkit/mkit_interface'
15
17
  require_relative 'mkit/mkit_dns'
16
18
  require_relative 'mkit/docker_listener'
17
19
  require 'mkit/app/helpers/haproxy'
18
20
  require 'mkit/app/controllers/services_controller'
19
21
  require 'mkit/app/controllers/mkitjobs_controller'
22
+ require 'mkit/app/controllers/mkit_controller'
20
23
  require 'mkit/mkit_interface'
21
24
  require 'mkit/mkit_dns'
22
25
  require 'mkit/job_manager'
@@ -40,23 +43,23 @@ module MKIt
40
43
  MKItLogger.debug!
41
44
  #
42
45
  # config dir
43
- if ENV["RACK_ENV"] != "development"
44
- @config_dir = options[:config_dir].nil? ? '/etc/mkit' : options[:config_dir]
45
- else
46
- @config_dir = options[:config_dir].nil? ? "#{@root}/config" : options[:config_dir]
47
- end
46
+ @config_dir = if ENV['RACK_ENV'] != 'development'
47
+ options[:config_dir].nil? ? '/etc/mkit' : options[:config_dir]
48
+ else
49
+ options[:config_dir].nil? ? "#{@root}/config" : options[:config_dir]
50
+ end
48
51
  MKIt::Utils.set_config_dir(@config_dir)
49
52
  # create dirs
50
- if ENV["RACK_ENV"] != "development" || !options[:config_dir].nil?
53
+ if ENV['RACK_ENV'] != 'development' || !options[:config_dir].nil?
51
54
  check_config_files = false
52
- if ! File.exists?(@config_dir)
55
+ unless File.exist?(@config_dir)
53
56
  FileUtils.mkdir_p(@config_dir)
54
57
  check_config_files = true
55
58
  end
56
- FileUtils.mkdir_p('/var/lib/mkitd') unless File.exists?('/var/lib/mkitd')
57
- FileUtils.cp( "#{@root}/config/mkit_config.yml", @config_dir) unless File.exists?("#{@config_dir}/mkit_config.yml")
58
- FileUtils.cp( "#{@root}/config/database.yml", @config_dir) unless File.exists?("#{@config_dir}/database.yml")
59
- FileUtils.cp( "#{@root}/config/mkitd_config.sh", @config_dir) unless File.exists?("#{@config_dir}/mkitd_config.sh")
59
+ FileUtils.mkdir_p('/var/lib/mkitd') unless File.exist?('/var/lib/mkitd')
60
+ FileUtils.cp("#{@root}/config/mkit_config.yml", @config_dir) unless File.exist?("#{@config_dir}/mkit_config.yml")
61
+ FileUtils.cp("#{@root}/config/database.yml", @config_dir) unless File.exist?("#{@config_dir}/database.yml")
62
+ FileUtils.cp("#{@root}/config/mkitd_config.sh", @config_dir) unless File.exist?("#{@config_dir}/mkitd_config.sh")
60
63
  if check_config_files
61
64
  MKItLogger.info "Configuration files copied to #{@config_dir}. Please check it and restart."
62
65
  exit
@@ -69,10 +72,12 @@ module MKIt
69
72
  # run config based tasks
70
73
  FileUtils.mkdir_p(MKIt::Config.mkit.haproxy.config_dir)
71
74
  # ...haproxy defaults file
72
- FileUtils.cp(
73
- "#{MKIt::Utils.root}/lib/mkit/app/templates/haproxy/0000_defaults.cfg",
74
- MKIt::Config.mkit.haproxy.config_dir
75
- ) unless File.exists?("#{MKIt::Config.mkit.haproxy.config_dir}/0000_defaults.cfg")
75
+ unless File.exist?("#{MKIt::Config.mkit.haproxy.config_dir}/0000_defaults.cfg")
76
+ FileUtils.cp(
77
+ "#{MKIt::Utils.root}/lib/mkit/app/templates/haproxy/0000_defaults.cfg",
78
+ MKIt::Config.mkit.haproxy.config_dir
79
+ )
80
+ end
76
81
  #
77
82
  # conn = { adapter: "sqlite3", database: ":memory:" }
78
83
  # ActiveRecord::Base.establish_connection(conn)
@@ -81,18 +86,16 @@ module MKIt
81
86
  # DatabaseTasks.db_dir = 'db'
82
87
  #
83
88
  DatabaseTasks.database_configuration = MKIt::Utils.load_db_config
84
- DatabaseTasks.env=MKIt::Config.mkit.database.env
85
- DatabaseTasks.migrations_paths=[ "#{@root}/db/migrate" ]
86
- DatabaseTasks.db_dir="db"
87
- DatabaseTasks.root=@root
89
+ DatabaseTasks.env = MKIt::Config.mkit.database.env
90
+ DatabaseTasks.migrations_paths = ["#{@root}/db/migrate"]
91
+ DatabaseTasks.db_dir = 'db'
92
+ DatabaseTasks.root = @root
88
93
  end
89
94
 
90
95
  def self.establish_db_connection
91
- #
92
96
  ActiveRecord::Base.establish_connection(DatabaseTasks.database_configuration[DatabaseTasks.env])
93
97
  ActiveRecord::Base.connection.migration_context.migrations_paths.clear
94
98
  ActiveRecord::Base.connection.migration_context.migrations_paths << "#{@root}/db/migrate"
95
- #
96
99
  MKItLogger.debug "database_tasks migration paths #{DatabaseTasks.migrations_paths}"
97
100
  MKItLogger.debug "active_record_base migration_paths #{ActiveRecord::Base.connection.migration_context.migrations_paths.inspect}"
98
101
  MKItLogger.debug "active_record_base configurations #{ActiveRecord::Base.configurations.inspect}"
@@ -100,62 +103,58 @@ module MKIt
100
103
  end
101
104
 
102
105
  def self.migrate
103
- ActiveRecord::Base.connection.migration_context.migrate if ActiveRecord::Base.connection.migration_context.needs_migration?
106
+ if ActiveRecord::Base.connection.migration_context.needs_migration?
107
+ ActiveRecord::Base.connection.migration_context.migrate
108
+ end
104
109
  end
105
110
 
106
111
  def self.restore_operation
107
- MKItLogger.info "restoring operations..."
112
+ MKItLogger.info 'restoring operations...'
108
113
  # create interfaces of deployed apps otherwise haproxy won't start
109
- Service.all.each { | srv |
114
+ Service.all.each do |srv|
110
115
  srv.deploy_network
111
116
  srv.update_status!
112
- }
117
+ end
113
118
  # daemontools would eventually start haproxy; systemd does not.
114
119
  # so, restart here.
120
+ MKItLogger.debug 'restarting proxy...'
115
121
  MKIt::HAProxy.restart
116
122
  end
117
123
 
118
124
  def self.startup(options: {})
119
- self.configure(options: options)
120
- self.establish_db_connection
121
- self.migrate
125
+ configure(options: options)
126
+ establish_db_connection
127
+ migrate
122
128
 
123
129
  MKIt::Initializers.load_default_configs
124
130
  MKIt::Interface.up
125
131
 
126
- System.register(:job_manager, memoize: true) {
132
+ System.register(:job_manager, memoize: true) do
127
133
  MKIt::JobManager.new
128
- }
129
- System.register(:mkit_dns, memoize: true) {
130
- Thread.new {
134
+ end
135
+ System.register(:mkit_dns, memoize: true) do
136
+ Thread.new do
131
137
  dns = MKIt::DNS.new
132
138
  dns.run
133
- }
134
- }
135
- System.register(:docker_listener, memoize: true) {
139
+ end
140
+ end
141
+ System.register(:docker_listener, memoize: true) do
136
142
  MKIt::DockerListener.new
137
- }
143
+ end
138
144
  # watchdog feature is to be re-evaluated
139
145
  # System.register(:watchdog, memoize: true) {
140
146
  # MKIt::WatchdogManager.new
141
147
  # }
142
148
 
143
149
  # register workers
144
- WorkerManager.register_workers
150
+ WorkerManager.register_workers
145
151
  SagaManager.register_workers
146
- #
147
152
  System[:job_manager].start
148
153
  System[:docker_listener].start
149
154
  # watchdog feature is to be re-evaluated
150
155
  # System[:watchdog].start
151
156
  System[:mkit_dns].run
152
- #
153
- self.restore_operation
154
- #
155
- MKItLogger.debug "restarting proxy..."
156
- MKIt::HAProxy.restart
157
- MKItLogger.info "MKIt is up and running!"
157
+ restore_operation
158
+ MKItLogger.info 'MKIt is up and running!'
158
159
  end
159
-
160
160
  end
161
-
data/mkit.gemspec CHANGED
@@ -1,40 +1,38 @@
1
- # encoding: UTF-8
1
+ # frozen_string_literal: true
2
2
 
3
- lib = File.expand_path("../lib", __FILE__)
3
+ lib = File.expand_path('lib', __dir__)
4
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
- require "mkit/version"
5
+ require 'mkit/version'
6
6
 
7
7
  Gem::Specification.new do |s|
8
- s.name = 'mkit'
9
- s.summary = 'Micro Kubernets on Ruby'
10
- s.bindir = 'bin'
11
- s.homepage = 'https://github.com/valexsantos/mkit'
12
- s.license = 'Apache-2.0'
13
- s.rubyforge_project = ''
14
- s.description = 'Micro k8s on Ruby - a simple tool to deploy containers to mimic a (very) minimalistic k8 cluster with a nice REST API'
15
- # s.require_paths = ["."]
16
- s.author = 'Vasco Santos'
17
- s.email = ['valexsantos@gmail.com']
18
- s.version = MKIt::VERSION
19
- s.platform = Gem::Platform::RUBY
20
- s.files = Dir.chdir(File.expand_path('..', __FILE__)) do
21
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|TODO|db/development.sqlite)}) }
22
- end
23
- s.executables << 'mkitd'
24
- s.executables << 'mkitc'
25
- s.add_runtime_dependency 'net-ping', '~> 2.0', '>= 2.0.8'
26
- s.add_runtime_dependency 'dry-container', '~> 0.9', '>= 0.9.0'
27
- s.add_runtime_dependency 'sqlite3', '~> 1.5', '>= 1.5.4'
28
- s.add_runtime_dependency 'standalone_migrations', '~> 7.1', '>= 7.1.0'
29
- s.add_runtime_dependency 'sinatra-activerecord', '~> 2.0', '>= 2.0.26'
30
- s.add_runtime_dependency 'rack', '~> 2.2', '>= 2.2.5'
31
- s.add_runtime_dependency 'rack-protection', '~> 3.0', '>= 3.0.5'
32
- s.add_runtime_dependency 'rack-test', '~> 2.0', '>= 2.0.2'
33
- s.add_runtime_dependency 'pry', '~> 0.14', '>= 0.14.2'
34
- s.add_runtime_dependency 'rubydns', '~> 2.0', '>= 2.0.2'
35
- s.add_runtime_dependency 'async-dns', '~> 1.3', '>= 1.3.0'
36
- s.add_runtime_dependency 'sinatra', '~> 3.0', '>= 3.0.5'
37
- s.add_runtime_dependency 'thin', '~> 1.8', '>= 1.8.1'
38
- s.add_runtime_dependency 'net_http_unix', '~> 0.2', '>= 0.2.2'
8
+ s.name = 'mkit'
9
+ s.summary = 'Micro Kubernets on Ruby'
10
+ s.bindir = 'bin'
11
+ s.homepage = 'https://github.com/valexsantos/mkit'
12
+ s.license = 'MIT'
13
+ s.description = 'Micro k8s on Ruby - a simple tool to deploy containers to mimic a (very) minimalistic k8 cluster with a nice REST API'
14
+ # s.require_paths = ["."]
15
+ s.author = 'Vasco Santos'
16
+ s.email = ['valexsantos@gmail.com']
17
+ s.version = MKIt::VERSION
18
+ s.platform = Gem::Platform::RUBY
19
+ s.files = Dir.chdir(File.expand_path(__dir__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|TODO|db/development.sqlite)}) }
21
+ end
22
+ s.executables << 'mkitd'
23
+ s.executables << 'mkitc'
24
+ s.add_runtime_dependency 'async-dns', '~> 1.3', '>= 1.3.0'
25
+ s.add_runtime_dependency 'dry-container', '~> 0.9', '>= 0.9.0'
26
+ s.add_runtime_dependency 'net_http_unix', '~> 0.2', '>= 0.2.2'
27
+ s.add_runtime_dependency 'net-ping', '~> 2.0', '>= 2.0.8'
28
+ s.add_runtime_dependency 'pry', '~> 0.14', '>= 0.14.2'
29
+ s.add_runtime_dependency 'rack', '~> 2.2', '>= 2.2.5'
30
+ s.add_runtime_dependency 'rack-protection', '~> 3.0', '>= 3.0.5'
31
+ s.add_runtime_dependency 'rack-test', '~> 2.0', '>= 2.0.2'
32
+ s.add_runtime_dependency 'rubydns', '~> 2.0', '>= 2.0.2'
33
+ s.add_runtime_dependency 'sinatra', '~> 3.0', '>= 3.0.5'
34
+ s.add_runtime_dependency 'sinatra-activerecord', '~> 2.0', '>= 2.0.26'
35
+ s.add_runtime_dependency 'sqlite3', '~> 1.5', '>= 1.5.4'
36
+ s.add_runtime_dependency 'standalone_migrations', '~> 7.1', '>= 7.1.0'
37
+ s.add_runtime_dependency 'thin', '~> 1.8', '>= 1.8.1'
39
38
  end
40
-
@@ -0,0 +1,21 @@
1
+ #
2
+ service:
3
+ name: kafka-cluster
4
+ network: kafka-cluster
5
+ image: confluentinc/cp-kafka:7.1.6
6
+ ports:
7
+ - 9092:9092:tcp:round_robin
8
+ volumes:
9
+ - docker://kafka_cluster_secrets:/etc/kafka/secrets
10
+ - docker://kafka_cluster_data:/var/lib/kafka/data
11
+ environment:
12
+ KAFKA_BROKER_ID: 1
13
+ KAFKA_ZOOKEEPER_CONNECT: kafka-zookeeper:2181
14
+ KAFKA_AUTO_CREATE_TOPICS_ENABLE: "true"
15
+ KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka-cluster:9092
16
+ KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT
17
+ # KAFKA_CONFLUENT_SCHEMA_REGISTRY_URL: http://kafka-schema-registry
18
+ KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
19
+ KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1
20
+ KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1
21
+
@@ -0,0 +1,16 @@
1
+ #
2
+ service:
3
+ name: kafka-magic
4
+ network: kafka-cluster
5
+ ports:
6
+ - 80:80:http:round_robin
7
+ image: digitsy/kafka-magic
8
+ environment:
9
+ KMAGIC_ALLOW_TOPIC_DELETE: "true"
10
+ KMAGIC_ALLOW_SCHEMA_DELETE: "true"
11
+ KMAGIC_CONFIG_STORE_TYPE: "file"
12
+ KMAGIC_CONFIG_STORE_CONNECTION: "Data Source=/config/KafkaMagicConfig.db;"
13
+ KMAGIC_CONFIG_ENCRYPTION_KEY: "123456"
14
+ volumes:
15
+ - docker://kafka_magic_config:/config
16
+
@@ -0,0 +1,15 @@
1
+ #
2
+ service:
3
+ name: kafka-zookeeper
4
+ image: confluentinc/cp-zookeeper:7.1.6
5
+ network: kafka-cluster
6
+ ports:
7
+ - 2181:2181:tcp:round_robin
8
+ volumes:
9
+ - docker://kafka_zookeeper_secrets:/etc/zookeeper/secrets
10
+ - docker://kafka_zookeeper_data:/var/lib/zookeeper/data
11
+ - docker://kafka_zookeeper_log:/var/lib/zookeeper/log
12
+ environment:
13
+ ZOOKEEPER_CLIENT_PORT: 2181
14
+ ZOOKEEPER_TICK_TIME: 2000
15
+
@@ -0,0 +1,16 @@
1
+ #
2
+ service:
3
+ name: minio
4
+ image: minio/minio
5
+ command: server /data --console-address ":9001"
6
+ network: bridge
7
+ ports:
8
+ - 9001:9001:http:round_robin
9
+ - 9000:9000:tcp:round_robin
10
+ environment:
11
+ MINIO_ACCESS_KEY: minio
12
+ MINIO_SECRET_KEY: minio123
13
+ volumes:
14
+ #- docker://minio_data:/data
15
+ - /tmp/minio_data:/data
16
+
@@ -0,0 +1,9 @@
1
+ #
2
+ service:
3
+ name: mongo
4
+ image: mongo:4.0
5
+ command: "--smallfiles"
6
+ network: bridge
7
+ ports:
8
+ - 27017:27017:tcp:round_robin
9
+
@@ -0,0 +1,13 @@
1
+ #
2
+ service:
3
+ name: nexus
4
+ image: sonatype/nexus3
5
+ network: bridge
6
+ ports:
7
+ - 80:8081:http:round_robin
8
+ resources:
9
+ max_replicas: 1
10
+ min_replicas: 1
11
+ volumes:
12
+ - docker://nexus_data:/nexus-data
13
+
@@ -0,0 +1,11 @@
1
+ #
2
+ service:
3
+ name: redis-sentinel
4
+ image: bitnami/redis-sentinel:latest
5
+ network: bridge
6
+ ports:
7
+ - 26379:26379:tcp:round_robin
8
+ environment:
9
+ REDIS_MASTER_HOST: redis
10
+
11
+
@@ -0,0 +1,9 @@
1
+ #
2
+ service:
3
+ name: redis
4
+ image: redis:4.0-alpine
5
+ network: bridge
6
+ ports:
7
+ - 6379:6379:tcp:round_robin
8
+
9
+