Comparing version 1.2.0 to 1.2.1
102
index.js
#!/usr/bin/env node | ||
'use strict'; | ||
const get = require('lodash/get') | ||
const execSync = require('child_process').execSync | ||
const readFileSync = require('fs').readFileSync | ||
const pjson = JSON.parse(readFileSync('package.json')) | ||
const config = pjson.config || {} | ||
const tagName = pjson.version | ||
const argv = require('yargs') | ||
.option('pre-tag', { | ||
alias: 'ot', | ||
describe: 'Commands to execute before building the docker image', | ||
type: 'array', | ||
default: [], | ||
}).argv | ||
function authConfig() { | ||
['ecrRepoUrl', 'ecrRepoName'].forEach(key => { | ||
if (! (key in config)) { | ||
console.error(`Missing required key config.${key}`) | ||
process.exit(1) | ||
} | ||
}) | ||
function readPackageKey(key) { | ||
const value = get(pjson, key) | ||
if (value) { | ||
console.log(`- ${key}: ${value}`) | ||
return value | ||
} else { | ||
console.error(`Missing \`${key}\` key in \`package.json\` `) | ||
process.exit(1) | ||
} | ||
} | ||
console.log('Deployment configuration:') | ||
const repoName = readPackageKey('name') | ||
const tagName = readPackageKey('version') | ||
const ecrRepoName = readPackageKey('config.ecrRepoName') | ||
const ecrRepoUrl = readPackageKey('config.ecrRepoUrl') | ||
// if pushing a tag | ||
// check if deps are met, exit with non-zero if not | ||
// do the docker-login stuff | ||
// build the docker image | ||
// tag the docker image with the same tag that is being pushed | ||
// push the docker image | ||
// if it fails, exit non-zero. the output of the command will appear so hopefully that's enough of an error message. | ||
// If success, exit 0 | ||
function exec(cmd, opts={}) { | ||
@@ -46,50 +37,17 @@ opts.stdio = 'stdio' in opts ? opts.stdio : [0, 1, 2] | ||
function buildAndPushDockerImage() { | ||
const remoteTag = `${config.ecrRepoUrl}/${config.ecrRepoName}:${tagName}` | ||
const localTag = `${config.ecrRepoName}:${tagName}` | ||
exec('`aws ecr get-login --region eu-west-1`') | ||
exec(`docker build -t ${localTag} .`) | ||
exec(`docker tag ${localTag} ${remoteTag}`) | ||
exec(`docker push ${remoteTag}`) | ||
function buildAndPushDockerImageRemote() { | ||
const remoteTag = `${ecrRepoUrl}/${ecrRepoName}:${tagName}` | ||
const localTag = `${ecrRepoName}:${tagName}` | ||
let sshcmd = [ | ||
`cd ${repoName}`, | ||
'git fetch', | ||
`git checkout v${tagName}`, | ||
'eval $(aws ecr get-login --region eu-west-1)', | ||
`docker build -t ${localTag} .`, | ||
`docker tag ${localTag} ${remoteTag}`, | ||
`docker push ${remoteTag}`, | ||
].join(' && ') | ||
exec(`ssh docker-build "${sshcmd}"`) | ||
} | ||
function startDockerIfNeeded() { | ||
if (process.platform == 'darwin') { | ||
try { | ||
execSync('docker ps') | ||
} catch(e) { | ||
exec('docker-machine restart') | ||
exec('docker-machine env', {stdio: undefined}).toString().split('\n') | ||
.filter(c => c.startsWith('export')) | ||
.map(c => c.split('=')) | ||
.map(([key, val]) => [key.replace('export ', ''), val.slice(1, -1)]) | ||
.map(([key, val]) => process.env[key] = val) | ||
} | ||
} | ||
} | ||
// Checks that the 'docker' and 'aws' commands exist, if they do not, will | ||
// exit in error | ||
function checkDeps() { | ||
const opts = {stdio: undefined} | ||
exec('which docker', opts) | ||
exec('which aws', opts) | ||
} | ||
function runPreArgs() { | ||
argv['pre-tag'].forEach(cmd => { | ||
exec(cmd) | ||
}) | ||
} | ||
process.stdin.once('data', data => { | ||
const commitLine = data.toString().trim() | ||
if (commitLine.startsWith('refs/tags/')) { | ||
console.log('Detected tag push, attempting to build docker image') | ||
authConfig() | ||
checkDeps() | ||
runPreArgs() | ||
startDockerIfNeeded() | ||
buildAndPushDockerImage() | ||
} | ||
}) | ||
buildAndPushDockerImageRemote() |
{ | ||
"name": "cpdeploy", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "", | ||
@@ -24,5 +24,4 @@ "main": "index.js", | ||
"dependencies": { | ||
"husky": "~0.11.4", | ||
"yargs": "~4.7.1" | ||
"lodash": "~4.15.0" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
1
1
1
3745
45
+ Addedlodash@~4.15.0
+ Addedlodash@4.15.0(transitive)
- Removedhusky@~0.11.4
- Removedyargs@~4.7.1
- Removedansi-regex@2.1.1(transitive)
- Removedcamelcase@3.0.0(transitive)
- Removedci-info@1.6.0(transitive)
- Removedcliui@3.2.0(transitive)
- Removedcode-point-at@1.1.0(transitive)
- Removeddecamelize@1.2.0(transitive)
- Removederror-ex@1.3.2(transitive)
- Removedfind-up@1.1.2(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedgraceful-fs@4.2.11(transitive)
- Removedhasown@2.0.2(transitive)
- Removedhosted-git-info@2.8.9(transitive)
- Removedhusky@0.11.9(transitive)
- Removedinvert-kv@1.0.0(transitive)
- Removedis-arrayish@0.2.1(transitive)
- Removedis-ci@1.2.1(transitive)
- Removedis-core-module@2.16.0(transitive)
- Removedis-fullwidth-code-point@1.0.0(transitive)
- Removedis-utf8@0.2.1(transitive)
- Removedlcid@1.0.0(transitive)
- Removedload-json-file@1.1.0(transitive)
- Removedlodash.assign@4.2.0(transitive)
- Removednormalize-package-data@2.5.0(transitive)
- Removednormalize-path@1.0.0(transitive)
- Removednumber-is-nan@1.0.1(transitive)
- Removedobject-assign@4.1.1(transitive)
- Removedos-locale@1.4.0(transitive)
- Removedparse-json@2.2.0(transitive)
- Removedpath-exists@2.1.0(transitive)
- Removedpath-parse@1.0.7(transitive)
- Removedpath-type@1.1.0(transitive)
- Removedpify@2.3.0(transitive)
- Removedpinkie@2.0.4(transitive)
- Removedpinkie-promise@2.0.1(transitive)
- Removedpkg-conf@1.1.3(transitive)
- Removedread-pkg@1.1.0(transitive)
- Removedread-pkg-up@1.0.1(transitive)
- Removedrequire-main-filename@1.0.1(transitive)
- Removedresolve@1.22.9(transitive)
- Removedsemver@5.7.2(transitive)
- Removedset-blocking@1.0.0(transitive)
- Removedspdx-correct@3.2.0(transitive)
- Removedspdx-exceptions@2.5.0(transitive)
- Removedspdx-expression-parse@3.0.1(transitive)
- Removedspdx-license-ids@3.0.20(transitive)
- Removedstring-width@1.0.2(transitive)
- Removedstrip-ansi@3.0.1(transitive)
- Removedstrip-bom@2.0.0(transitive)
- Removedsupports-preserve-symlinks-flag@1.0.0(transitive)
- Removedsymbol@0.2.3(transitive)
- Removedvalidate-npm-package-license@3.0.4(transitive)
- Removedwindow-size@0.2.0(transitive)
- Removedwrap-ansi@2.1.0(transitive)
- Removedy18n@3.2.2(transitive)
- Removedyargs@4.7.1(transitive)
- Removedyargs-parser@2.4.1(transitive)