diff --git a/kargo.js b/kargo.js index 744fdfe3d..b7c60f9fc 100644 --- a/kargo.js +++ b/kargo.js @@ -132,16 +132,16 @@ function diffConfig () { return true }*/ -function listEnvironment () { - let variables = [] - _.forEach(_.toPairs(config.environment), variable => { - variables.push({ name: variable[0], value: variable[1]}) +function setEnvironment () { + if (!readStates()) return false + _.forEach(_.toPairs(states.config.environment), variable => { + shell.env[_.toUpper(_.snakeCase(variable[0]))] = variable[1] }) - return variables + return true } function listStacks () { - return _.keys(config.stacks) + return _.keys(states.config.stacks) } function listServices (stack) { @@ -237,7 +237,8 @@ async function apply () { async function deploy (stackOrAll) { debug('[subcommand] deploy') - if (!readConfig()) return + if (!setEnvironment()) return + /*if (writeConfig()) { @@ -251,25 +252,31 @@ async function deploy (stackOrAll) { }*/ } -function exec () { +function exec (script) { debug('[subcommand] exec') - if (readConfig()) { + if (!setEnvironment()) return false + let scriptFile = path.join(runtimeScriptsDir, script) + if (!fs.existsSync(scriptFile)) { + log('The specified script file \'' + script + '\' does not exist', 'error') + return + } + if (shell.exec(scriptFile).code!==0) { + log('An error has occured while executing \'' + script + '\'', 'error') } } function info () { debug('[subcommand] info') - if (readConfig()) { - _.forEach(listStacks(), stack => { - console.log('- %s', stack) - _.forEach(listServices(stack), service => { - console.log(' - %s', service.name) - _.forEach(_.toPairs(service.settings), settings => { - console.log(' - %s: %s', settings[0], settings[1]) - }) + if (!readStates()) return false + _.forEach(listStacks(), stack => { + console.log('- %s', stack) + _.forEach(listServices(stack), service => { + console.log(' - %s', service.name) + _.forEach(_.toPairs(service.settings), settings => { + console.log(' - %s: %s', settings[0], settings[1]) }) }) - } + }) } function plan () { @@ -289,6 +296,7 @@ function pull () { } function use (workspace) { + debug('[subcommand] use') // TODO check states // Check whether the specified path exists if (!fs.existsSync(workspace)) { @@ -314,7 +322,12 @@ function use (workspace) { // Configure the states states = { 'workspace': { 'name': path.basename(workspace), 'path': workspace }, - 'config': { environment: {}, labels: {}, stacks: {} } + 'config': { + environment: { + "kargo-version": require('./package.json').version + }, + labels: {}, + stacks: {} } } // Save the states if (writeStates()) { @@ -345,7 +358,6 @@ program program .command('use ') .action((workspace) => use(workspace)) - - program.parse(process.argv) +program.parse(process.argv) diff --git a/scripts/display-env.sh b/scripts/display-env.sh new file mode 100644 index 000000000..e69de29bb diff --git a/scripts/update-labels.sh b/scripts/update-labels.sh index 0122daa1d..81828cbe2 100755 --- a/scripts/update-labels.sh +++ b/scripts/update-labels.sh @@ -1,42 +1,5 @@ #!/bin/bash -usage() { - echo "usage: update-labels " -} +echo $KARGO_VERSION -help() { - echo "Update the labels of the specified node" - usage -} - -exec() { - local NODE=$1 - local LABELS=$2 - # Retrieve the existing labels - local EXISTING_LABELS=`docker node inspect -f '{{ range $k, $v := .Spec.Labels }}{{ $k }}={{ $v }} {{end}}' $NODE` - # Keep the existing labels if needed - for EXISTING_LABEL in $EXISTING_LABELS; do - if [[ ! $NEW_LABELS =~ $EXISTING_LABEL ]]; then - EXISTING_LABEL_KEY=${EXISTING_LABEL%=*} - docker node update --label-rm $EXISTING_LABEL_KEY $NODE > /dev/null - fi - done - # Add the label of needed - for LABEL in $LABELS; do - if [[ ! $EXISTING_LABELS =~ $LABEL ]]; then - docker node update --label-add $LABEL $NODE > /dev/null - fi - done -} - -if [ "$#" -ne 2 ]; then - echo error: illegal number of arguments - usage - exit 1 -fi - -case $1 in - -h|--help) help;; - *) exec "$1" "$2" -esac