kubernetes_helper 1.19.0 → 1.20.1

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: 3d37444885845a0d47f9824c6b9e220f278ae7db62de9cc7d3222d3ea91da753
4
- data.tar.gz: 64834c2950efa2394c032adfacdd13b8dcb392d7a5346a6101fb7c7c04e30c92
3
+ metadata.gz: 06d96c71b76d19776633e4c87af5dd1ef111411e1e547cc3c1ed02b02dd8dbe4
4
+ data.tar.gz: b1d06ffb2d9171a8ee8b2bdb3df4c040ae5e0b61e0ba4b2ade820b01c8633b21
5
5
  SHA512:
6
- metadata.gz: aa17228790e2b026d284272ae7312d9a241d00646be1fb904b863fec037c266d95e853932d3d4c62147db54e9b167d30a89191f50d8d7ae5da74605b963f7100
7
- data.tar.gz: 65a3991a40379500a37789b37af86c258d472d627a48e95f108366050ff9300f7cc4851981e3723092074dbe161d2366935022df629447117a6cce0e7d137609
6
+ metadata.gz: '09f1196d7c49cb45b312ce5f7b5a3a1a95a69687008d72387cee15bd7b587e0c86448c8084fb95c42e64f0590a970521be8c0900a46e4f742fa78f20e0a3f313'
7
+ data.tar.gz: 5f30b70d43b0d622a95ed011830bdf8f0df54458251a4f7382e894e7a1f2eac69d9e97e146f8372a8055a3d929bb0c4a832c7efabe7c60a1db346e963acfa79a
data/README.md CHANGED
@@ -49,17 +49,44 @@ Configuration and customization can be done for multiple environments and at any
49
49
  - `deployment.logs_resources` (Hash, optional): Configure depending on the app requirements. Default: `{ cpu: { max: '200m', min: '50m' }, mem: { max: '200Mi', min: '50Mi' } }`
50
50
 
51
51
  ### Application deployment.yml for jobs or services without internet interaction (Optional)
52
+ Ideal to run sidekiq or similar jobs as a service without interacting via HTTP.
52
53
  - `deployment.job_apps[].name` (String, optional): Job deployment name (Note: Underscores are not accepted). Sample: `my-app-job`. Note: This deployment is created only if this value is present
53
54
  - `deployment.job_apps[].command` (String, optional): Bash command to be used for job container. Sample: `bundle exec sidekiq`
54
55
  - `deployment.job_apps[].sidekiq_alive_gem` (Boolean, default false): If true will add liveness checker settings using `sidekiq_alive_gem` (`sidekiq_alive` gem needs to be present in your Gemfile)
55
56
  - `deployment.job_apps[].services` (Array, Optional): List of linux service names that are required for a healthy job container. Sample: `['sidekiq', 'cron']`. Note: This will be ignored if `sidekiq_alive_gem` was defined.
56
57
  - `deployment.job_apps[].resources` (Hash, optional): Configure depending on the job app requirements. Sample: `{ cpu: { max: '1', min: '500m' }, mem: { max: '1Gi', min: '500Mi' } }`
58
+ Sample:
59
+ ```ruby
60
+ {
61
+ job_apps: [
62
+ {
63
+ name: "my-app-sidekiq",
64
+ command: 'bundle exec sidekiq',
65
+ services: %w[sidekiq],
66
+ resources: { mem: { max: '10Gi', min: '5Gi' } }
67
+ }
68
+ ]
69
+ }
70
+
71
+ ```
57
72
 
58
73
  ### Required settings for Cronjob apps (Note: Cronjobs do not support `sidekiq_alive_gem` and `services`)
74
+ Ideal to process periodic tasks
59
75
  - `deployment.job_apps[].schedule` (String): Cron schedule. Sample: `*/5 * * * *`
60
76
  - `deployment.job_apps[].kind` (String, default `Deployment`): Kind of job application [`Deployment` or `CronJob`]
