njord 0.1.3 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e1f779aa1dabcd22824c02ef6e8937a9a0f82ecb2501ea3028adf753561ca242
4
- data.tar.gz: e22141b4e3c2f18657eb0dd49651f9dd271383c4b5a05013ef92c893e0071ad8
3
+ metadata.gz: ebf061d4eb10b738341d40e91bf9edf89a93ce0fa1f280e24190e3019ed6cb5f
4
+ data.tar.gz: 2477f6b61a16810c76a07e2212bac7a3146745825a974bb748c72e14557cb8e5
5
5
  SHA512:
6
- metadata.gz: e1110ee6d6962d1e7cfac0b957dab3a617f25195cc9671fe68db395da70f6f07299a9420c3c1256724322b1d490f37f014162a0c7e85f5debc2a3d3c550336e0
7
- data.tar.gz: 9fd55e362233e528a7a0662387005c0807a12ee2539ffd74a163a80c4cf81ee10b491093a1f7639d60d58abb48e772ee10831ba71dbd01f24dce52864af14677
6
+ metadata.gz: b8e051d1266de46a18810f2d5c8ea653b8117fbc6375f2d3a6486d62fda2b132e0a25b68ae7edec22da403a8730488e30d5a4101ce5440cbe5ed305cc8ac6260
7
+ data.tar.gz: 17b55cc38c3c339fbd5a5ce1c12a48ebd78b8e807003f7389508eef8313a21f56ac8d07fe25246403485faf965bd8034166d466977f625617d40536c21156d43
data/exe/njord CHANGED
@@ -1,9 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
-
3
2
  $LOAD_PATH.unshift("#{__dir__}/../lib")
4
-
5
3
  require 'njord'
6
4
 
7
- cli = Njord::CLI.new
8
- status = cli.run
9
- exit(status)
5
+ Njord::CLI.start
data/lib/njord.rb CHANGED
@@ -1,14 +1,13 @@
1
+ require 'thor'
2
+ require 'njord/cli'
1
3
  require "njord/docker_handler"
2
4
  require "njord/configuration_reader"
3
5
  require "njord/version"
4
- require 'njord/cli'
5
6
 
6
7
  module Njord
7
8
  class << self
8
- attr_accessor :config
9
-
10
- def configure(config)
11
- self.config ||= config
9
+ def config
10
+ @config ||= ConfigurationReader.read_from_file
12
11
  end
13
12
  end
14
13
  end
data/lib/njord/cli.rb CHANGED
@@ -1,24 +1,23 @@
1
+ require "njord/commands/kubernetes"
2
+
1
3
  module Njord
2
- class CLI
3
- attr_accessor :config
4
-
5
- def initialize
6
- config = ConfigurationReader.read_from_file
7
- Njord.configure(config)
4
+ class CLI < Thor
5
+ desc "build", "Builds the docker container from a Dockerfile"
6
+ def build
7
+ DockerHandler.build_images
8
+ DockerHandler.tag_images
9
+ end
10
+
11
+ desc "push", "Pushes the docker container to the defined host"
12
+ def push
13
+ DockerHandler.push_images
8
14
  end
9
15
 
10
- def run(args = ARGV)
11
- njord = self.class.new
12
- case args[0]
13
- when "build"
14
- DockerHandler.build_images
15
- DockerHandler.tag_images
16
- when "push"
17
- DockerHandler.push_images
18
- end
19
- return 0
20
- rescue RuntimeError
21
- return 1
16
+ desc "k8s", "Kubernetes related tasks"
17
+ subcommand "k8s", Njord::Commands::Kubernetes
18
+
19
+ def self.exit_on_failure?
20
+ true
22
21
  end
23
22
  end
24
23
  end
