@leverege/build-tools 1.8.4 → 1.10.2

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.
package/src/helmify CHANGED
@@ -46,7 +46,8 @@ spec:
46
46
  selector:
47
47
  app: $chartname
48
48
  ports:
49
- - protocol: TCP
49
+ - name: $chartname-input
50
+ protocol: TCP
50
51
  port: {{ .Values.$chartname_go.SERVER_PORT }}
51
52
  targetPort: api
52
53
  SVC_YAML
@@ -98,7 +99,7 @@ CHARTYAML
98
99
  cat<<VALUESYAML > values.yaml
99
100
  # List your env variables here
100
101
  $chartname_go:
101
- VERSION: v$PACKAGE_VERSION
102
+ VERSION: vX.Y.Z
102
103
  SERVER_PORT: 8080
103
104
  IMAGE: gcr.io/leverege-docker-images/$chartname
104
105
 
@@ -108,7 +109,7 @@ default:
108
109
  MAX_CHILD_PROCESSES: "1"
109
110
 
110
111
  MODEL_FIREBASE_SERVICE_ACCOUNT: /var/config/keys/model-data
111
- MODEL_FIREBASE_DATABASE_URL: <firebase URL>
112
+ MODEL_FIREBASE_DATABASE_URL: https://OVH:<PROJECT_NAME>.firebaseio.com
112
113
  MODEL_FIREBASE_CONFIG: /var/config/keys/model-data-config
113
114
 
114
115
  SECRET_KEY: key.json
@@ -191,34 +192,39 @@ spec:
191
192
  - name: pubsub-key
192
193
  secret:
193
194
  secretName: pubsub
194
- # UNCOMMENT TO USE PRE-EMPTIBLES
195
- # tolerations:
196
- # - key: "preemptible"
197
- # operator: "Equal"
198
- # value: "true"
199
- # effect: "NoSchedule"
200
- # affinity:
201
- # podAntiAffinity:
202
- # preferredDuringSchedulingIgnoredDuringExecution:
203
- # - weight: 100
204
- # podAffinityTerm:
205
- # labelSelector:
206
- # matchExpressions:
207
- # - key: app
208
- # operator: In
209
- # values:
210
- # - api-server
211
- # topologyKey: kubernetes.io/hostname
212
- # nodeAffinity:
213
- # preferredDuringSchedulingIgnoredDuringExecution:
214
- # - preference:
215
- # matchExpressions:
216
- # - key: cloud.google.com/gke-preemptible
217
- # operator: Exists
218
- # weight: 50
195
+ {{- if (.Values.$chartname_go.PREEMPTIBLE) and eq .Values.$chartname_go.PREEMPTIBLE "true" }}
196
+ tolerations:
197
+ - key: "preemptible"
198
+ operator: "Equal"
199
+ value: "true"
200
+ effect: "NoSchedule"
201
+ affinity:
202
+ podAntiAffinity:
203
+ preferredDuringSchedulingIgnoredDuringExecution:
204
+ - weight: 100
205
+ podAffinityTerm:
206
+ labelSelector:
207
+ matchExpressions:
208
+ - key: app
209
+ operator: In
210
+ values:
211
+ - api-server
212
+ topologyKey: kubernetes.io/hostname
213
+ nodeAffinity:
214
+ preferredDuringSchedulingIgnoredDuringExecution:
215
+ - preference:
216
+ matchExpressions:
217
+ - key: cloud.google.com/gke-preemptible
218
+ operator: Exists
219
+ weight: 50
220
+ {{- end }}
219
221
  containers:
220
222
  - name: $chartname
221
223
  image: gcr.io/leverege-docker-images/$chartname:{{ .Values.$chartname_go.VERSION }}
224
+ imagePullPolicy: Always
225
+ securityContext:
226
+ runAsUser: 1000
227
+ allowPrivilegeEscalation: false
222
228
  resources:
223
229
  requests:
224
230
  cpu: "10m"
package/src/helmup CHANGED
@@ -3,9 +3,12 @@
3
3
  # This script is used to ease the pain of transition testing to chart museum
4
4
  # prior to setting up keel for new clusters / installs.
