@leverege/build-tools 2.0.5 → 2.0.7

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.
@@ -1,353 +0,0 @@
1
- #!/bin/bash
2
- if [ -z "$1" ]; then
3
- echo " Usage: create <version number>"
4
- exit 1
5
- fi
6
-
7
- # cleanup trapper for gracefully killing, which doesn't do much right now
8
- cleanup() {
9
- printf "\nCleaning up and exiting...\n\n"
10
- rm -rf ./workspace $SSHDIR .npmrc
11
- exit 0
12
- }
13
- trap cleanup INT
14
-
15
- # Usage: colorize <color> <string>
16
- # where: color = [red|green|yellow]
17
- # string = the thing to apply the color to
18
- colorize() {
19
- local C_green='\e[92m'
20
- local C_yellow='\e[93m'
21
- local C_red='\e[91m'
22
- local C_off='\e[0m'
23
-
24
- case "$1" in
25
- 'red' ) clr="$C_red" ;;
26
- 'green' ) clr="$C_green" ;;
27
- 'yellow') clr="$C_yellow" ;;
28
- *) clr=$C_off;;
29
- esac
30
-
31
- printf "$clr$2$C_off"
32
- }
33
-
34
- strip_undefined() {
35
- local result="$1"
36
- [ "$1" == "undefined" ] && result=""
37
- printf "$result"
38
- }
39
-
40
- # Useful links with information regarding k8s/docker/nodejs and PID 1
41
- # No PID 1 for NodeJS => https://bit.ly/2r4gHkZ
42
- # What tini is all about => https://bit.ly/2HsSxqP
43
- # Graceful kills with k8s => https://bit.ly/2NONEJG
44
- #
45
- # Params: $1 = version from dockerize invocation
46
- # $2 = node image to dockerize, default: dubnium-alpine (node 10)
47
- # $3 = additional packages to install (htop redis-cli etc)
48
- create_Dockerfile() {
49
- local regvers="${1}"
50
- local nodeimg="${2:-dubnium-alpine}"
51
- local apkadds="${3}"
52
- echo "Creating the Dockerfile for node ${nodeimg}"
53
- cat<<EODOCKER > Dockerfile
54
- # Version ${regvers} @ `date`
55
- #
56
- # The FROM directive sets the Base Image for subsequent instructions
57
- FROM node:${nodeimg} as intermediate
58
-
59
- RUN mkdir -p /usr/src/app
60
- WORKDIR /usr/src/app
61
-
62
- # Install app dependencies
63
- COPY ./workspace/ /usr/src/app/
64
- ENV GRPC_VERBOSITY ERROR
65
-
66
- # --------------------------------------------------------------
67
- # copy the ssh keys into place, npm install, and remove them
68
- # --------------------------------------------------------------
69
-
70
- # Install packages to install private repos with ssh keys
71
- COPY ./.npmrc /usr/src/app/.npmrc
72
- RUN apk --no-cache add curl git openssh-client && \
73
- apk --update add --no-cache --virtual build-dep g++ gcc libgcc \\
74
- libstdc++ linux-headers make python ${apkadds} && \
75
- npm install --production --silent && \
76
- rm -f /usr/src/app/.npmrc /root/.ssh/*
77
-
78
- # --------------------------------------------------------------
79
- # On to the real build now, the thing before was just an intermediate container
80
- # --------------------------------------------------------------
81
-
82
- FROM node:${nodeimg}
83
-
84
- # Install tint for PID 1 and replace shell with bash so we can source files
85
- RUN apk update && \
86
- apk add --no-cache tini bash vim ${apkadds} && \
87
- rm /bin/sh && ln -s /bin/bash /bin/sh && \
88
- mkdir -p /usr/src/app /tmp/levlog
89
- ENTRYPOINT [ "/sbin/tini", "--" ]
90
- WORKDIR /usr/src/app
91
-
92
- COPY --from=intermediate /usr/src/app /usr/src/app
93
-
94
- USER node
95
- COPY ./bashrc /home/node/.bashrc
96
- CMD [ "/bin/bash", "-c", "node index.js" ]
97
- EODOCKER
98
- } # end of create_Dockerfile
99
-
100
- # Params: $1 = version from dockerize invocation
101
- create_bashrc() {
102
- cat<<EOBASHRC > bashrc
103
- #!/bin/bash
104
- #
105
- # Version $1 @ `date`
106
-
107
- alias h=history
108
-
109
- alias ls='ls -CF --color=auto'
110
- alias ll='ls -lh'
111
- alias lla='ls -lha'
112
- alias ltr='ls -CF --color=auto -lthr'
113
- alias genv='env | grep -i'
114
- alias glep='grep -l -s'
115
- alias m=less
116
- alias menv='env | sort | less'
117
-
118
- alias whatsmyip='wget -qO- ifconfig.co'
119
-
120
- alias dbg='wget -q -O- localhost:5111/logLevel/debug'
121
- alias inf='wget -q -O- localhost:5111/logLevel/info'
122
- alias err='wget -q -O- localhost:5111/logLevel/error'
123
- alias wrn='wget -q -O- localhost:5111/logLevel/warn'
124
-
125
- cmstat()
126
- {
127
- wget -qO- localhost:5111\${1}
128
- }
129
-
130
- cmclear()
131
- {
132
- cmstat /status/clear
133
- }
134
-
135
- loglev()
136
- {
137
- local wget='wget -q -O- localhost:5111'
138
- local logl=''
139
-
140
- if [ "\$1" != "" ];
141
- then
142
- logl="logLevel/\$1"
143
- fi
144
-
145
- printf "Running=> \$wget/\${logl}\n"
146
- printf "\n\`\$wget/\$logl\`\n\n"
147
- }
148
- EOBASHRC
149
- } # end of create_bashrc
150
-
151
- NPMRC="$HOME/.npmrc.ro"
152
- if [ ! -f "$NPMRC" ];
153
- then
154
- cat<<ROTOKEN
155
-
156
- $(colorize 'red' '***ERROR: expecting to see a readonly npmjs token')
157
-
158
- For security purposes, we deploy images with read-only npmjs tokens.
159
- These may be acquired from another developer, or can be created with the
160
- npmjs leverege account.
161
-
162
- Obtain the token and drop it here => $(colorize 'green' "$NPMRC")
163
-
164
-
165
- ROTOKEN
166
- exit 1
167
- fi
168
-
169
- # Look for leverege specifics, but only require the project name.
170
- project=$(strip_undefined "`node -p \"require('../package.json').leverege.project\"`")
171
- if [ "$project" == "" ];
172
- then
173
- cat<<NOPROJ
174
-
175
- $(colorize 'red' '***ERROR: package.json missing a leverege project statement')
176
-
177
- The package.json file must contain a project setting in the leverege
178
- namespace stating which GCP project the docker images are written to. It
179
- should look something like:
180
-
181
- "leverege": {
182
- "project": "leverege-docker-images"
183
- },
184
-
185
- NOPROJ
186
- exit 1
187
- fi
188
-
189
- nodeimg=$(strip_undefined "`node -p \"require('../package.json').leverege.nodeimg\"`")
190
- nodeimg="${nodeimg:-carbon-alpine}"
191
- apkadds=$(strip_undefined "`node -p \"require('../package.json').leverege.apkadds\"`")
192
-
193
- container="`node -p \"require('../package.json').leverege.container\"`"
194
- if [ "$container" == "undefined" ];
195
- then
196
- container=$(basename `git config --get remote.origin.url` .git)
197
- fi
198
- gcimage=gcr.io/$project/$container
199
-
200
- version=$1
201
- previous=`cat .previous`
202
- pckgver="v`node -p \"require('../package.json').version\"`"
203
- pckgdts="`date +\"%Y%m%d-%H%M\"`"
204
- tagging=`echo $version | egrep -e "^v\d+\.\d+\.\d+$"`
205
-
206
- if [ $tagging ];
207
- then
208
- if [[ `git status --porcelain` ]]; then
209
- cat<<DIRTAG
210
-
211
- $(colorize 'red' '***ERROR: attempting to tag a non-beta dirty git repository')
212
-
213
- You are attempting to create a tagged release image for pushing to the
214
- container registry, but there are locally modified files. This is not
215
- allowed since the applied tag will not be relevant to the image version
216
- due to the pending commits.
217
-
218
- Available options for proceeding:
219
-
220
- $(colorize 'green' '1) cleanly commit all local mods assuming relevance')
221
- $(colorize 'yellow' '2) eliminate unwanted local modifications')
222
- $(colorize 'red' '3) stash anything that is irrelevant to this release')
223
-
224
-
225
- DIRTAG
226
- exit 1
227
- fi
228
-
229
- # since we're tagging, the current branch must have an upstream
230
- branch=`git rev-parse --abbrev-ref HEAD`
231
- git rev-parse --abbrec-ref ${branch}@{u} &> /dev/null
232
-
233
- if [ $? -ne 0 ];
234
- then
235
- cat<<NOUPSTR
236
-
237
- $(colorize 'red' '***ERROR: the current branch must have an upstream')
238
-
239
- You are attempting to create a tagged release image for pushing to the
240
- container registry, but the current branch does not have an upstream to
241
- push to. This is not allowed since the applied tag will be stranded here
242
- in your local repository, which is what we are attempting to avoid.
243
-
244
- Available options for proceeding:
245
-
246
- $(colorize 'green' '1) set an upstream for this branch via:')
247
- $(colorize 'green' " git push --set-upstream origin ${branch}")
248
-
249
- $(colorize 'yellow' '2) rebase, squash and merge onto a branch with an upstream')
250
-
251
- NOUPSTR
252
- exit 1
253
- fi
254
-
255
- tagstat=$(colorize 'yellow' 'will be tagged')
256
- else
257
- tagstat=$(colorize 'red' 'BETA RELEASE WILL NOT BE TAGGED')
258
- fi
259
-
260
- cat<<IMGINFO
261
-
262
- Project: $(colorize 'green' "$project")
263
- Container: $(colorize 'green' "$container")
264
- NodeImage: $(colorize 'green' "$nodeimg")
265
- AddedPkgs: $(colorize 'green' "$apkadds")
266
- Version: $(colorize 'green' "$version") $tagstat
267
- Previous: $(colorize 'yellow' "$previous")
268
- DateStamp: $(colorize 'green' "$pckgdts")
269
- GCImage: $(colorize 'green' "$gcimage:$version")
270
-
271
- IMGINFO
272
-
273
- if [ "$pckgver" != "$version" ];
274
- then
275
- cat<<EOPKG
276
- $(colorize 'yellow' '***WARNING: specified version does not match package.json version' )
277
- package.json => $(colorize 'green' "$pckgver")
278
- specified => $(colorize 'red' "$version")
279
-
280
- EOPKG
281
- if [ $tagging ];
282
- then
283
- cat<<EONOPE
284
-
285
- $(colorize 'red' '... and you are attempting to release so NOPE!' )
286
-
287
- EONOPE
288
- exit 1
289
- fi
290
- fi
291
-
292
- create_Dockerfile "$version" "$nodeimg" "$apkadds"
293
- create_bashrc "$version" "$nodeimg"
294
-
295
- [ -d ./workspace ] && rm -rf ./workspace
296
- mkdir -p ./workspace
297
- cp -rfp ../package*json ../dist/* ./workspace
298
-
299
- # grab the read only npmrc token for the image
300
- cp -f $NPMRC .npmrc
301
-
302
- [ "$CIRCLECI" == "true" ] && exit 0
303
-
304
- printf "Hit return to continue or ^C to exit\n\n"; read ANS
305
-
306
- echo $version > .previous
307
-
308
- echo "Changing Google Project to $project"
309
- gcloud config set project $project
310
-
311
- echo "Creating Docker Image for $gcimage:$version"
312
- echo " Building the workspace"
313
-
314
- # use kaniko to cache builds
315
- if [ "$USE_KANIKO" == "yes" ];
316
- then
317
- gcloud config set builds/use_kaniko True
318
- else
319
- gcloud config unset builds/use_kaniko
320
- fi
321
-
322
- # submit the build request to gcloud
323
- gcloud builds submit --tag $gcimage:$version .
324
-
325
- if [ $? -ne 0 ];
326
- then
327
- bldErr=$?
328
- cat<<BUILDERR
329
-
330
- $(colorize 'red' '***ERROR: build failed! Aborting without tagging.')
331
-
332
- The gcloud build process seems to have run into a problem. Please fix the
333
- issue and rerun the dockerize process. This build will not be tagged, nor
334
- will it be pushed.
335
-
336
- BUILDERR
337
- exit $bldErr
338
- fi
339
-
340
- # Tag the container with the node detailsand the culprit.
341
- gcloud beta container images add-tag --quiet $gcimage:$version $gcimage:$pckgdts-$nodeimg-$USER
342
-
343
- if [ $tagging ];
344
- then
345
- printf "\n$(colorize 'green' "Tagging and Pushing $version")\n"
346
- git tag -af $1 -m "Docker version $1"
347
- git push --follow-tags
348
- gcloud beta container images add-tag --quiet $gcimage:$version $gcimage:latest
349
- else
350
- printf "\n$(colorize 'yellow' '*** Skipped git tagging - beta release')\n\n"
351
- fi
352
-
353
- cleanup
@@ -1,49 +0,0 @@
1
- #!/bin/bash
2
- display_usage() {
3
- echo "This script encrypts files using Google KMS."
4
- echo -e "\nInputs: .env and secrets directory (if it exists) \n"
5
- }
6
-
7
- if [ "$1" == "-h" ]; then
8
- display_usage
9
- exit 1
10
- fi
11
-
12
- # Attempt to grab org name from git remote origin
13
- git_orgname=`git config --get remote.origin.url | cut -d ":" -f 2 | cut -d "/" -f 1`
14
-
15
- # Set project based on org name
16
- printf "\nDetecting organization name...\n"
17
-
18
- if [ "$git_orgname" = "leverege" ]; then
19
- printf "\nUsing leverege\n\n"
20
- gcp_project=leverege-docker-images
21
- elif [ "$git_orgname" = "cox2m" ]; then
22
- printf "\nUsing cox2m\n\n"
23
- gcp_project=cox2m-docker-images
24
- else
25
- printf "\nDid not recognize organization name...\n"
26
- printf "\nDefaulting to leverege\n\n"
27
- gcp_project=leverege-docker-images
28
- fi
29
-
30
- # encrypt .env file
31
- gcloud kms encrypt --project $gcp_project \
32
- --key circle-ci \
33
- --keyring build-tools \
34
- --location us-east4 \
35
- --plaintext-file .env \
36
- --ciphertext-file .env.enc
37
-
38
- if [ -d "secrets" ]; then
39
- # tar up secrets directory
40
- tar -zcvf secrets.tar.gz secrets
41
- # encrypt secrets file
42
- gcloud kms encrypt \
43
- --project $gcp_project \
44
- --key circle-ci \
45
- --keyring build-tools \
46
- --location us-east4 \
47
- --plaintext-file secrets.tar.gz \
48
- --ciphertext-file secrets.tar.gz.enc
49
- fi
@@ -1,23 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- /**
4
- * This script parses a firebase config into something useful.
5
- */
6
- let stdbuf = []
7
-
8
- process.stdin
9
- .on( 'data', ( d ) => { stdbuf.push( d ) } )
10
- .on( 'end', () => {
11
- const rawCfg = stdbuf.join( '' ).replace( /["\n\r]/g, '' )
12
- const keyVals = rawCfg.match(/\{(.*)\}/)[1].split(',')
13
-
14
- const lastLine = keyVals.length - 1
15
- console.log( "{" )
16
- for( let i = 0; i <= lastLine; i++ ) {
17
- const kv = keyVals[i].trim().split( ' ' )
18
- console.log( ` "${kv[0].replace( /:/, '')}": "${kv[1]}"${(i < lastLine ? ',' : '')}` )
19
- }
20
- console.log( "}" )
21
-
22
- } )
23
- .setEncoding( 'utf8' )
@@ -1,48 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- /**
4
- * This script will allow the user to grab a value from a JSON file and
5
- * optionally apply a regular expression to it. Given this test.json file:
6
- *
7
- * {
8
- * "name": "@leverege/packagename",
9
- * "main": "lib/index.js"
10
- * }
11
- *
12
- * and invoking as:
13
- * ./getjson --file ./test.json --key name --regex "^@\w{3}"
14
- *
15
- * will yield an output of: @lev
16
- */
17
-
18
- /**
19
- * Get a command line switch parser.
20
- */
21
- const fs = require( 'fs' )
22
- const opts = require( 'commander' )
23
-
24
- opts
25
- .version( '0.0.1' )
26
- .option( '-f, --file <file name>', 'file to parse JSON from' )
27
- .option( '-k, --key <key>', 'JSON key whose value to grab' )
28
- .option( '-r, --regex <reg>', 'regular expression to apply to the value' )
29
- .parse( process.argv )
30
-
31
- if( !opts.key ) { return }
32
-
33
- if( !opts.file ) {
34
- console.error( `\n***ERROR: Missing a --file param\n` )
35
- opts.outputHelp()
36
- process.exit( 1 )
37
- }
38
-
39
- try {
40
- const json = JSON.parse( fs.readFileSync( opts.file, 'utf8' ))
41
- const value = json[opts.key]
42
- const match = new RegExp( opts.regex || ".*" ).exec( value )
43
-
44
- console.log( match ? match[match.length-1] : '' )
45
- }
46
- catch( e ) {
47
- console.log( e )
48
- }
@@ -1,89 +0,0 @@
1
- #!/bin/bash
2
-
3
- # If it isn't already set use the default ~/work/.gitar
4
- #
5
- [ -z $GITAR ] && GITAR="${HOME}/.gitar"
6
-
7
- if [ ! -d $GITAR ]
8
- then
9
- cat<<GITAR
10
-
11
- *** Either set \$GITAR to point to the directory for storing the tarballs
12
- *** or mkdir $GITAR and we will use that instead.
13
-
14
- GITAR
15
- exit 2
16
- fi
17
-
18
- TARX="$GITAR/AAA_TarExcludes"
19
-
20
- # Might be nice to eventually build this up from the .gitignore files or
21
- # maybe the output from git ls-files --others --ignore --exclude-standard
22
- if [ ! -f $TARX ]
23
- then
24
- cat<<TARX
25
-
26
- *** Missing $TARX
27
-
28
- *** This file is used to contain a list of files to exclude from the
29
- *** tarball. Creating with default list of:
30
-
31
- *.o
32
- *.so
33
- core.*
34
- node_modules
35
- TARX
36
-
37
- cat > $TARX <<DEFX
38
- *.o
39
- *.so
40
- core.*
41
- node_modules
42
- DEFX
43
- fi
44
-
45
- # Ask git for the root directory of the repository,
46
- GTOP=`git rev-parse --show-toplevel 2> /dev/null`
47
-
48
- if [ $? != 0 ];
49
- then
50
- cat<<NOGIT
51
-
52
- *** Are you sure this is a git repository?
53
-
54
- NOGIT
55
- exit 2
56
- fi
57
-
58
- REPO=`basename ${GTOP}`
59
-
60
- # Create the repo tarball dir if needed
61
- #
62
- [ ! -d $GITAR/$REPO ] && mkdir $GITAR/$REPO
63
-
64
- # Build a date time string of YYYYMMDD-HHMMSS
65
- #
66
- DTS="`date +\"%Y%m%d-%H%M%S\"`"
67
-
68
- TARB=${GITAR}/${REPO}/${DTS}.tar # Craft the target tarball name.
69
-
70
- # Now do the work
71
- #
72
- cd ${GTOP}/..
73
- printf "\n*** Tarring $TARB\n"
74
- tar cf $TARB -X $TARX $REPO
75
- chmod 0640 $TARB
76
-
77
- # Do the compression and use xz if it's available
78
- #
79
- ZIPPER=bzip2
80
- FIZ=bz2
81
- if (type xz 2>&1) >/dev/null
82
- then
83
- ZIPPER=xz
84
- FIZ=xz
85
- fi
86
-
87
- printf "*** Compressing $TARB.$FIZ (background)\n\n"
88
- $ZIPPER $TARB &
89
- cd - 2>&1 >/dev/null
package/lib/server/helmdn DELETED
@@ -1,111 +0,0 @@
1
- #!/bin/bash
2
-
3
- # Simple ANSI color coded string generator.
4
- color() {
5
- local color=
6
- case "$1" in
7
- 'g') color="92m" ;; # green
8
- 'c') color="96m" ;; # lt blue
9
- 'y') color="93m" ;; # yellow
10
- 'r') color="91m" ;; # red
11
- 'toast') color="1;3;7;91;103;5m" ;;
12
- esac
13
- printf "\e[$color$2\e[0m"
14
- }
15
-
16
- clearlyWarn() {
17
- clear
18
- cat<<CLEARWARN
19
-
20
- `color toast '*** WARNING *** WARNING *** WARNING *** WARNING *** WARNING *** WARNING ***'`
21
-
22
- CLEARWARN
23
- }
24
-
25
- clearlyWarn
26
- cat<<ABOUT2NUKE
27
- You are about to start nuking deployments, as in delete with --purge. Are
28
- you certain this is what you want to do?
29
-
30
- Enter "yes" if that is in fact the case.
31
-
32
- ABOUT2NUKE
33
-
34
- read ANS && [ "$ANS" != "yes" ] && exit 1
35
-
36
- #
37
- # This script is used to ease the pain of transition testing to chart museum
38
- # prior to setting up keel for new clusters / installs.
39
- #
40
- PLATFORM=(
41
- api-server
42
- db-curator
43
- emailer
44
- imagine
45
- message-processor
46
- messenger
47
- reason
48
- scheduler
49
- transponder-bq
50
- transponder-fb
51
- transponder-postgres
52
- # transponder-sql
53
- )
54
-
55
- SYSTEM=(
56
- elastic
57
- monitoring
58
- polaris
59
- redis
60
- velero
61
- )
62
-
63
- GITTOP=`git rev-parse --show-toplevel`
64
- cd $GITTOP
65
-
66
- npm run ahoy
67
- [ $? -ne 0 ] && printf "\n\n***Aborting helmup...\n\n" && exit 1
68
-
69
- helm repo update && helm search chartmuseum
70
-
71
- function doNuking() {
72
-
73
- for PARAM in "$@";
74
- do
75
- SERVICE=${PARAM%/} # strip trailing / if it's there
76
-
77
- if [ "$SERVICE" == "platform" ];
78
- then
79
- doNuking "${PLATFORM[@]}" && exit $?
80
- fi
81
-
82
- if [ "$SERVICE" == "system" ];
83
- then
84
- doNuking "${SYSTEM[@]}" && exit $?
85
- fi
86
-
87
- if [ "$SERVICE" == "ingress" ];
88
- then
89
- clearlyWarn
90
- cat<<NOGRESS
91
-
92
- Deleting the ingress is probably the most costly deployment to nuke since
93
- it takes so long to rebuild and stabilize. Therefore, if you REALLY want
94
- to do that then you can copy and paste these commands by hand and do it
95
- yourself:
96
-
97
- npm run ahoy; helm delete --purge $SERVICE
98
-
99
- NOGRESS
100
- continue
101
- fi
102
-
103
- [ "$SERVICE" == "elastic" ] && doNuking elasticsearch && continue
104
-
105
- helm delete --purge $SERVICE
106
- done
107
- }
108
-
109
- doNuking $@
110
- printf "\nDoing => helm ls\n\n" && helm ls
111
- cd - &> /dev/null