@@ -0,0 +1,14 @@
1
+ require_relative 'kubernetes_setup'
2
+
3
+ module Njord
4
+ module Commands
5
+ class Kubernetes < Thor
6
+ def self.banner(command, _namespace = nil, _subcommand = false)
7
+ "#{basename} k8s #{command.usage}"
8
+ end
9
+
10
+ desc "setup", "Setups the files needed for the deployment to kubernetes"
11
+ subcommand "setup", Njord::Commands::KubernetesSetup
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,78 @@
1
+ module Njord
2
+ module Commands
3
+ class KubernetesSetup < Thor
4
+ include Thor::Actions
5
+ attr_accessor :config
6
+
7
+ APPNAME = "njord-blog"
8
+ NAMESPACE = "njord-namespace"
9
+ ENVIRONMENT = "production"
10
+ HOSTNAME = "blog.njord.com"
11
+
12
+ desc "all", "Configures all resources needed to run a rails project"
13
+ def all
14
+ init
15
+ setup(:deployment)
16
+ setup(:service)
17
+ setup(:configmap)
18
+ setup(:ingress)
19
+ end
20
+
21
+ desc "deployment", "Configures the deployment resource"
22
+ def deployment
23
+ init
24
+ setup(:deployment)
25
+ end
26
+
27
+ desc "service", "Configures the service resource"
28
+ def service
29
+ init
30
+ setup(:service)
31
+ end
32
+
33
+ desc "configmap", "Configures the configmap resource"
34
+ def configmap
35
+ init
36
+ setup(:configmap)
37
+ end
38
+
39
+ desc "ingress", "Configures the ingress resource"
40
+ def ingress
41
+ init
42
+ setup(:ingress)
43
+ end
44
+
45
+ def self.banner(command, _namespace = nil, _subcommand = false)
46
+ "#{basename} k8s setup #{command.usage}"
47
+ end
48
+
49
+ def self.source_root
50
+ "#{__dir__}/../templates/kubernetes"
51
+ end
52
+
53
+ private
54
+ def init
55
+ @config = {}
56
+ @config[:appname] = ask("Name of your app [#{APPNAME}]", default: APPNAME)
57
+ @config[:namespace] = ask("Namespace of your app [#{NAMESPACE}]", default: NAMESPACE)
58
+ @config[:environment] = ask("Environment your app is running in [#{ENVIRONMENT}]", default: ENVIRONMENT)
59
+ @config[:hostname] = ask("Hostname of your app [#{HOSTNAME}]", default: HOSTNAME)
60
+ @config[:imagename] = ask("Name of your Dockerimage including repo [#{full_image_name}]", default: full_image_name)
61
+ end
62
+
63
+ def setup(resource)
64
+ case resource
65
+ when :deployment then template("deployments.yaml.tt", "deployment/deployments.yaml", @config)
66
+ when :service then template("services.yaml.tt", "deployment/services.yaml", @config)
67
+ when :configmap then template("configmaps.yaml.tt", "deployment/configmaps.yaml", @config)
68
+ when :ingress then template("ingresses.yaml.tt", "deployment/ingresses.yaml", @config)
69
+ end
70
+ end
71
+
72
+ def full_image_name
73
+ image = Njord.config.images.first
74
+ "#{image.docker_repo}/#{image.image_name}:latest"
75
+ end
76
+ end
77
+ end
78
+ end
@@ -4,17 +4,18 @@ require 'ostruct'
4
4
 
5
5
  module Njord
6
6
  module ConfigurationReader
7
- CONFIG_FILE = ".njord.yml"
7
+ CONFIG_FILE = ".njord.yml".freeze
8
8
 
9
9
  def self.read_from_file
10
10
  if File.exist?(CONFIG_FILE)
11
- JSON.parse(YAML::load_file(CONFIG_FILE).to_json, object_class: OpenStruct)
11
+ JSON.parse(YAML.load_file(CONFIG_FILE).to_json, object_class: OpenStruct)
12
12
  else