5
5
  #
6
+ # Removing db-curator from the list of platform components for now. It needs
7
+ # to be turned into a cronjob to avoid having it run as soon as it gets
8
+ # deployed.
9
+ #
6
10
  PLATFORM=(
7
11
  api-server
8
- db-curator
9
12
  emailer
10
13
  imagine
11
14
  message-processor
@@ -19,18 +22,138 @@ PLATFORM=(
19
22
 
20
23
  SYSTEM=(
21
24
  descheduler
25
+ disks
22
26
  elastic
23
27
  monitoring
28
+ polaris
24
29
  redis
25
30
  )
26
31
 
32
+ # Simple ANSI color coded string generator.
33
+ function color() {
34
+ local color=
35
+ case "$1" in
36
+ 'g') color="92m" ;; # green
37
+ 'c') color="96m" ;; # lt blue
38
+ 'y') color="93m" ;; # yellow
39
+ 'r') color="91m" ;; # red
40
+ 'toast') color="1;3;7;91;103;5m" ;;
41
+ esac
42
+ printf "\e[$color$2\e[0m"
43
+ }
44
+ RED_ERROR=`color r '***ERROR:'`
45
+ YELO_WARN="`color y '***WARNING:'`"
46
+
47
+ function setOrUnset() {
48
+ local setting=`color toast "NEEDS TO BE SET"`
49
+ [ ! -z "$1" ] && setting=`color g $1`
50
+ echo "$setting"
51
+ }
52
+
53
+ # Installing keel is a little more involved since we need to feed it svc acct
54
+ # keys and a slack bot token.
55
+ function keelNeeds() {
56
+ cat<<KEELNEEDS
57
+
58
+ $RED_ERROR $1
59
+
60
+ In order to get its job done keel needs the service account JSON file for the
61
+ project containing the docker images that it is reponsible for. It also needs
62
+ a token for the slack bot in order to interact with slack.
63
+
64
+ `color g LEV_KEYS`
65
+ points to the top level directory containing the keys and secrets
66
+ to the k8s clusters
67
+ `color g \$LEV_KEYS/docker-image-svc-acct`
68
+ directory containing the service account JSON files
69
+ `color g "\$LEV_KEYS/<branch-name>/slack-bot-token"`
70
+ location of the slack bot token text file
71
+
72
+ Current settings:
73
+ LEV_KEYS => `setOrUnset $LEV_KEYS`
74
+
75
+ Missing variables should be set using the standard bash syntax:
76
+ `color y export\ VARNAME=\"\<YOUR_SETTING\>\"`
77
+
78
+ KEELNEEDS
79
+ exit 1
80
+ }
81
+
82
+ function createSSDYAML(){
83
+ cat<<EOSSD > k8-utils/ssd-storageclass.yaml
84
+ apiVersion: storage.k8s.io/v1
85
+ kind: StorageClass
86
+ metadata:
87
+ name: ssd
88
+ provisioner: kubernetes.io/gce-pd
89
+ parameters:
90
+ type: pd-ssd
91
+ EOSSD
92
+ }
93
+
94
+ function checkSSDStorageClass(){
95
+ kubectl get storageclass ssd
96
+ if [[ $? -eq 1 ]]; then
97
+ printf "\n*** SSD Storage Class not defined ***\n\n"
98
+ if [ ! -f k8-utils/ssd-storageclass.yaml ]; then
99
+ createSSDYAML
100
+ fi
101
+ kubectl apply -f k8-utils/ssd-storageclass.yaml
102
+ fi
103
+
104
+ printf "\n*** Attaching PVC to SSD Class ***\n\n"
105
+ }
106
+
107
+ function installKeel() {
108
+ [ ! -d "$LEV_KEYS" ] &&
109
+ keelNeeds "`color c \\$LEV_KEYS` must point to the keys directory for the clusters."
110
+
111
+ # TODO make the docker image project configurable and not just lev
112
+ SVC_ACCT="$LEV_KEYS/docker-image-svc-acct/leverege-docker-images.json"
113
+ [ ! -f "$SVC_ACCT" ] &&
114
+ keelNeeds "Missing service account info => `color c $SVC_ACCT`"
115
+
116
+ BRANCH=`git rev-parse --abbrev-ref HEAD`
117
+ SLACK_BOT_NAME="`overwhelm -k SLACK_BOT_NAME`"
118
+ [ -z "$SLACK_BOT_NAME" ] && SLACK_BOT_NAME=$BRANCH
119
+ SLACK_TOKEN="$LEV_KEYS/$BRANCH/slack-bot-token"
120
+ [ ! -f "$SLACK_TOKEN" ] &&
121
+ keelNeeds "Missing slack bot token => `color c $SLACK_TOKEN`"
122
+
123
+ helm repo add keel https://charts.keel.sh; helm repo update
124
+ helm upgrade --install keel keel/keel \
125
+ --set gcr.enabled="true" \
126
+ --set gcr.projectId="leverege-docker-images" \
127
+ --set gcr.pubSub.enabled="true" \
128
+ --set slack.enabled="true" \
129
+ --set slack.channel="devs-cicd" \
130
+ --set slack.approvalsChannel="cd-approvals" \
131
+ --set slack.botName="$SLACK_BOT_NAME" \
132
+ --set slack.token="$(cat $SLACK_TOKEN)" \
133
+ --set googleApplicationCredentials="$(cat $SVC_ACCT | base64 -w 0)"
134
+ }
135
+
136
+ # ---------- helmup MAIN ----------
137
+ command -v chartmuseum &> /dev/null
138
+ if [ $? -ne 0 ];
139
+ then
140
+ cat<<NOMUSEUM
141
+
142
+ $RED_ERROR Missing chartmuseum. Head over to the wiki site and follow the
143
+ instructions in the section entitled Installing ChartMuseum down
144
+ in the How-to articles -> Helm Charts via ChartMuseum.
145
+
146
+ NOMUSEUM
147
+ exit 1
148
+ fi
149
+
27
150
  GITTOP=`git rev-parse --show-toplevel`
28
151
  cd $GITTOP
29
152
 
30
153
  npm run ahoy
31
154
  [ $? -ne 0 ] && printf "\n\n***Aborting helmup...\n\n" && exit 1
32
155
 
33
- helm repo update && helm search chartmuseum
156
+ helm repo update &> /dev/null && helm search chartmuseum
34
157
 
35
158
  function doInstall() {
36
159
 
@@ -41,6 +164,7 @@ function doInstall() {
41
164
  case "$SERVICE" in
42
165
  "platform")
43
166
  doInstall "${PLATFORM[@]}"
167
+ printf "\nkeel may be installed by running => helmup keel\n\n"
44
168
  ;;
45
169
 
46
170
  "system")
@@ -49,35 +173,83 @@ function doInstall() {
49
173
 
50
174
  "descheduler")
51
175
  helm repo add akomljen-charts https://raw.githubusercontent.com/komljen/helm-charts/master/charts/
52
- helm upgrade --install descheduler akomljen-charts/descheduler --set schedule="*/13 * * * *"
176
+ helm upgrade --install descheduler akomljen-charts/descheduler --set schedule="*/15 * * * *",deschedulerPolicy.strategies.RemovePodsViolatingNodeAffinity.params.nodeAffinityType={preferredDuringSchedulingIgnoredDuringExecution}
177
+ ;;
178
+
179
+ "disks")
180
+ checkSSDStorageClass
181
+ helm upgrade --install disks ./disks
53
182
  ;;
54
183
 
55
184
  "elastic"|"elasticsearch")
185
+ checkSSDStorageClass
56
186
  helm repo add elastic https://helm.elastic.co
57
- helm upgrade --install elasticsearch elastic/elasticsearch --version 7.2.0
187
+ helm upgrade --install elasticsearch elastic/elasticsearch --set volumeClaimTemplate.storageClassName="ssd"
188
+ ;;
189
+
190
+ "keel")
191
+ installKeel # because it's a little more involved
58
192
  ;;
59
193
 
60
194
  "monitoring")
61
195
  helm dep up ./monitoring && helm upgrade --install monitoring ./monitoring
