kubernetes_helper 1.0 → 1.1

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: 528e61587a3011330c7e474b523ce04079c8e49483bf894d5eb1806927436888
4
- data.tar.gz: 9df4e7aab70108b75831077d2f4390067e5807664050f70e1557f504835144bd
3
+ metadata.gz: 3bed0753481fee12fa822da715a6836b55fb561deaca02e8763e59d05b3edc6b
4
+ data.tar.gz: 28d56d40d55c667e479ee26126fc7014415afec77ee884eb58daac2c4e60809e
5
5
  SHA512:
6
- metadata.gz: 9ed371a62084598f9bb4755df54ca059ffbeb729731555e4a6a6cf58dceecc0c347741921b5c46fc11408a937c914ea2d3fddaf3da94bc801dd6cd7f9ecc1ed8
7
- data.tar.gz: 6248035be5a30995594a39ad56b73b811935b3b55988d067173a530ee0522294f6afb0e6361f664d4f696e7b370ce7b816ed74a53cb3f416c584e12c76ff023d
6
+ metadata.gz: d4d8b5606a4d3d9649de1add4341dcea076e2892e2d908d24f1cce5c14fb206b9bd779da7546544634b0341806163f3949f98c24bdd9a0a16dbf4149fa597117
7
+ data.tar.gz: 331f4263fb0ad4fd29bda318f079e36e0954c58bd8a50dc4507e49d0e88043afcfe03a8bad22390d5776042bd07837d4232c5b7879a06074870369274866537d
data/README.md CHANGED
@@ -11,7 +11,10 @@ kubernetes_helper generate_templates
11
11
  ```
12
12
  Note: Requires ruby 1.7+
13
13
 
14
- ## Usage
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/
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KubernetesHelper
4
- VERSION = '1.0'
4
+ VERSION = '1.1'
5
5
  end
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
- rm -f -- $AUTH_PATH
21
- echo $KB_AUTH_TOKEN >> $AUTH_PATH
22
-
23
- ## ***** GOOGLE CONNECTOR
24
- # Download and install Google Cloud SDK
25
- if [ -z "$(which gcloud)" ]; then
26
- 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
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,11 +46,15 @@ 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
@@ -59,6 +63,7 @@ documents:
59
63
  "-credential_file=/secrets/gcloud/credentials.json"]
60
64
  volumeMounts:
61
65
  - *cloud_credentials_volume
66
+ <% end %>
62
67
 
63
68
  - &logs_container # print to stdout all log files
64
69
  name: print-logs
@@ -69,9 +74,12 @@ documents:
69
74
 
70
75
  terminationGracePeriodSeconds: 120
71
76
  volumes:
77
+ <% if deployment.cloud_secret_name %>
72
78
  - name: gcloud-creds
73
79
  secret:
74
80
  secretName: '<%=deployment.cloud_secret_name%>'
81
+ <% end %>
82
+
75
83
  - name: applog
76
84
  emptyDir: {}
77
85
 
@@ -116,7 +124,10 @@ documents:
116
124
  <% end %>
117
125
  <% end %>
118
126
 
127
+ <% if deployment.cloud_secret_name %>
119
128
  - *cloudsql_container
129
+ <% end %>
130
+
120
131
  - <<: *logs_container
121
132
  <% end %>
122
133
 
@@ -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 ? 'my_app' : 'my_beta_app'
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,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kubernetes_helper
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.0'
4
+ version: '1.1'
5
5
  platform: ruby
6
6
  authors:
7
7
  - owen2345