@leverege/build-tools 1.8.4
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/.publishrc +15 -0
- package/CHANGELOG.md +30 -0
- package/LICENSE.md +3 -0
- package/README.md +32 -0
- package/lib/server/auditate/help.js +119 -0
- package/lib/server/auditate/index.js +23 -0
- package/lib/server/auditate/report.js +61 -0
- package/lib/server/circleate +549 -0
- package/lib/server/decrypt-secrets +91 -0
- package/lib/server/dnsify/CloudflareAPI.js +103 -0
- package/lib/server/dnsify/accounts.json.enc +0 -0
- package/lib/server/dnsify/index.js +92 -0
- package/lib/server/dockreate +338 -0
- package/lib/server/encrypt-secrets +31 -0
- package/lib/server/getfbcfg +23 -0
- package/lib/server/getjson +48 -0
- package/lib/server/helmdn +103 -0
- package/lib/server/helmify +289 -0
- package/lib/server/helmup +87 -0
- package/lib/server/overwhelm +303 -0
- package/lib/server/packleate/Packleator.js +269 -0
- package/lib/server/packleate/index.js +98 -0
- package/lib/server/packleate/logo-ansi.js +17 -0
- package/lib/server/pkgck +136 -0
- package/lib/server/pkglint/index.js +19 -0
- package/lib/server/test.json +4 -0
- package/lib/web/auditate/help.js +158 -0
- package/lib/web/auditate/index.js +27 -0
- package/lib/web/auditate/report.js +91 -0
- package/lib/web/dnsify/CloudflareAPI.js +250 -0
- package/lib/web/dnsify/index.js +147 -0
- package/lib/web/packleate/Packleator.js +645 -0
- package/lib/web/packleate/index.js +157 -0
- package/lib/web/packleate/logo-ansi.js +3 -0
- package/lib/web/pkglint/index.js +19 -0
- package/package.json +74 -0
- package/src/auditate/help.js +83 -0
- package/src/auditate/index.js +25 -0
- package/src/auditate/report.js +54 -0
- package/src/circleate +549 -0
- package/src/decrypt-secrets +91 -0
- package/src/dnsify/CloudflareAPI.js +99 -0
- package/src/dnsify/accounts.json.enc +0 -0
- package/src/dnsify/index.js +82 -0
- package/src/dockreate +338 -0
- package/src/encrypt-secrets +31 -0
- package/src/getfbcfg +23 -0
- package/src/getjson +48 -0
- package/src/helmdn +103 -0
- package/src/helmify +289 -0
- package/src/helmup +87 -0
- package/src/overwhelm +303 -0
- package/src/packleate/Packleator.js +271 -0
- package/src/packleate/index.js +86 -0
- package/src/packleate/logo-ansi.js +16 -0
- package/src/pkgck +136 -0
- package/src/pkglint/index.js +21 -0
- package/src/test.json +4 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const ora = require('ora');
|
|
4
|
+
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
|
|
7
|
+
const path = require('path');
|
|
8
|
+
|
|
9
|
+
const {
|
|
10
|
+
promisify
|
|
11
|
+
} = require('util');
|
|
12
|
+
|
|
13
|
+
class CloudflareAPI {
|
|
14
|
+
constructor(options) {
|
|
15
|
+
const {
|
|
16
|
+
args
|
|
17
|
+
} = options;
|
|
18
|
+
const {
|
|
19
|
+
url,
|
|
20
|
+
proxy,
|
|
21
|
+
ipaddress,
|
|
22
|
+
account
|
|
23
|
+
} = args;
|
|
24
|
+
this.url = url;
|
|
25
|
+
this.proxy = proxy;
|
|
26
|
+
this.ipaddress = ipaddress;
|
|
27
|
+
this.spinner = ora({
|
|
28
|
+
text: 'Creating DNS record...',
|
|
29
|
+
spinner: 'monkey'
|
|
30
|
+
});
|
|
31
|
+
this.account = account;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async decrypt(projectId = 'leverege-docker-images', keyRingId = 'build-tools', cryptoKeyId = 'circle-ci', ciphertextFileName = './accounts.json.enc', plaintextFileName = './accounts.json') {
|
|
35
|
+
// Import the library and create a client
|
|
36
|
+
const kms = require('@google-cloud/kms');
|
|
37
|
+
|
|
38
|
+
const client = new kms.KeyManagementServiceClient(); // The location of the crypto key's key ring, e.g. "global"
|
|
39
|
+
|
|
40
|
+
const locationId = 'us-east4'; // Reads the file to be decrypted
|
|
41
|
+
|
|
42
|
+
const readFile = promisify(fs.readFile);
|
|
43
|
+
const contentsBuffer = await readFile(path.resolve(__dirname, ciphertextFileName));
|
|
44
|
+
const name = client.cryptoKeyPath(projectId, locationId, keyRingId, cryptoKeyId);
|
|
45
|
+
const ciphertext = contentsBuffer.toString('base64'); // Decrypts the file using the specified crypto key
|
|
46
|
+
|
|
47
|
+
const [result] = await client.decrypt({
|
|
48
|
+
name,
|
|
49
|
+
ciphertext
|
|
50
|
+
}); // Writes the decrypted file to disk
|
|
51
|
+
|
|
52
|
+
const writeFile = promisify(fs.writeFile);
|
|
53
|
+
await writeFile(path.resolve(__dirname, plaintextFileName), Buffer.from(result.plaintext, 'base64'));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
setAccountValues() {
|
|
57
|
+
const accountJson = require(path.resolve(__dirname, './accounts.json'));
|
|
58
|
+
|
|
59
|
+
const accountInfo = accountJson[this.account];
|
|
60
|
+
const {
|
|
61
|
+
email,
|
|
62
|
+
key,
|
|
63
|
+
zone
|
|
64
|
+
} = accountInfo;
|
|
65
|
+
this.cf = require('cloudflare')({
|
|
66
|
+
email,
|
|
67
|
+
key
|
|
68
|
+
});
|
|
69
|
+
this.zone = zone;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async deleteSecrets() {
|
|
73
|
+
const deleteFile = promisify(fs.unlink);
|
|
74
|
+
await deleteFile(path.resolve(__dirname, './accounts.json'));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async createDNSRecord() {
|
|
78
|
+
try {
|
|
79
|
+
this.spinner.start();
|
|
80
|
+
this.spinner.text = 'Decrypting Cloudflare secrets...';
|
|
81
|
+
await this.decrypt();
|
|
82
|
+
this.spinner.text = 'Initializing Cloudflare API...';
|
|
83
|
+
this.setAccountValues();
|
|
84
|
+
this.spinner.text = 'Adding A name record...';
|
|
85
|
+
await this.cf.dnsRecords.add(this.zone, {
|
|
86
|
+
type: 'A',
|
|
87
|
+
name: this.url,
|
|
88
|
+
content: this.ipaddress,
|
|
89
|
+
proxied: this.proxy
|
|
90
|
+
});
|
|
91
|
+
this.spinner.text = 'Removing secrets...';
|
|
92
|
+
await this.deleteSecrets();
|
|
93
|
+
this.spinner.stop();
|
|
94
|
+
} catch (ex) {
|
|
95
|
+
this.spinner.stop();
|
|
96
|
+
console.log(ex);
|
|
97
|
+
throw ex;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
module.exports = CloudflareAPI;
|
|
Binary file
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
const commandLineArgs = require('command-line-args');
|
|
5
|
+
|
|
6
|
+
const commandLineUsage = require('command-line-usage');
|
|
7
|
+
|
|
8
|
+
const Cloudflare = require('./CloudflareAPI');
|
|
9
|
+
|
|
10
|
+
const defaultConfig = {
|
|
11
|
+
account: 'leverege',
|
|
12
|
+
proxy: true
|
|
13
|
+
};
|
|
14
|
+
const sections = [{
|
|
15
|
+
content: 'Wraps Cloudflare to modify DNS configs for new UI/Servers'
|
|
16
|
+
}, {
|
|
17
|
+
header: 'Options',
|
|
18
|
+
optionList: [{
|
|
19
|
+
name: 'account',
|
|
20
|
+
alias: 'a',
|
|
21
|
+
description: 'Cloudflare account to use'
|
|
22
|
+
}, {
|
|
23
|
+
name: 'ipaddress',
|
|
24
|
+
alias: 'i',
|
|
25
|
+
description: 'IP address to point DNS account to (e.g. 35.178.29.10)'
|
|
26
|
+
}, {
|
|
27
|
+
name: 'url',
|
|
28
|
+
alias: 'u',
|
|
29
|
+
description: 'URL name (e.g. myserver)'
|
|
30
|
+
}, {
|
|
31
|
+
name: 'proxy',
|
|
32
|
+
alias: 'p',
|
|
33
|
+
description: 'Turn on Cloudflare proxy (optional)'
|
|
34
|
+
}, {
|
|
35
|
+
name: 'help',
|
|
36
|
+
description: 'Print this usage guide.'
|
|
37
|
+
}]
|
|
38
|
+
}];
|
|
39
|
+
const usage = commandLineUsage(sections);
|
|
40
|
+
const optionDefinitions = [{
|
|
41
|
+
name: 'account',
|
|
42
|
+
alias: 'a',
|
|
43
|
+
type: String,
|
|
44
|
+
defaultValue: defaultConfig.account
|
|
45
|
+
}, {
|
|
46
|
+
name: 'ipaddress',
|
|
47
|
+
alias: 'i',
|
|
48
|
+
type: String
|
|
49
|
+
}, {
|
|
50
|
+
name: 'url',
|
|
51
|
+
alias: 'u',
|
|
52
|
+
type: String
|
|
53
|
+
}, {
|
|
54
|
+
name: 'proxy',
|
|
55
|
+
alias: 'p',
|
|
56
|
+
type: Boolean,
|
|
57
|
+
defaultValue: defaultConfig.proxy
|
|
58
|
+
}, {
|
|
59
|
+
name: 'help',
|
|
60
|
+
alias: 'h',
|
|
61
|
+
type: Boolean
|
|
62
|
+
}];
|
|
63
|
+
const args = commandLineArgs(optionDefinitions);
|
|
64
|
+
|
|
65
|
+
async function main() {
|
|
66
|
+
if (args.help) {
|
|
67
|
+
console.log(usage);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (!args.url || !args.ipaddress) {
|
|
71
|
+
console.log('\n*******************************************');
|
|
72
|
+
console.log('** **');
|
|
73
|
+
console.log('** Need to specify URL and/or IP address **');
|
|
74
|
+
console.log('** **');
|
|
75
|
+
console.log('*******************************************');
|
|
76
|
+
console.log(usage);
|
|
77
|
+
} else {
|
|
78
|
+
const CF = new Cloudflare({ ...defaultConfig,
|
|
79
|
+
args
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
try {
|
|
83
|
+
await CF.createDNSRecord();
|
|
84
|
+
console.log('Successfully created a new DNS record');
|
|
85
|
+
console.log('It may take a few minutes for DNS to propagate');
|
|
86
|
+
} catch (ex) {
|
|
87
|
+
console.error(ex.message);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
main();
|
|
@@ -0,0 +1,338 @@
|
|
|
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/2Txi9Jq
|
|
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: carbon-alpine (node 8)
|
|
47
|
+
# $3 = additional packages to install (htop redis-cli etc)
|
|
48
|
+
create_Dockerfile() {
|
|
49
|
+
local regvers="${1}"
|
|
50
|
+
local nodeimg="${2:-carbon-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
|
+
|
|
65
|
+
# --------------------------------------------------------------
|
|
66
|
+
# copy the ssh keys into place, npm install, and remove them
|
|
67
|
+
# --------------------------------------------------------------
|
|
68
|
+
|
|
69
|
+
# Install packages to install private repos with ssh keys
|
|
70
|
+
COPY ./.npmrc /usr/src/app/.npmrc
|
|
71
|
+
RUN apk --no-cache add curl git openssh-client && \
|
|
72
|
+
apk --update add --no-cache --virtual build-dep g++ gcc libgcc \\
|
|
73
|
+
libstdc++ linux-headers make python && \
|
|
74
|
+
npm install --production --silent && \
|
|
75
|
+
rm -f /usr/src/app/.npmrc /root/.ssh/*
|
|
76
|
+
|
|
77
|
+
# --------------------------------------------------------------
|
|
78
|
+
# On to the real build now, the thing before was just an intermediate container
|
|
79
|
+
# --------------------------------------------------------------
|
|
80
|
+
|
|
81
|
+
FROM node:${nodeimg}
|
|
82
|
+
|
|
83
|
+
# Install tint for PID 1 and replace shell with bash so we can source files
|
|
84
|
+
RUN apk update && \
|
|
85
|
+
apk add --no-cache tini bash vim ${apkadds} && \
|
|
86
|
+
rm /bin/sh && ln -s /bin/bash /bin/sh && \
|
|
87
|
+
mkdir -p /usr/src/app /tmp/levlog
|
|
88
|
+
ENTRYPOINT [ "/sbin/tini", "--" ]
|
|
89
|
+
WORKDIR /usr/src/app
|
|
90
|
+
|
|
91
|
+
COPY --from=intermediate /usr/src/app /usr/src/app
|
|
92
|
+
|
|
93
|
+
USER node
|
|
94
|
+
COPY ./bashrc /home/node/.bashrc
|
|
95
|
+
CMD [ "/bin/bash", "-c", "node index.js" ]
|
|
96
|
+
EODOCKER
|
|
97
|
+
} # end of create_Dockerfile
|
|
98
|
+
|
|
99
|
+
# Params: $1 = version from dockerize invocation
|
|
100
|
+
create_bashrc() {
|
|
101
|
+
cat<<EOBASHRC > bashrc
|
|
102
|
+
#!/bin/bash
|
|
103
|
+
#
|
|
104
|
+
# Version $1 @ `date`
|
|
105
|
+
|
|
106
|
+
alias golog='cd /var/log/levlog;ls -l'
|
|
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 golog='cd /var/log/levlog'
|
|
116
|
+
alias m=less
|
|
117
|
+
alias menv='env | sort | less'
|
|
118
|
+
|
|
119
|
+
alias whatsmyip='wget -qO- ifconfig.co'
|
|
120
|
+
|
|
121
|
+
alias rcli='redis-cli -h \${DATABASES_REDIS_SERVICE_HOST}'
|
|
122
|
+
|
|
123
|
+
alias buny='/usr/src/app/node_modules/bunyan/bin/bunyan'
|
|
124
|
+
alias bunlog='golog;cat *-1.log | buny | m'
|
|
125
|
+
alias dbg='wget -q -O- localhost:5111/logLevel/debug'
|
|
126
|
+
alias inf='wget -q -O- localhost:5111/logLevel/info'
|
|
127
|
+
|
|
128
|
+
loglev()
|
|
129
|
+
{
|
|
130
|
+
local wget='wget -q -O- localhost:5111'
|
|
131
|
+
local logl=''
|
|
132
|
+
|
|
133
|
+
if [ "\$1" != "" ];
|
|
134
|
+
then
|
|
135
|
+
logl="logLevel/\$1"
|
|
136
|
+
fi
|
|
137
|
+
|
|
138
|
+
printf "Running=> \$wget/\$logl\n"
|
|
139
|
+
printf "\n\`\$wget/\$logl\`\n\n"
|
|
140
|
+
}
|
|
141
|
+
EOBASHRC
|
|
142
|
+
} # end of create_bashrc
|
|
143
|
+
|
|
144
|
+
NPMRC="$HOME/.npmrc.ro"
|
|
145
|
+
if [ ! -f "$NPMRC" ];
|
|
146
|
+
then
|
|
147
|
+
cat<<ROTOKEN
|
|
148
|
+
|
|
149
|
+
$(colorize 'red' '***ERROR: expecting to see a readonly npmjs token')
|
|
150
|
+
|
|
151
|
+
For security purposes, we deploy images with read-only npmjs tokens.
|
|
152
|
+
These may be acquired from another developer, or can be created with the
|
|
153
|
+
npmjs leverege account.
|
|
154
|
+
|
|
155
|
+
Obtain the token and drop it here => $(colorize 'green' "$NPMRC")
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
ROTOKEN
|
|
159
|
+
exit 1
|
|
160
|
+
fi
|
|
161
|
+
|
|
162
|
+
# Look for leverege specifics, but only require the project name.
|
|
163
|
+
project=$(strip_undefined "`node -p \"require('../package.json').leverege.project\"`")
|
|
164
|
+
if [ "$project" == "" ];
|
|
165
|
+
then
|
|
166
|
+
cat<<NOPROJ
|
|
167
|
+
|
|
168
|
+
$(colorize 'red' '***ERROR: package.json missing a leverege project statement')
|
|
169
|
+
|
|
170
|
+
The package.json file must contain a project setting in the leverege
|
|
171
|
+
namespace stating which GCP project the docker images are written to. It
|
|
172
|
+
should look something like:
|
|
173
|
+
|
|
174
|
+
"leverege": {
|
|
175
|
+
"project": "leverege-docker-images"
|
|
176
|
+
},
|
|
177
|
+
|
|
178
|
+
NOPROJ
|
|
179
|
+
exit 1
|
|
180
|
+
fi
|
|
181
|
+
|
|
182
|
+
nodeimg=$(strip_undefined "`node -p \"require('../package.json').leverege.nodeimg\"`")
|
|
183
|
+
nodeimg="${nodeimg:-carbon-alpine}"
|
|
184
|
+
apkadds=$(strip_undefined "`node -p \"require('../package.json').leverege.apkadds\"`")
|
|
185
|
+
|
|
186
|
+
container="`node -p \"require('../package.json').leverege.container\"`"
|
|
187
|
+
if [ "$container" == "undefined" ];
|
|
188
|
+
then
|
|
189
|
+
container=$(basename `git config --get remote.origin.url` .git)
|
|
190
|
+
fi
|
|
191
|
+
gcimage=gcr.io/$project/$container
|
|
192
|
+
|
|
193
|
+
version=$1
|
|
194
|
+
previous=`cat .previous`
|
|
195
|
+
pckgver="v`node -p \"require('../package.json').version\"`"
|
|
196
|
+
pckgdts="`date +\"%Y%m%d-%H%M\"`"
|
|
197
|
+
tagging=`echo $version | egrep -e "^v\d+\.\d+\.\d+$"`
|
|
198
|
+
|
|
199
|
+
if [ $tagging ];
|
|
200
|
+
then
|
|
201
|
+
if [[ `git status --porcelain` ]]; then
|
|
202
|
+
cat<<DIRTAG
|
|
203
|
+
|
|
204
|
+
$(colorize 'red' '***ERROR: attempting to tag a non-beta dirty git repository')
|
|
205
|
+
|
|
206
|
+
You are attempting to create a tagged release image for pushing to the
|
|
207
|
+
container registry, but there are locally modified files. This is not
|
|
208
|
+
allowed since the applied tag will not be relevant to the image version
|
|
209
|
+
due to the pending commits.
|
|
210
|
+
|
|
211
|
+
Available options for proceeding:
|
|
212
|
+
|
|
213
|
+
$(colorize 'green' '1) cleanly commit all local mods assuming relevance')
|
|
214
|
+
$(colorize 'yellow' '2) eliminate unwanted local modifications')
|
|
215
|
+
$(colorize 'red' '3) stash anything that is irrelevant to this release')
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
DIRTAG
|
|
219
|
+
exit 1
|
|
220
|
+
fi
|
|
221
|
+
|
|
222
|
+
# since we're tagging, the current branch must have an upstream
|
|
223
|
+
branch=`git rev-parse --abbrev-ref HEAD`
|
|
224
|
+
git rev-parse --abbrec-ref ${branch}@{u} &> /dev/null
|
|
225
|
+
|
|
226
|
+
if [ $? -ne 0 ];
|
|
227
|
+
then
|
|
228
|
+
cat<<NOUPSTR
|
|
229
|
+
|
|
230
|
+
$(colorize 'red' '***ERROR: the current branch must have an upstream')
|
|
231
|
+
|
|
232
|
+
You are attempting to create a tagged release image for pushing to the
|
|
233
|
+
container registry, but the current branch does not have an upstream to
|
|
234
|
+
push to. This is not allowed since the applied tag will be stranded here
|
|
235
|
+
in your local repository, which is what we are attempting to avoid.
|
|
236
|
+
|
|
237
|
+
Available options for proceeding:
|
|
238
|
+
|
|
239
|
+
$(colorize 'green' '1) set an upstream for this branch via:')
|
|
240
|
+
$(colorize 'green' " git push --set-upstream origin ${branch}")
|
|
241
|
+
|
|
242
|
+
$(colorize 'yellow' '2) rebase, squash and merge onto a branch with an upstream')
|
|
243
|
+
|
|
244
|
+
NOUPSTR
|
|
245
|
+
exit 1
|
|
246
|
+
fi
|
|
247
|
+
|
|
248
|
+
tagstat=$(colorize 'yellow' 'will be tagged')
|
|
249
|
+
else
|
|
250
|
+
tagstat=$(colorize 'red' 'BETA RELEASE WILL NOT BE TAGGED')
|
|
251
|
+
fi
|
|
252
|
+
|
|
253
|
+
cat<<IMGINFO
|
|
254
|
+
|
|
255
|
+
Project: $(colorize 'green' "$project")
|
|
256
|
+
Container: $(colorize 'green' "$container")
|
|
257
|
+
NodeImage: $(colorize 'green' "$nodeimg")
|
|
258
|
+
AddedPkgs: $(colorize 'green' "$apkadds")
|
|
259
|
+
Version: $(colorize 'green' "$version") $tagstat
|
|
260
|
+
Previous: $(colorize 'yellow' "$previous")
|
|
261
|
+
DateStamp: $(colorize 'green' "$pckgdts")
|
|
262
|
+
GCImage: $(colorize 'green' "$gcimage:$version")
|
|
263
|
+
|
|
264
|
+
IMGINFO
|
|
265
|
+
|
|
266
|
+
if [ "$pckgver" != "$version" ];
|
|
267
|
+
then
|
|
268
|
+
cat<<EOPKG
|
|
269
|
+
$(colorize 'yellow' '***WARNING: specified version does not match package.json version' )
|
|
270
|
+
package.json => $(colorize 'green' "$pckgver")
|
|
271
|
+
specified => $(colorize 'red' "$version")
|
|
272
|
+
|
|
273
|
+
EOPKG
|
|
274
|
+
if [ $tagging ];
|
|
275
|
+
then
|
|
276
|
+
cat<<EONOPE
|
|
277
|
+
|
|
278
|
+
$(colorize 'red' '... and you are attempting to release so NOPE!' )
|
|
279
|
+
|
|
280
|
+
EONOPE
|
|
281
|
+
exit 1
|
|
282
|
+
fi
|
|
283
|
+
fi
|
|
284
|
+
|
|
285
|
+
create_Dockerfile "$version" "$nodeimg" "$apkadds"
|
|
286
|
+
create_bashrc "$version" "$nodeimg"
|
|
287
|
+
|
|
288
|
+
[ -d ./workspace ] && rm -rf ./workspace
|
|
289
|
+
mkdir -p ./workspace
|
|
290
|
+
cp -rfp ../package*json ../dist/* ./workspace
|
|
291
|
+
|
|
292
|
+
# grab the read only npmrc token for the image
|
|
293
|
+
cp -f $NPMRC .npmrc
|
|
294
|
+
|
|
295
|
+
[ "$CIRCLECI" == "true" ] && exit 0
|
|
296
|
+
|
|
297
|
+
printf "Hit return to continue or ^C to exit\n\n"; read ANS
|
|
298
|
+
|
|
299
|
+
echo $version > .previous
|
|
300
|
+
|
|
301
|
+
echo "Changing Google Project to $project"
|
|
302
|
+
gcloud config set project $project
|
|
303
|
+
|
|
304
|
+
echo "Creating Docker Image for $gcimage:$version"
|
|
305
|
+
echo " Building the workspace"
|
|
306
|
+
|
|
307
|
+
# submit the build request to gcloud
|
|
308
|
+
gcloud builds submit --tag $gcimage:$version .
|
|
309
|
+
|
|
310
|
+
if [ $? -ne 0 ];
|
|
311
|
+
then
|
|
312
|
+
bldErr=$?
|
|
313
|
+
cat<<BUILDERR
|
|
314
|
+
|
|
315
|
+
$(colorize 'red' '***ERROR: build failed! Aborting without tagging.')
|
|
316
|
+
|
|
317
|
+
The gcloud build process seems to have run into a problem. Please fix the
|
|
318
|
+
issue and rerun the dockerize process. This build will not be tagged, nor
|
|
319
|
+
will it be pushed.
|
|
320
|
+
|
|
321
|
+
BUILDERR
|
|
322
|
+
exit $bldErr
|
|
323
|
+
fi
|
|
324
|
+
|
|
325
|
+
# Tag the container with the node detailsand the culprit.
|
|
326
|
+
gcloud beta container images add-tag --quiet $gcimage:$version $gcimage:$pckgdts-$nodeimg-$USER
|
|
327
|
+
|
|
328
|
+
if [ $tagging ];
|
|
329
|
+
then
|
|
330
|
+
printf "\n$(colorize 'green' "Tagging and Pushing $version")\n"
|
|
331
|
+
git tag -af $1 -m "Docker version $1"
|
|
332
|
+
git push --follow-tags
|
|
333
|
+
gcloud beta container images add-tag --quiet $gcimage:$version $gcimage:latest
|
|
334
|
+
else
|
|
335
|
+
printf "\n$(colorize 'yellow' '*** Skipped git tagging - beta release')\n\n"
|
|
336
|
+
fi
|
|
337
|
+
|
|
338
|
+
cleanup
|
|
@@ -0,0 +1,31 @@
|
|
|
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
|
+
if [ -d "secrets" ]; then
|
|
13
|
+
# tar up secrets directory
|
|
14
|
+
tar -zcvf secrets.tar.gz secrets
|
|
15
|
+
# encrypt secrets file
|
|
16
|
+
gcloud kms encrypt \
|
|
17
|
+
--project leverege-docker-images \
|
|
18
|
+
--key circle-ci \
|
|
19
|
+
--keyring build-tools \
|
|
20
|
+
--location us-east4 \
|
|
21
|
+
--plaintext-file secrets.tar.gz \
|
|
22
|
+
--ciphertext-file secrets.tar.gz.enc
|
|
23
|
+
fi
|
|
24
|
+
|
|
25
|
+
# encrypt .env file
|
|
26
|
+
gcloud kms encrypt --project leverege-docker-images \
|
|
27
|
+
--key circle-ci \
|
|
28
|
+
--keyring build-tools \
|
|
29
|
+
--location us-east4 \
|
|
30
|
+
--plaintext-file .env \
|
|
31
|
+
--ciphertext-file .env.enc
|
|
@@ -0,0 +1,23 @@
|
|
|
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]}": "${kv[1]}"${(i < lastLine ? ',' : '')}` )
|
|
19
|
+
}
|
|
20
|
+
console.log( "}" )
|
|
21
|
+
|
|
22
|
+
} )
|
|
23
|
+
.setEncoding( 'utf8' )
|
|
@@ -0,0 +1,48 @@
|
|
|
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
|
+
}
|