Skip to content

Instantly share code, notes, and snippets.

@rosskevin
Created November 13, 2018 22:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rosskevin/de6e21d5831e3c9ba85d368484d9a1cb to your computer and use it in GitHub Desktop.
Save rosskevin/de6e21d5831e3c9ba85d368484d9a1cb to your computer and use it in GitHub Desktop.
ksonnet setup
#!/usr/bin/env bash
set -e
MANIFESTS=${BASH_SOURCE%/*}/./environments/$1/manifests
rm -rf ${MANIFESTS} && mkdir ${MANIFESTS}
FILE=${MANIFESTS}/cert-manager.yml
./show "$@" --module cert-manager > ${FILE}
FILE=${MANIFESTS}/certificates.yml
./show "$@" --component traefik.certWildcard --component spinnaker.certWildcard > ${FILE}
FILE=${MANIFESTS}/dbmigrate.yml
./show "$@" --component app.dbmigrate > ${FILE}
FILE=${MANIFESTS}/app.yml
./show "$@" --module app --omit-component app.dbmigrate > ${FILE}
FILE=${MANIFESTS}/traefik.yml
./show "$@" --module traefik --omit-component traefik.certWildcard > ${FILE}
FILE=${MANIFESTS}/spinnaker.yml
./show "$@" --module spinnaker --omit-component spinnaker.certWildcard > ${FILE}
#!/usr/bin/env bash
# -V commit=7d1ceee0ce2b8735c70acded97ce40356d019b3d -V appVersion=0.0.1
./show.js $1 -V project=$1 "${@:2}"
#!/usr/bin/env node
// https://github.com/ksonnet/ksonnet/issues/882
// wrapper adding --omit-component, --omit-module, --module to `ks show`
const util = require('util')
const exec = util.promisify(require('child_process').exec)
const args = process.argv.slice(2)
const omitComponentArgsIndexes = []
const omitModuleArgsIndexes = []
const moduleArgsIndexes = []
const propagateArgs = []
const options = {
omitComponent: [],
omitModule: [],
module: [],
}
function debug(...args) {
// console.log(...args)
}
args.forEach((val, index, array) => {
// debug(index + ': ' + val)
if (val === '--omit-component') {
omitComponentArgsIndexes.push(index)
} else if (omitComponentArgsIndexes.includes(index - 1)) {
options.omitComponent.push(val)
} else if (val === '--omit-module') {
omitModuleArgsIndexes.push(index)
} else if (omitModuleArgsIndexes.includes(index - 1)) {
options.omitModule.push(val)
} else if (val === '--module') {
moduleArgsIndexes.push(index)
} else if (moduleArgsIndexes.includes(index - 1)) {
options.module.push(val)
} else {
propagateArgs.push(val)
}
})
async function createComponentArgLine() {
const { stdout, stderr } = await exec('ks component list --output json')
debug(options)
// debug('stdout:', stdout)
// debug('stderr:', stderr)
const parsed = JSON.parse(stdout)
// debug(JSON.stringify(parsed, null, ' '))
let componentArgs = ''
for (const j of parsed.data) {
const { component } = j
let module
if (component.includes('.')) {
module = component.split('.')[0]
}
// debug(module, component)
if (!options.omitComponent.includes(component)) {
let omit = false
// see if --module is specified
if (options.module.length) {
if (!options.module.includes(module)) {
omit = true
// debug(module, component, 'not included in module[]', options.module)
}
}
// see if match omitModule
if (!omit) {
for (const omitModule of options.omitModule) {
if (module === omitModule) {
omit = true
break
}
}
}
if (!omit) {
console.log('# ', component)
componentArgs += `--component ${component} `
}
}
}
return componentArgs
}
// top level async
;(async () => {
try {
let cmd
if (propagateArgs.includes('--component')) {
// --component means inclusive so skip the omits
cmd = `ks show ${propagateArgs.join(' ')}`
} else {
const componentArgLine = await createComponentArgLine()
cmd = `ks show ${propagateArgs.join(' ')} ${componentArgLine}`
}
debug(cmd)
const { stdout, stderr } = await exec(cmd)
console.log(stdout)
// console.log(stderr)
} catch (e) {
console.error(e)
process.exit(1)
}
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment