@leverege/build-tools 2.5.4 → 2.5.6

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.
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ const SimpleGit = require('simple-git');
5
+
6
+ const git = new SimpleGit();
7
+
8
+ const getCurrentBranchName = async () => {
9
+ const branchInfo = await git.branch();
10
+ return Object.entries(branchInfo.branches).find(([name, info]) => info.current)[0];
11
+ };
12
+
13
+ const isProtected = async () => {
14
+ const protectedBranches = ['master', 'development'];
15
+ const theBranch = await getCurrentBranchName();
16
+ return protectedBranches.includes(theBranch);
17
+ };
18
+
19
+ (async () => {
20
+ try {
21
+ const active = await isProtected();
22
+ process.exit(active ? 0 : 1);
23
+ } catch (err) {
24
+ console.error(err);
25
+ }
26
+ })();
Binary file
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ const SimpleGit = require('simple-git');
5
+
6
+ const git = new SimpleGit();
7
+
8
+ const getCurrentBranchName = async () => {
9
+ const branchInfo = await git.branch();
10
+ return Object.entries(branchInfo.branches).find(([name, info]) => info.current)[0];
11
+ };
12
+
13
+ const isProtected = async () => {
14
+ const protectedBranches = ['master', 'development'];
15
+ const theBranch = await getCurrentBranchName();
16
+ return protectedBranches.includes(theBranch);
17
+ };
18
+
19
+ (async () => {
20
+ try {
21
+ const active = await isProtected();
22
+ process.exit(active ? 0 : 1);
23
+ } catch (err) {
24
+ console.error(err);
25
+ }
26
+ })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leverege/build-tools",
3
- "version": "2.5.4",
3
+ "version": "2.5.6",
4
4
  "description": "A collection of build / support tools for Leverege developers",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -33,6 +33,7 @@
33
33
  "helminit-dp": "src/helminit-dp",
34
34
  "helminit-scaler": "src/helminit-scaler",
35
35
  "helmup": "src/helmup",
36
+ "husky-check": "src/husky-check.js",
36
37
  "k8scale": "src/k8scale",
37
38
  "k8x": "src/k8x",
38
39
  "npm-link": "src/npm-link",