61
77
  - `deployment.job_apps[].concurrency_policy` (String, default `Forbid`): [Documentation](https://kubernetes.io/docs/tasks/job/automated-tasks-with-cron-jobs/#concurrency-policy)
62
78
  - `deployment.job_apps[].suspend` (String, default `false`): If `true` then marks as finished the job application (stops creating new pods).
79
+ Sample:
80
+ ```ruby
81
+ {
82
+ job_apps: [{
83
+ name: "my-promotions-cronjob",
84
+ command: 'bundle exec rake promotions:process > ./log/promotions.log 2>&1',
85
+ schedule: '0 22 * * *',
86
+ kind: 'CronJob'
87
+ }]
88
+ }
89
+ ```
63
90
 
64
91
  ### Applications secrets.yml (Optional)
65
92
  - `secrets.name` (String): K8s secrets name where env vars will be saved and fetched from. Sample: `my-app-secrets`
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KubernetesHelper
4
- VERSION = '1.19.0'
4
+ VERSION = '1.20.1'
5
5
  end
@@ -84,50 +84,10 @@ This gem comes with continuous deployment script out of the box which can be exe
84
84
  PROD_CLOUD_TOKEN=<secret content here>
85
85
  ```
86
86
 
87
- * Add github workflow to automatically run deployment when merged into master or staging, something like:
88
- ```yml
89
- name: "Continuous Deployment"
90
- on:
91
- push:
92
- branches:
93
- - master
94
- - staging
95
-
96
- deployment:
97
- runs-on: ubuntu-latest
98
- jobs:
99
- steps:
100
- - uses: actions/checkout@v2
101
- with:
102
- ref: ${{ env.DEPLOY_BRANCH }}
103
- - name: Cancel previous Workflow Actions
104
- uses: styfle/cancel-workflow-action@0.6.0
105
- with:
106
- access_token: ${{ github.token }}
107
-
108
- - name: Set up Cloud SDK
109
- uses: google-github-actions/setup-gcloud@master
110
- - uses: satackey/action-docker-layer-caching@v0.0.11
111
- continue-on-error: true
112
- with:
113
- key: CD-docker-cache-${{ hashFiles('Dockerfile', 'Gemfile.lock') }}
114
-
115
- #### App deployment
116
- - run: sudo gem install kubernetes_helper
117
- - name: App deployment
118
- env:
119
- KB_AUTH_TOKEN: ${{ github.ref_name == 'master' && secrets.PROD_CLOUD_TOKEN || secrets.BETA_CLOUD_TOKEN }}
120
- DEPLOY_ENV: ${{ github.ref_name == 'master' && 'production' || 'beta' }}
121
- run: kubernetes_helper run_deployment 'cd.sh'
122
- ```
87
+ * Add github workflow to automatically run deployment when merged into master or staging: [See here](https://github.com/owen2345/reusable-ci-cd-actions#continuous-deployment)
123
88
 
124
- ## Apply any k8s setting changes
125
- - Secrets
126
- Open kubernetes secrets and add/edit/remove values and then save it
127
- `kubectl edit secret ...`
128
- Once secrets were updated, then restart all related pods, see: https://medium.com/devops-dudes/how-to-propagate-a-change-in-kubernetes-secrets-by-restarting-dependent-pods-b71231827656
129
-
130
- - Other settings
89
+ ## Apply deployment changes manually
90
+ Note: it can be enable for auto update with (`settings.rb`): `update_deployment: true`
131
91
  ```bash
132
92
  DEPLOY_ENV=beta kubernetes_helper run_yml 'deployment.yml' 'kubectl apply'
133
- ```
93
+ ```
@@ -12,11 +12,7 @@ fi
12
12
 
13
13
  ## Build and push containers
14
14
  echo "****** building image..."
15
- <% if continuous_deployment.docker_cmd %>
16
- <%= continuous_deployment.docker_cmd %>
17
- <% else %>
18
- docker <%=continuous_deployment.docker_build_cmd || 'build -f Dockerfile'%> -t $DEPLOY_NAME .
19
- <% end %>
15
+ eval $DOCKER_BUILD_CMD
20
16
  docker push $DEPLOY_NAME
21
17
 
22
18
  echo "****** tagging image $DEPLOY_NAME as $LATEST_NAME"
@@ -23,11 +23,7 @@ if [ -z $ALREADY_DEPLOYED ]
23
23
  then
24
24
  ## Build and push containers
25
25
  echo "****** image not created yet, building image..."
26
- <% if continuous_deployment.docker_cmd %>
27
- <%= continuous_deployment.docker_cmd %>
28
- <% else %>
29
- docker <%=continuous_deployment.docker_build_cmd || 'build -f Dockerfile'%> -t $DEPLOY_NAME .
30
- <% end %>
26
+ eval $DOCKER_BUILD_CMD
31
27
  docker push $DEPLOY_NAME
32
28
  else
33
29
  echo "****** image was already created: $ALREADY_DEPLOYED"
@@ -22,6 +22,7 @@
22
22
  <% if locals[:job_app][:resources] %>
23
23
  <%= include_template "_resources.yml", locals[:job_app][:resources].merge(tab: 2) %>
24
24
  <% end %>
25
+ ports: [ ]
25
26
  livenessProbe: null
26
27
  readinessProbe: null
27
28
  <%= include_template "_container_extra_settings.yml", { pod: 'job', pod_name: locals[:job_app][:name], tab: 2 } %>
@@ -1,12 +1,15 @@
1
1
  ports: [ ]
2
- <% if (deployment.job_services || []).any? %>
2
+ <% if (locals[:services] || []).any? %>
3
3
  livenessProbe: &liveness_probe
4
4
  exec:
5
5
  command: [ /bin/sh, -c,
6
- 'if [ $(ps -ef | grep "<%= deployment.job_services.join("\\|") %>" | grep -v "grep" | wc -l) -lt <%= deployment.job_services.count %> ]; then
6
+ 'if [ $(ps -ef | grep "<%= locals[:services].join("\\|") %>" | grep -v "grep" | wc -l) -lt <%= locals[:services].count %> ]; then
7
7
  echo "Some required services are not running"; exit 1;
8
8
  fi' ]
9
9
  initialDelaySeconds: 120
10
10
  periodSeconds: 30
11
11
  readinessProbe: *liveness_probe
12
+ <% else %>
13
+ livenessProbe: null
14
+ readinessProbe: null
12
15
  <% end %>
@@ -30,7 +30,7 @@
30
30
  <% if locals[:job_app][:sidekiq_alive_gem] %>
31
31
  <%= include_template "_sidekiq_alive_gem.yml" %>
32
32
  <% else %>
33
- <%= include_template "_job_liveness.yml" %>
33
+ <%= include_template "_job_liveness.yml", { services: locals[:job_app][:services] } %>
34
34
  <% end %>
35
35
 
36
36
  <% if deployment.cloud_secret_name %>
data/lib/templates/cd.sh CHANGED
@@ -16,6 +16,12 @@ CI_COMMIT_SHA=${CI_COMMIT_SHA:-$(date +%s) }
16
16
  DEPLOY_NAME="${IMAGE_NAME}:${CI_COMMIT_SHA}"
17
17
  LATEST_NAME="${IMAGE_NAME}:<%= continuous_deployment.image_tag || 'latest' %>"
18
18
 
19
+ <% if continuous_deployment.docker_cmd %>
20
+ DOCKER_BUILD_CMD="<%= continuous_deployment.docker_cmd %>"
21
+ <% else %>
22
+ DOCKER_BUILD_CMD="docker <%=continuous_deployment.docker_build_cmd || 'build -f Dockerfile'%> -t $DEPLOY_NAME --build-arg DEPLOY_VERSION=${DEPLOY_VERSION} --build-arg DEPLOY_ENV=${DEPLOY_ENV} ."
23
+ <% end %>
24
+
19
25
  <%= include_template "_cd_google.sh" if continuous_deployment.image_name.include?('gcr.io/') %>
20
26
  <%= include_template "_cd_digital.sh" if continuous_deployment.image_name.include?('digitalocean.com/') %>
21
27
 
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.19.0
4
+ version: 1.20.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - owen2345
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-07-14 00:00:00.000000000 Z
11
+ date: 2022-08-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: erb