@leverege/build-tools 2.0.5 → 2.0.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.
@@ -1,108 +0,0 @@
1
- #!/bin/bash
2
- display_usage() {
3
- echo "This script decrypts files using Google KMS."
4
- echo -e "\nInputs: .env.enc and secrets.tar.gz.enc (if it exists) \n"
5
- }
6
-
7
- install_gcloud() {
8
- install () {
9
- # Set sudo to work whether logged in as root user or non-root user
10
- if [[ $EUID == 0 ]]; then export SUDO=""; else export SUDO="sudo"; fi
11
-
12
- # Create an environment variable for the correct distribution
13
- if [[ $(command -v lsb_release) == "" ]]; then
14
- $SUDO apt-get update && $SUDO apt-get -y install lsb-release
15
- export CLOUD_SDK_REPO="cloud-sdk-$(lsb_release -c -s)"
16
- else
17
- export CLOUD_SDK_REPO="cloud-sdk-$(lsb_release -c -s)"
18
- fi
19
-
20
- # Add the Google Cloud SDK distribution URI as a package source
21
- echo "deb http://packages.cloud.google.com/apt $CLOUD_SDK_REPO main" | $SUDO tee -a /etc/apt/sources.list.d/google-cloud-sdk.list
22
-
23
- # Import the Google Cloud public key
24
- if [[ $(command -v curl) == "" ]]; then
25
- $SUDO apt-get update && $SUDO apt-get -y install curl
26
- curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | $SUDO apt-key add -
27
- else
28
- curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | $SUDO apt-key add -
29
- fi
30
-
31
- # Update and install the Cloud SDK
32
- $SUDO apt-get update && $SUDO apt-get -y install google-cloud-sdk
33
- }
34
-
35
- if grep 'docker\|lxc' /proc/1/cgroup; then
36
- if [[ $(command -v gcloud) == "" ]]; then
37
- install
38
- else
39
- echo "gcloud CLI is already installed."
40
- fi
41
- else
42
- echo "----------------------------------------------------------------------------------------------------"
43
- echo "this is a machine executor job, replacing default installation of gcloud CLI"
44
- echo "----------------------------------------------------------------------------------------------------"
45
- sudo rm -rf /opt/google-cloud-sdk
46
- install
47
- fi
48
- }
49
-
50
- initialize_gcloud() {
51
- echo ${GCLOUD_SERVICE_KEY} > ${HOME}/gcloud-service-key.json
52
-
53
- # Initialize gcloud CLI
54
- gcloud auth activate-service-account --key-file=${HOME}/gcloud-service-key.json
55
- gcloud --quiet config set project ${GOOGLE_PROJECT_ID}
56
- gcloud --quiet config set compute/zone ${GOOGLE_COMPUTE_ZONE}
57
- }
58
-
59
- if [ "$1" == "-h" ]; then
60
- display_usage
61
- exit 1
62
- fi
63
-
64
- if [ "$CIRCLECI" == "true" ]; then
65
- install_gcloud
66
- initialize_gcloud
67
- fi
68
-
69
- # Attempt to grab org name from git remote origin
70
- git_orgname=`git config --get remote.origin.url | cut -d ":" -f 2 | cut -d "/" -f 1`
71
-
72
- # Set project based on org name
73
- printf "\nDetecting organization name...\n"
74
-
75
- if [ "$git_orgname" = "leverege" ]; then
76
- printf "\nUsing leverege\n\n"
77
- gcp_project=leverege-docker-images
78
- elif [ "$git_orgname" = "cox2m" ]; then
79
- printf "\nUsing cox2m\n\n"
80
- gcp_project=cox2m-docker-images
81
- else
82
- printf "\nDid not recognize organization name...\n"
83
- printf "\nDefaulting to leverege\n\n"
84
- gcp_project=leverege-docker-images
85
- fi
86
-
87
- # decrypt .env.enc file
88
- gcloud kms decrypt \
89
- --project $gcp_project \
90
- --key circle-ci \
91
- --keyring build-tools \
92
- --location us-east4 \
93
- --plaintext-file .env \
94
- --ciphertext-file .env.enc
95
-
96
- if [ -f "secrets.tar.gz.enc" ]; then
97
- # decrypt the secrets.tar.gz.enc
98
- gcloud kms decrypt \
99
- --project $gcp_project \
100
- --key circle-ci \
101
- --keyring build-tools \
102
- --location us-east4 \
103
- --plaintext-file secrets.tar.gz \
104
- --ciphertext-file secrets.tar.gz.enc
105
-
106
- # untar secrets.tar.gz
107
- tar xvzf secrets.tar.gz
108
- fi
@@ -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