kubernetes_helper 1.0 → 1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -5
- data/lib/kubernetes_helper/version.rb +1 -1
- data/lib/templates/cd.sh +19 -15
- data/lib/templates/deployment.yml +11 -0
- data/lib/templates/settings.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3bed0753481fee12fa822da715a6836b55fb561deaca02e8763e59d05b3edc6b
|
4
|
+
data.tar.gz: 28d56d40d55c667e479ee26126fc7014415afec77ee884eb58daac2c4e60809e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
##
|
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/
|
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,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
|
|
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,
|