13
- raise ArgumentError.new("No .njord.yml config file exists. Please create one.") if config.nil?
13
+ raise(ArgumentError, "No .njord.yml config file exists. \
14
+ Please create one.")
14
15
  end
15
16
  rescue
16
- raise ArgumentError.new("Something is wrong with the .njord.yml - please check the README for a valid example.") if config.nil?
17
+ raise(ArgumentError, "Something is wrong with the .njord.yml - \
18
+ please check the README for a valid example.")
17
19
  end
18
20
  end
19
21
  end
20
-
@@ -0,0 +1,7 @@
1
+ apiVersion: v1
2
+ kind: ConfigMap
3
+ data:
4
+ MEMCACHED_HOST: memcached.memcached.svc.cluster.local
5
+ metadata:
6
+ name: <%= config[:appname] %>-<%= config[:environment] %>-config
7
+ namespace: <%= config[:namespace] %>
@@ -0,0 +1,117 @@
1
+ apiVersion: apps/v1
2
+ kind: Deployment
3
+ metadata:
4
+ name: <%= config[:appname] %>-<%= config[:environment] %>
5
+ namespace: <%= config[:namespace] %>
6
+ labels:
7
+ app: <%= config[:appname] %>-<%= config[:environment] %>
8
+ spec:
9
+ replicas: 1
10
+ strategy:
11
+ rollingUpdate:
12
+ maxSurge: 1
13
+ maxUnavailable: 0
14
+ type: RollingUpdate
15
+ selector:
16
+ matchLabels:
17
+ app: <%= config[:appname] %>-<%= config[:environment] %>
18
+ template:
19
+ metadata:
20
+ labels:
21
+ app: <%= config[:appname] %>-<%= config[:environment] %>
22
+ spec:
23
+ volumes:
24
+ - name: rails-data
25
+ emptyDir: {}
26
+ containers:
27
+ - env:
28
+ - name: RAILS_ENV
29
+ value: production
30
+ envFrom:
31
+ - configMapRef:
32
+ name: <%= config[:appname] %>-<%= config[:environment] %>-config
33
+ - secretRef:
34
+ name: <%= config[:appname] %>-<%= config[:environment] %>-dbconfig
35
+ image: <%= config[:imagename] %>
36
+ imagePullPolicy: Always
37
+ volumeMounts:
38
+ - name: rails-data
39
+ mountPath: /app/public-shared
40
+ lifecycle:
41
+ postStart:
42
+ exec:
43
+ command: ["/bin/sh", "-c", "cp -r /app/public/* /app/public-shared"]
44
+ livenessProbe:
45
+ failureThreshold: 3
46
+ httpGet:
47
+ path: /healthcheck
48
+ port: 3000
49
+ scheme: HTTP
50
+ initialDelaySeconds: 10
51
+ periodSeconds: 10
52
+ successThreshold: 1
53
+ timeoutSeconds: 10
54
+ name: <%= config[:appname] %>-<%= config[:environment] %>
55
+ readinessProbe:
56
+ failureThreshold: 3
57
+ httpGet:
58
+ path: /healthcheck
59
+ port: 3000
60
+ scheme: HTTP
61
+ initialDelaySeconds: 10
62
+ periodSeconds: 10
63
+ successThreshold: 2
64
+ timeoutSeconds: 10
65
+ resources:
66
+ requests:
67
+ memory: "512Mi"
68
+ cpu: "500m"
69
+ limits:
70
+ memory: "1024Mi"
71
+ cpu: "1000m"
72
+ securityContext:
73
+ allowPrivilegeEscalation: false
74
+ privileged: false
75
+ procMount: Default
76
+ readOnlyRootFilesystem: false
77
+ runAsNonRoot: false
78
+ stdin: true
79
+ tty: true
80
+ - env:
81
+ - name: HTTPS_PROXY_REDIRECT
82
+ value: "1"
83
+ - name: NGINX_SERVER_NAME
84
+ value: <%= config[:hostname] %>
85
+ image: nexus.devops-e.de:8090/ema/rails-http:latest
86
+ imagePullPolicy: Always
87
+ volumeMounts:
88
+ - name: rails-data
89
+ mountPath: /app/public
90
+ name: <%= config[:appname] %>-<%= config[:environment] %>-nginx
91
+ ports:
92
+ - containerPort: 80
93
+ name: 80tcp2
94
+ protocol: TCP
95
+ resources:
96
+ requests:
97
+ memory: "128Mi"
98
+ cpu: "125m"
99
+ limits:
100
+ memory: "256Mi"
101
+ cpu: "250m"
102
+ securityContext:
103
+ allowPrivilegeEscalation: false
104
+ privileged: false
105
+ procMount: Default
106
+ readOnlyRootFilesystem: false
107
+ runAsNonRoot: false
108
+ stdin: true
109
+ tty: true
110
+ dnsPolicy: ClusterFirst
111
+ hostAliases:
112
+ - hostnames:
113
+ - rails
114
+ ip: 127.0.0.1
115
+ imagePullSecrets:
116
+ - name: nexus
117
+ restartPolicy: Always
@@ -0,0 +1,22 @@
1
+ apiVersion: extensions/v1beta1
2
+ kind: Ingress
3
+ metadata:
4
+ name: <%= config[:appname] %>-production
5
+ namespace: <%= config[:namespace] %>
6
+ annotations:
7
+ kubernetes.io/ingress.class: nginx
8
+ cert-manager.io/cluster-issuer: letsencrypt-prod
9
+ nginx.ingress.kubernetes.io/from-to-www-redirect: "true"
10
+ spec:
11
+ tls:
12
+ - hosts:
13
+ - www.<%= config[:hostname] %>
14
+ - <%= config[:hostname] %>
15
+ secretName: letsencrypt-<%= config[:appname] %>-prod
16
+ rules:
17
+ - host: www.<%= config[:hostname] %>
18
+ http:
19
+ paths:
20
+ - backend:
21
+ serviceName: <%= config[:appname] %>-production
22
+ servicePort: 80
@@ -0,0 +1,15 @@
1
+ apiVersion: v1
2
+ kind: Service
3
+ metadata:
4
+ name: <%= config[:appname] %>-<%= config[:environment] %>
5
+ namespace: <%= config[:namespace] %>
6
+ spec:
7
+ selector:
8
+ app: <%= config[:appname] %>-<%= config[:environment] %>
9
+ ports:
10
+ - name: default
11
+ port: 80
12
+ protocol: TCP
13
+ targetPort: 80
14
+ sessionAffinity: ClientIP
15
+ type: ClusterIP
data/lib/njord/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Njord
2
- VERSION = "0.1.3"
2
+ VERSION = "0.2.0".freeze
3
3
  end
data/njord.gemspec CHANGED
@@ -34,4 +34,5 @@ Gem::Specification.new do |spec|
34
34
 
35
35
  spec.add_development_dependency "bundler", "~> 2.0"
36
36
  spec.add_development_dependency "rake", "~> 10.0"
37
+ spec.add_development_dependency "thor", "~> 1.0"
37
38
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: njord
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Trierweiler
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-01-08 00:00:00.000000000 Z
11
+ date: 2020-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: thor
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
41
55
  description:
42
56
  email:
43
57
  - danieltrierweiler@gmail.com
@@ -56,8 +70,14 @@ files:
56
70
  - exe/njord
57
71
  - lib/njord.rb
58
72
  - lib/njord/cli.rb
73
+ - lib/njord/commands/kubernetes.rb
74
+ - lib/njord/commands/kubernetes_setup.rb
59
75
  - lib/njord/configuration_reader.rb
60
76
  - lib/njord/docker_handler.rb
77
+ - lib/njord/templates/kubernetes/configmaps.yaml.tt
78
+ - lib/njord/templates/kubernetes/deployments.yaml.tt
79
+ - lib/njord/templates/kubernetes/ingresses.yaml.tt
80
+ - lib/njord/templates/kubernetes/services.yaml.tt
61
81
  - lib/njord/version.rb
62
82
  - njord.gemspec
63
83
  homepage: https://github.com/DTrierweiler/njord