62
196
  ;;
63
197
 
198
+ "polaris")
199
+ helm repo add reactiveops-stable https://charts.reactiveops.com/stable
200
+ helm upgrade --install polaris reactiveops-stable/polaris --namespace polaris
201
+ printf "\n***Proxy 8081 with this=> kubectl port-forward --namespace polaris svc/polaris-dashboard 8081:80\n\n"
202
+ ;;
203
+
64
204
  "redis")
65
205
  # https://github.com/helm/charts/tree/master/stable/redis
66
206
  helm upgrade --install redis stable/redis \
67
207
  --set usePassword=false,cluster.slaveCount=3,networkPolicy.enabled=true,metrics.enabled=true
68
208
  ;;
69
209
 
210
+ "timescale-db")
211
+ helm dep up ./timescale-db && helm upgrade --install timescale-db ./timescale-db
212
+ ;;
213
+
70
214
  "ingress")
71
215
  helm upgrade --install ingress ./ingress
72
216
  ;;
73
217
 
74
218
  *)
75
- [ ! -d $SERVICE ] && continue
76
- [ ! -f $SERVICE/values-local.yaml ] && continue
219
+ if [ ! -d $SERVICE ] || [ ! -f $SERVICE/values-local.yaml ];
220
+ then
221
+ printf "\n$YELO_WARN Skipping unknown service => $SERVICE\n\n"
222
+ continue
223
+ fi
77
224
 
78
225
  printf "\n--------------------------------------------------------------\nCharting $SERVICE\n"
79
- helm upgrade --install $SERVICE chartmuseum/$SERVICE -f $SERVICE/values.yaml
80
- [ $? -ne 0 ] && printf "The $SERVICE chart failed - you have issues.\n"
226
+ # By default the museum chart name will be the same as the service, but
227
+ # we have the flexibility to override the naming when the charts are
228
+ # reference by the downstream repositories via the .helmup-charmuseum file.
229
+ OVERRIDE="$SERVICE/.helmup-chartmuseum"
230
+ MUSEUM=$SERVICE
231
+ if [ -f $OVERRIDE ];
232
+ then
233
+ MUSEUM=$(<${OVERRIDE})
234
+ printf "\n$YELO_WARN Local chartmuseum name override from ${SERVICE} to ${MUSEUM}\n"
235
+ fi
236
+ helm upgrade --install $SERVICE chartmuseum/$MUSEUM -f $SERVICE/values.yaml 2> /dev/null
237
+ if [ $? -ne 0 ];
238
+ then
239
+ cat<<NOTRUNNING
240
+
241
+ $RED_ERROR The $SERVICE chart failed to upgrade or install. Is chartmuseum up
242
+ and running on the proper port? Try firing it up with:
243
+
244
+ chartmuseum \\
245
+ --port="8080" \\
246
+ --storage-google-bucket="leverege-helm-charts" \\
247
+ --storage-google-prefix="" \\
248
+ --storage="google" &> /dev/null &
249
+
250
+ NOTRUNNING
251
+ exit 1
252
+ fi
81
253
  ;;
82
254
  esac
83
255
  done
package/src/overwhelm CHANGED
@@ -11,16 +11,19 @@ const ask = require( 'readline-sync' )
11
11
  const YAML = require( 'js-yaml' )
12
12
 
13
13
  const optionsDefinitions = [
14
+ { name : 'context', alias : 'x', type : String, default : '' },
14
15
  { name : 'section', alias : 's', type : String, default : 'default' },
15
16
  { name : 'key', alias : 'k', type : String },
16
17
  { name : 'export', alias : 'e', type : Boolean, default : false },
17
18
  { name : 'continue', alias : 'c', type : Boolean, default : false },
19
+ { name : 'checkctx', alias : 't', type : Boolean, default : false },
18
20
  { name : 'verbose', alias : 'v', type : Boolean, default : false },
19
21
  ]
20
22
  const args = cliArgs( optionsDefinitions )
21
23
 
22
24
  // The kubernetes context is equal to the git branch name.
