kubernetes_helper 1.0 → 1.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/README.md +5 -5
- data/lib/kubernetes_helper/core.rb +3 -1
- data/lib/kubernetes_helper/version.rb +1 -1
- data/lib/kubernetes_helper.rb +8 -0
- data/lib/templates/{_replicas.yml.erb → _replicas.yml} +0 -0
- data/lib/templates/{_sidekiq_alive_gem.yml.erb → _sidekiq_alive_gem.yml} +0 -0
- data/lib/templates/cd.sh +19 -15
- data/lib/templates/certificate.yml +7 -0
- data/lib/templates/deployment.yml +16 -3
- data/lib/templates/ingress.yml +1 -7
- data/lib/templates/service.yml +4 -2
- data/lib/templates/settings.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 954aee8be3740b9cedb7496bd66ad857328ee8e1bf72a3571947bc70f849d97a
|
4
|
+
data.tar.gz: e9a33fa7278d6fd5eb844067c5378490588ce44e71df439c6e5178e24fcc5e73
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bab608c022fec18c45f6a0aa84f5d3528d0e455d1cf9670a3c07c8cc65d4115642c924d9d1482140037892d7e48282826b98ed55ed87d923a8aed5b809ca0c52
|
7
|
+
data.tar.gz: a8a65ba45e6c362928f07788909497b8bb8ec8eb152ad72ea998c0af5f55bb9d0de06adc94ff256d97b2719da4b8aec43f606739999cd753825670cef020f3d1
|
data/README.md
CHANGED
@@ -11,7 +11,10 @@ kubernetes_helper generate_templates
|
|
11
11
|
```
|
12
12
|
Note: Requires ruby 1.7+
|
13
13
|
|
14
|
-
##
|
14
|
+
## Deployment
|
15
|
+
Once you generated the basic templates, it comes with the corresponding [readme.md](/lib/templates/README.md) which includes all the steps to deploy your application.
|
16
|
+
|
17
|
+
## API
|
15
18
|
- Run any kubernetes document
|
16
19
|
`DEPLOY_ENV=<env name> kubernetes_helper run_deployment "<document name>" "<bash command>"`
|
17
20
|
Evaluates the kubernetes document with the following details:
|
@@ -46,10 +49,7 @@ When performing a command or script, the setting variables are replaced based on
|
|
46
49
|
All these setting variable values are configured in `.kubernetes/settings.rb` which defines the values based on `DEPLOY_ENV`.
|
47
50
|
These setting variables use [erb](https://github.com/ruby/erb) template gem to define variable replacement and conditional blocks, and so on.
|
48
51
|
Note: Setting variable values are referenced as an object format instead of a hash format for simplicity.
|
49
|
-
|
50
|
-
|
51
|
-
## Deployment
|
52
|
-
Once you generated the basic templates, it comes with the corresponding [readme.md](/lib/templates/README.md) which includes all the steps to deploy your application.
|
52
|
+
|
53
53
|
|
54
54
|
## Sample
|
55
55
|
https://owen2345.github.io/kubernetes_helper/
|
@@ -22,7 +22,7 @@ module KubernetesHelper
|
|
22
22
|
|
23
23
|
# @param _env_name (String)
|
24
24
|
def initialize(_env_name)
|
25
|
-
@config_values = KubernetesHelper.load_settings
|
25
|
+
@config_values = KubernetesHelper.default_settings.merge(KubernetesHelper.load_settings)
|
26
26
|
end
|
27
27
|
|
28
28
|
def parse_yml_file(file_path, output_path)
|
@@ -115,6 +115,8 @@ module KubernetesHelper
|
|
115
115
|
def parse_documents(yml_data)
|
116
116
|
documents = []
|
117
117
|
Array(yml_data).each do |document|
|
118
|
+
next unless document
|
119
|
+
|
118
120
|
document['documents'] ? documents.push(*document['documents']) : documents.push(document)
|
119
121
|
end
|
120
122
|
documents
|
data/lib/kubernetes_helper.rb
CHANGED
@@ -20,6 +20,14 @@ module KubernetesHelper
|
|
20
20
|
settings
|
21
21
|
end
|
22
22
|
|
23
|
+
def self.default_settings
|
24
|
+
{
|
25
|
+
cloud: {
|
26
|
+
name: 'gcloud'
|
27
|
+
}
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
23
31
|
def self.settings_path(file_name = nil, use_template: false)
|
24
32
|
path = File.join(Dir.pwd, FOLDER_NAME)
|
25
33
|
if file_name
|
File without changes
|
File without changes
|
data/lib/templates/cd.sh
CHANGED
@@ -12,26 +12,30 @@ PROJECT_NAME="<%=continuous_deployment.project_name%>"
|
|
12
12
|
CLUSTER_REGION="<%=continuous_deployment.cluster_region%>"
|
13
13
|
DOCKER_BUILD_CMD="<%=continuous_deployment.docker_build_cmd || 'build -f Dockerfile'%>"
|
14
14
|
|
15
|
-
CI_COMMIT_SHA=$(git rev-parse --verify HEAD)
|
15
|
+
CI_COMMIT_SHA=$(git rev-parse --verify HEAD || :)
|
16
|
+
CI_COMMIT_SHA=${CI_COMMIT_SHA:-$(date +%s) }
|
16
17
|
DEPLOY_NAME="${IMAGE_NAME}:${CI_COMMIT_SHA}"
|
17
18
|
LATEST_NAME="${IMAGE_NAME}:latest"
|
18
|
-
AUTH_PATH="$SCRIPT_DIR/k8s-auth-token.json"
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
20
|
+
if [ ! -z "$KB_AUTH_TOKEN" ]
|
21
|
+
then
|
22
|
+
AUTH_PATH="$SCRIPT_DIR/k8s-auth-token.json"
|
23
|
+
rm -f -- $AUTH_PATH
|
24
|
+
echo $KB_AUTH_TOKEN >> $AUTH_PATH
|
25
|
+
|
26
|
+
## ***** GOOGLE CONNECTOR
|
27
|
+
# Download and install Google Cloud SDK
|
28
|
+
if [ -z "$(which gcloud)" ]; then
|
29
|
+
export CLOUDSDK_CORE_DISABLE_PROMPTS=1; curl https://sdk.cloud.google.com | bash && source /home/runner/google-cloud-sdk/path.bash.inc && gcloud --quiet components update kubectl
|
30
|
+
fi
|
31
|
+
|
32
|
+
# Connect to cluster
|
33
|
+
gcloud auth activate-service-account --key-file $AUTH_PATH --project $PROJECT_NAME
|
34
|
+
gcloud docker --authorize-only --project $PROJECT_NAME
|
35
|
+
gcloud container clusters get-credentials $CLUSTER_NAME --region $CLUSTER_REGION
|
36
|
+
## ***** END GOOGLE CONNECTOR
|
27
37
|
fi
|
28
38
|
|
29
|
-
# Connect to cluster
|
30
|
-
gcloud auth activate-service-account --key-file $AUTH_PATH --project $PROJECT_NAME
|
31
|
-
gcloud docker --authorize-only --project $PROJECT_NAME
|
32
|
-
gcloud container clusters get-credentials $CLUSTER_NAME --region $CLUSTER_REGION
|
33
|
-
## ***** END GOOGLE CONNECTOR
|
34
|
-
|
35
39
|
|
36
40
|
## Build and push containers
|
37
41
|
docker $DOCKER_BUILD_CMD -t $DEPLOY_NAME .
|
@@ -46,32 +46,42 @@ documents:
|
|
46
46
|
- &log_volume
|
47
47
|
name: applog
|
48
48
|
mountPath: /app/log
|
49
|
+
|
50
|
+
<% if deployment.cloud_secret_name %>
|
49
51
|
- &cloud_credentials_volume
|
50
52
|
name: gcloud-creds
|
51
53
|
mountPath: /secrets/gcloud
|
52
54
|
readOnly: true
|
55
|
+
<% end %>
|
53
56
|
|
57
|
+
<% if deployment.cloud_secret_name %>
|
54
58
|
- &cloudsql_container
|
55
59
|
image: gcr.io/cloudsql-docker/gce-proxy:1.09 # Cloud sql proxy
|
56
60
|
name: cloudsql-proxy
|
57
61
|
command: ["/cloud_sql_proxy", "--dir=/cloudsql",
|
58
62
|
"-instances=<%=deployment.cloud_sql_instance%>",
|
59
63
|
"-credential_file=/secrets/gcloud/credentials.json"]
|
64
|
+
env: []
|
60
65
|
volumeMounts:
|
61
66
|
- *cloud_credentials_volume
|
67
|
+
<% end %>
|
62
68
|
|
63
69
|
- &logs_container # print to stdout all log files
|
64
70
|
name: print-logs
|
65
71
|
image: busybox
|
66
|
-
command: [/bin/sh, -c, 'until find log/*.log; do sleep 1; done; tail -n+1 -f log/*.log']
|
72
|
+
command: [/bin/sh, -c, 'until find /app/log/*.log; do sleep 1; done; tail -n+1 -f /app/log/*.log']
|
73
|
+
env: []
|
67
74
|
volumeMounts:
|
68
75
|
- *log_volume
|
69
76
|
|
70
77
|
terminationGracePeriodSeconds: 120
|
71
78
|
volumes:
|
79
|
+
<% if deployment.cloud_secret_name %>
|
72
80
|
- name: gcloud-creds
|
73
81
|
secret:
|
74
82
|
secretName: '<%=deployment.cloud_secret_name%>'
|
83
|
+
<% end %>
|
84
|
+
|
75
85
|
- name: applog
|
76
86
|
emptyDir: {}
|
77
87
|
|
@@ -100,7 +110,7 @@ documents:
|
|
100
110
|
<% end %>
|
101
111
|
|
102
112
|
<% if deployment.job_sidekiq_alive_gem %>
|
103
|
-
<%= include_template "_sidekiq_alive_gem.yml
|
113
|
+
<%= include_template "_sidekiq_alive_gem.yml" %>
|
104
114
|
<% else %>
|
105
115
|
ports: [ ]
|
106
116
|
<% if (deployment.job_services || []).any? %>
|
@@ -116,10 +126,13 @@ documents:
|
|
116
126
|
<% end %>
|
117
127
|
<% end %>
|
118
128
|
|
129
|
+
<% if deployment.cloud_secret_name %>
|
119
130
|
- *cloudsql_container
|
131
|
+
<% end %>
|
132
|
+
|
120
133
|
- <<: *logs_container
|
121
134
|
<% end %>
|
122
135
|
|
123
136
|
<% if deployment.replicas_range %>
|
124
|
-
<%= include_template "_replicas.yml
|
137
|
+
<%= include_template "_replicas.yml" %>
|
125
138
|
<% end %>
|
data/lib/templates/ingress.yml
CHANGED
@@ -1,11 +1,5 @@
|
|
1
1
|
<% if ingress.domain_name %>
|
2
|
-
|
3
|
-
kind: ManagedCertificate
|
4
|
-
metadata:
|
5
|
-
name: '<%=ingress.certificate_name%>'
|
6
|
-
spec:
|
7
|
-
domains: # does not support for willcard domains
|
8
|
-
- '<%=ingress.domain_name%>'
|
2
|
+
<%= include_template "certificate.yml" %>
|
9
3
|
<% end %>
|
10
4
|
|
11
5
|
---
|
data/lib/templates/service.yml
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
<% if cloud.name == 'gcloud' %>
|
1
2
|
---
|
2
3
|
# used to increase request timeout
|
3
4
|
apiVersion: cloud.google.com/v1beta1
|
@@ -6,16 +7,17 @@ metadata:
|
|
6
7
|
name: '<%=service.config_name%>'
|
7
8
|
spec:
|
8
9
|
timeoutSec: 1800
|
9
|
-
|
10
10
|
---
|
11
|
-
|
11
|
+
<% end %>
|
12
12
|
|
13
13
|
kind: Service
|
14
14
|
apiVersion: v1
|
15
15
|
metadata:
|
16
16
|
name: '<%=service.name%>'
|
17
17
|
annotations:
|
18
|
+
<% if cloud.name == 'gcloud' %>
|
18
19
|
beta.cloud.google.com/backend-config: '{"ports": {"80":"<%=service.config_name%>"}}'
|
20
|
+
<% end %>
|
19
21
|
spec:
|
20
22
|
selector:
|
21
23
|
name: '<%=deployment.name%>'
|
data/lib/templates/settings.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
is_production = ENV['DEPLOY_ENV'] == 'production'
|
4
|
-
app_name = is_production ? '
|
4
|
+
app_name = is_production ? 'my-app' : 'my-beta-app' # underscore not accepted
|
5
5
|
settings = {
|
6
6
|
deployment: {
|
7
7
|
name: app_name,
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kubernetes_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '1.
|
4
|
+
version: '1.4'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- owen2345
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-09-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: erb
|
@@ -40,9 +40,10 @@ files:
|
|
40
40
|
- lib/kubernetes_helper/railtie.rb
|
41
41
|
- lib/kubernetes_helper/version.rb
|
42
42
|
- lib/templates/README.md
|
43
|
-
- lib/templates/_replicas.yml
|
44
|
-
- lib/templates/_sidekiq_alive_gem.yml
|
43
|
+
- lib/templates/_replicas.yml
|
44
|
+
- lib/templates/_sidekiq_alive_gem.yml
|
45
45
|
- lib/templates/cd.sh
|
46
|
+
- lib/templates/certificate.yml
|
46
47
|
- lib/templates/deployment.yml
|
47
48
|
- lib/templates/ingress.yml
|
48
49
|
- lib/templates/secrets.yml
|