package/src/helmup CHANGED
@@ -149,11 +149,45 @@ function installMonitoringCharts(){
149
149
 
150
150
  ## Installing stackdriver exporter in GKE
151
151
  if [[ "$IS_GKE" = true ]]; then
152
+ # Check SA creation
153
+ kubectl get sa -n monitoring stackdriver-exporter
154
+ if [[ $? -eq 1 ]]; then
155
+ # Create Kubernetes SA
156
+ printf "\n*** Creating stackdriver-exporter SA ***\n\n"
157
+ kubectl create sa -n monitoring stackdriver-exporter
158
+
159
+ # Detect Project ID
160
+ currContext=`kubectl config current-context`
161
+
162
+ IFS='_'
163
+ read -ra ADDR <<< "$currContext"
164
+
165
+ GCP_PROJECT_ID=${ADDR[1]} # project id is the second string split by _
166
+
167
+ # Create GCP SA and bind policies
168
+ printf "\n*** Creating GCP SA with monitoring/viewer ***\n\n"
169
+ gcloud iam service-accounts create stackdriver-exporter --project "$GCP_PROJECT_ID"
170
+
171
+ gcloud projects add-iam-policy-binding "$GCP_PROJECT_ID" \
172
+ --member "serviceAccount:stackdriver-exporter@$GCP_PROJECT_ID.iam.gserviceaccount.com" \
173
+ --role "roles/monitoring.viewer"
174
+
175
+ gcloud iam service-accounts add-iam-policy-binding \
176
+ --role roles/iam.workloadIdentityUser \
177
+ --member "serviceAccount:$GCP_PROJECT_ID.svc.id.goog[monitoring/stackdriver-exporter]" \
178
+ "stackdriver-exporter@$GCP_PROJECT_ID.iam.gserviceaccount.com"
179
+
180
+ # Annotate Kubernetes SA
181
+ kubectl annotate serviceaccount stackdriver-exporter \
182
+ "iam.gke.io/gcp-service-account=stackdriver-exporter@$GCP_PROJECT_ID.iam.gserviceaccount.com" \
183
+ --namespace monitoring
184
+ fi
185
+
152
186
  helm upgrade --install stackdriver-exporter \
153
187
  stable/stackdriver-exporter \
154
188
  --namespace monitoring \
155
189
  -f stackdriver-exporter/values.yaml \
156
- --version 1.2.3
190
+ --version 1.3.0
157
191
  fi
158
192
 
159
193
  ## Install Prometheus
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env node
2
+
3
+ const SimpleGit = require( 'simple-git' )
4
+ const git = new SimpleGit()
5
+
6
+ const getCurrentBranchName = async () => {
7
+ const branchInfo = await git.branch()
8
+ return Object
9
+ .entries( branchInfo.branches )
10
+ .find( ( [ name, info ] ) => ( info.current ) )[0]
11
+ }
12
+
13
+ const isProtected = async () => {
14
+ const protectedBranches = [ 'master', 'development' ]
15
+ const theBranch = await getCurrentBranchName()
16
+ return protectedBranches.includes( theBranch )
17
+ }
18
+
19
+ ( async () => {
20
+ try {
21
+ const active = await isProtected()
22
+ process.exit( active ? 0 : 1 )
23
+ } catch ( err ) {
24
+ console.error( err )
25
+ }
26
+ } )()
@@ -0,0 +1,23 @@
1
+ #!/bin/bash
2
+
3
+ IMPERSONATE='gcloud config set auth/impersonate_service_account'
4
+ impersonate() {
5
+ sa=$1
6
+ echo "Impersonating $sa"
7
+ $IMPERSONATE $sa
8
+ }
9
+
10
+ case $1 in
11
+ gke)
12
+ impersonate k8s@project.iam.gserviceaccount.com
13
+ ;;
14
+ admin)
15
+ impersonate admin@other-project.iam.gserviceaccount.com
16
+ ;;
17
+ clear)
18
+ gcloud config unset auth/impersonate_service_account
19
+ ;;
20
+ *)
21
+ echo "Usage: Updates impersonated service account"
22
+ echo " imp-sa [gke|admin|clear]"
23
+ esac
@@ -0,0 +1,46 @@
1
+ #!/bin/bash
2
+
3
+ SVC_PROJ="leverege-dev-john"
4
+
5
+ SVC_NAME="terraformer"
6
+ SVC_ACCT="${SVC_NAME}@${SVC_PROJ}.iam.gserviceaccount.com"
7
+
8
+ function countdown() {
9
+ local SEC=${1}
10
+ shift
11
+ local MSG=${@}
12
+ while [ $SEC -ne 0 ];
13
+ do
14
+ printf "\r\033[KWaiting %.d seconds $MSG" $((SEC--))
15
+ sleep 1
16
+ done
17
+ }
18
+
19
+ gcloud iam service-accounts create ${SVC_NAME} \
20
+ --project=${SVC_PROJ} --quiet \
21
+ --description="the terraforming account" \
22
+ --display-name="terraformer" &> /dev/null
23
+
24
+ gcloud projects add-iam-policy-binding ${SVC_PROJ} \
25
+ --project=${SVC_PROJ} --quiet \
26
+ --member=serviceAccount:${SVC_ACCT} \
27
+ --role=roles/editor &> /dev/null
28
+
29
+ gcloud projects add-iam-policy-binding ${SVC_PROJ} \
30
+ --project=${SVC_PROJ} --quiet \
31
+ --member=serviceAccount:${SVC_ACCT} \
32
+ --role=roles/iam.securityAdmin &> /dev/null
33
+
34
+ countdown 30 "will delete ${SVC_NAME} service account"
35
+
36
+ gcloud projects remove-iam-policy-binding ${SVC_PROJ} \
37
+ --project=${SVC_PROJ} --quiet \
38
+ --member=serviceAccount:${SVC_ACCT} \
39
+ --role=roles/iam.securityAdmin &> /dev/null
40
+
41
+ gcloud projects remove-iam-policy-binding ${SVC_PROJ} \
42
+ --project=${SVC_PROJ} --quiet \
43
+ --member=serviceAccount:${SVC_ACCT} \
44
+ --role=roles/editor &> /dev/null
45
+
46
+ gcloud iam service-accounts delete ${SVC_ACCT} --quiet &> /dev/null