23
- const context = require( 'git-branch' ).sync()
25
+ const gitBranch = require( 'git-branch' ).sync()
26
+ const context = args.context || gitBranch
24
27
 
25
28
  if ( context == 'master' ) {
26
29
  console.log( '***ERROR: master context is forbidden; change to a different branch\n\n' )
@@ -36,15 +39,17 @@ if ( context == 'master' ) {
36
39
  // my-project:
37
40
  // GCE_MACHINE : "n1-highcpu-8"
38
41
  //
39
- // where the my-project specific setting may override the default if it
40
- // needs a beefier deployment. Any setting can be defaulted in this
41
42
  // fashion, but it is advised not to set a default region with this
42
43
  // approach in order to keep us cognizant of exactly where a cluster is
43
44
  // being formed.
44
45
  //
45
46
  const yaml = YAML.safeLoad( fs.readFileSync( 'overwhelm.yaml', 'utf-8' ) )
46
47
  const over = yaml.default
47
- const cfgs = yaml[context]
48
+ let cfgs = yaml[context]
49
+ let wtfs = cfgs
50
+
51
+ // If we just need to check context return 0 if cfgs exists, else error.
52
+ if ( args.checkctx ) { process.exit( !cfgs ) }
48
53
 
49
54
  if ( !cfgs ) {
50
55
  console.log( `***ERROR: Unknown context => [${context}]\n` )
@@ -56,6 +61,17 @@ if ( !cfgs ) {
56
61
  process.exit( 1 )
57
62
  }
58
63
 
64
+ // Check to see if we are deriving from another configuration.
65
+ if ( cfgs['PROJECT_BASE'] ) {
66
+ const baseName = cfgs['PROJECT_BASE']
67
+ const tempCfgs = cfgs
68
+ cfgs = yaml[baseName]
69
+ Object.keys( tempCfgs ).forEach( ( key ) => { cfgs[key] = tempCfgs[key] } )
70
+ console.log( "PROJECT_BASE still under evaluation" )
71
+ console.log( "\n cfgs=", cfgs )
72
+ process.exit( 1 ) //XXX HERE
73
+ }
74
+
59
75
  Object.keys( cfgs ).forEach( ( key ) => { over[key] = cfgs[key] || over[key] } )
60
76
 
61
77
  // Expand any variables that reference other variable settings. A perfect
@@ -232,7 +248,7 @@ ahoy.forEach( ( dir ) => {
232
248
 
233
249
  // Set the GCP context for safety!
234
250
  const clusterName = over['CLUSTER_NAME']
235
- const projectName = over['PROJECT_NAME']
251
+ const projectId = over['PROJECT_ID']
236
252
  const zone = over['GCE_REGION'] + ( over['GCE_ZONE'] ? `-${over['GCE_ZONE']}` : '' )
237
253
 
238
254
  if ( !clusterName ) {
@@ -248,7 +264,7 @@ ahoy.forEach( ( dir ) => {
248
264
  ${chalk.bold.green( `CLUSTER_NAME : "\${PROJECT_NAME}"` )}
249
265
 
250
266
  However, if the CLUSTER_NAME is not the same as the PROJECT_NAME then go
251
- ahead and add the CLUSTER_NAME setting to the ${chalk.bold.green(projectName)} section of the
267
+ ahead and add the CLUSTER_NAME setting to the ${chalk.bold.green(projectId)} section of the
252
268
  overwhelm.yaml file.
253
269
 
254
270
  ` ) )
@@ -262,9 +278,9 @@ ahoy.forEach( ( dir ) => {
262
278
  } catch (err) { }
263
279
 
264
280
  const currentCtx = kubeout.toString().trim()
265
- const desiredCtx = `gke_${projectName}_${zone}_${clusterName}`
281
+ const desiredCtx = `gke_${projectId}_${zone}_${clusterName}`
266
282
  const matchedCtx = ( currentCtx === desiredCtx )
267
- const cmd = `gcloud container clusters get-credentials ${clusterName} --zone ${zone} --project ${projectName}`
283
+ const cmd = `gcloud container clusters get-credentials ${clusterName} --zone ${zone} --project ${projectId}`
268
284
 
269
285
  if ( matchedCtx ) {
270
286
  console.log( `
@@ -278,7 +294,7 @@ ahoy.forEach( ( dir ) => {
278
294
 
279
295
  You are about to change your GCP context to:
280
296
  CLUSTER_NAME => ${chalk.bold.green(clusterName)}
281
- PROJECT_NAME => ${chalk.bold.green(projectName)}
297
+ PROJECT_ID => ${chalk.bold.green(projectId)}
282
298
  GCE_REGION => ${chalk.bold.green(zone)}
283
299
 
284
300
  ` )
@@ -16,6 +16,7 @@ function arrayContainsArray( superset, subset ) {
16
16
  } )
17
17
  }
18
18
 
19
- arrayContainsArray( mdFiles, filesToCheck ) ?
20
- console.log( 'README and LICENSE files exist' ) :
19
+ if ( !arrayContainsArray( mdFiles, filesToCheck ) ) {
20
+ console.log( 'Cannot find README.md or LICENSE.md' )
21
21
  process.exit( 1 )
22
+ }
@@ -1,119 +0,0 @@
1
- "use strict";
2
-
3
- const groupBy = require('lodash.groupby');
4
-
5
- const keyBy = require('lodash.keyby');
6
-
7
- const countBy = require('lodash.countby');
8
-
9
- const orderBy = require('lodash.orderby');
10
-
11
- const map = require('lodash.map');
12
-
13
- const first = require('lodash.first');
14
-
15
- module.exports = (config = {}) => {
16
- function affectsProd(resolves) {
17
- return !(config['prod-only'] && resolves.every(({
18
- dev
19
- }) => dev));
20
- }
21
-
22
- function requireAttention(auditResult) {
23
- const {
24
- actions,
25
- advisories
26
- } = auditResult;
27
- const reviewActions = actions.filter(({
28
- action,
29
- resolves,
30
- isMajor
31
- }) => (action === 'review' || isMajor) && affectsProd(resolves));
32
- const reviewAdvisories = reviewActions.reduce((acc, {
33
- resolves
34
- }) => {
35
- const advisoriesToInclude = resolves.reduce((result, {
36
- id
37
- }) => Object.assign({}, result, {
38
- [id]: advisories[id]
39
- }), {});
40
- return Object.assign({}, acc, advisoriesToInclude);
41
- }, {});
42
- return Object.assign({}, auditResult, {
43
- actions: reviewActions,
44
- advisories: reviewAdvisories
45
- });
46
- }
47
-
48
- function getHighestSeverity({
49
- advisories
50
- }) {
51
- for (const severity of ['critical', 'high', 'moderate', 'low']) {
52
- if (Object.keys(advisories).find(key => advisories[key].severity === severity)) {
53
- return severity;
54
- }
55
- }
56
- }
57
-
58
- function filterAuditResultsBySeverity(auditResult, highestSeverity) {
59
- const {
60
- actions,
61
- advisories
62
- } = auditResult;
63
- const groupedAdvisories = groupBy(advisories, 'severity');
64
- const advisoriesForSeverity = keyBy(groupedAdvisories[highestSeverity], 'id');
65
- const actionsForSeverity = actions.reduce((acc, action) => {
66
- const resolvesSevereAdvisory = action.resolves.some(({
67
- id
68
- }) => advisoriesForSeverity[id]);
69
- return resolvesSevereAdvisory ? [].concat(acc, action) : acc;
70
- }, []);
71
- return Object.assign({}, auditResult, {
72
- actions: actionsForSeverity,
73
- advisories
74
- });
75
- }
76
-
77
- function getAutoFixCount(auditResult) {
78
- return auditResult.actions.filter(({
79
- action,
80
- resolves,
81
- isMajor
82
- }) => action !== 'review' && !isMajor && affectsProd(resolves)).length;
83
- }
84
-
85
- function findRootLibs(resolves) {
86
- return resolves.reduce((acc, resolve) => [].concat(acc, resolve.path.split('>')[0]), []);
87
- }
88
-
89
- function getMostProblematicDependency({
90
- actions
91
- }) {
92
- const rootLibraries = actions.reduce((libs, {
93
- resolves
94
- }) => [].concat(libs, findRootLibs(resolves)), []);
95
- return first(orderBy(map(countBy(rootLibraries), (count, lib) => ({
96
- count,
97
- name: lib
98
- })), ({
99
- count
100
- }) => count, ['desc']));
101
- }
102
-
103
- return function help(npmAuditResultJson) {
104
- const npmAuditResult = JSON.parse(npmAuditResultJson);
105
- const resultsThatRequireAttention = requireAttention(npmAuditResult);
106
- const highestSeverity = getHighestSeverity(resultsThatRequireAttention);
107
- const auditResult = filterAuditResultsBySeverity(resultsThatRequireAttention, highestSeverity);
108
- const autoFixCount = getAutoFixCount(npmAuditResult);
109
- const exitCode = config['exit-zero'] || !auditResult.actions.length && !autoFixCount ? 0 : 1;
110
- return {
111
- npmAuditResult,
112
- auditResult,
113
- autoFixCount,
114
- mostProblematicDependency: getMostProblematicDependency(resultsThatRequireAttention),
115
- highestSeverity,
116
- exitCode
117
- };
118
- };
119
- };
@@ -1,23 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
-
4
- const getStdin = require('get-stdin');
5
-
6
- const options = require('minimist')(process.argv.slice(2));
7
-
8
- const help = require('./help');
9
-
10
- const report = require('./report');
11
-
12
- const defaults = {
13
- 'exit-zero': false,
14
- 'prod-only': false
15
- };
16
- const config = Object.assign({}, defaults, options);
17
- getStdin().then(help(config)).then(result => report(result).then(theReport => {
18
- console.log(theReport);
19
- process.exit(result.exitCode);
20
- })).catch(error => {
21
- console.error(error);
22
- process.exit(1);
23
- });
@@ -1,61 +0,0 @@
1
- "use strict";
2
-
3
- const auditReport = require('npm-audit-report');
4
-
5
- const chalk = require('chalk');
6
-
7
- function automaticFixes(autoFixCount) {
8
- return autoFixCount ? `run ${chalk.yellow('`npm audit fix`')} to automatically fix ${chalk.yellow(autoFixCount)} issues. These should all be non-breaking upgrades, so don't stress.` : '';
9
- }
10
-
11
- function fixesToReview({
12
- actions,
13
- advisories
14
- }, highestSeverity) {
15
- const advisoryIds = Object.keys(advisories);
16
-
17
- if (!actions.length || !advisoryIds.length) {
18
- return '';
19
- }
20
-
21
- return `Resolve the ${chalk.green(actions.length)} ${chalk.green(highestSeverity)} severity issues above and run this command again to move to the next severity.`;
22
- }
23
-
24
- function mostProblematic(mostProblematicDependency) {
25
- if (!mostProblematicDependency) {
26
- return '';
27
- }
28
-
29
- const {
30
- name,
31
- count
32
- } = mostProblematicDependency;
33
- return count && count > 2 ? `The most problematic dependency seems to be ${chalk.blue(name)} with ${chalk.blue(count)} issue${count ? 's' : ''} that need your attention.` : '';
34
- }
35
-
36
- module.exports = async function printFullReport({
37
- npmAuditResult,
38
- auditResult,
39
- autoFixCount,
40
- mostProblematicDependency,
41
- highestSeverity
42
- }) {
43
- const {
44
- report
45
- } = await auditReport(npmAuditResult, {
46
- reporter: 'install',
47
- withColor: true,
48
- withUnicode: true
49
- });
50
- const hints = [].concat(automaticFixes(autoFixCount)).concat(fixesToReview(auditResult, highestSeverity)).concat(mostProblematic(mostProblematicDependency)).filter(Boolean);
51
- const help = hints.length ? `
52
-
53
- ${chalk.green('=== A little bit of help ===')}
54
-
55
- Where to start:
56
- ${hints.reduce((acc, hint) => `${acc}
57
- - ${hint}
58
- `, '')}
59
- ` : '';
60
- return `${report}${help}`;
61
- };