diff --git a/ide/docopts.md b/ide/docopts.md index fd1b68f..43a0cc0 100644 --- a/ide/docopts.md +++ b/ide/docopts.md @@ -24,9 +24,9 @@ OpenServerless Ide Development Utilities. ```text Usage: - ide login [] [] + ide login [] [] [--local] [--pin] ide devel [--fast] [--dry-run] - ide deploy [] [--dry-run] + ide deploy [|--packages|--web] [--dry-run] ide undeploy [] [--dry-run] ide clean ide setup @@ -60,6 +60,30 @@ Usage: ## Options ``` ---fast Skip the initial deployment step and go in incremental update mode --dry-run Simulates the execution without making any actual changes +--packages Only deploy packages, skip web upload +--web Only deploy web folder, skip packages +--pin Save the current key in .env as AUTH_CHECK to verify deployments use that key +--local Save the login as a local .wskprops instead of a global one +--fast Skip the initial deployment step and go in incremental update mode ``` + +## Login + +If you login with `ops ide login` it will read the .env and +login using env vars `OPS_USERNAME` `OPS_PASSWORD` `OPS_APIHOST` + +If you login with `ops ide login ` it will use, if not empty in preference: + +`OPS__USERNAME` `OPS__PASSWORD` `OPS__APIHOST` + +By default the credentials are stored in ~/.wskprops. +If there is a local `.wskprops` in current directory it will used that instead. + +If you specify `--local` or the variable `OPS_LOCAL` or ops `OPS__LOCAL` is not empty, +credentials are stored in the local file. +Also if you login and there is already a local file will be used the local instead of the global. + +If you specify `--pin`, or the variable `OPS_PIN` or `OPS__PIN`, +an `AUTH_CHECK` variable will be added to your `.env` to verify deployments +use the same configurations of the login and not another by mistake. \ No newline at end of file diff --git a/ide/opsfile.yml b/ide/opsfile.yml index d518cad..dfbbe3a 100644 --- a/ide/opsfile.yml +++ b/ide/opsfile.yml @@ -36,7 +36,15 @@ vars: then cat "$OPS_ROOT/ide/deploy/hash.lock" else echo "0" fi - + +env: + WSK_CONFIG_FILE: + sh: | + if test -e "$OPS_PWD/..wskprops" + then echo "$OPS_PWD/.wskprops" + else echo ~/.wskprops + fi + tasks: prereq: @@ -148,9 +156,35 @@ tasks: if test -e "$OPS_PWD/.env" then source "$OPS_PWD/.env" fi + + IS_LOCAL=$(if {{.__local}}; then echo "1" ; else echo "" ; fi) + IS_PIN=$(if {{.__pin}} ; then echo "1" ; else echo "" ; fi) + IS_LOCAL="$IS_LOCAL$OPS_LOCAL" + IS_PIN="$IS_PIN$OPS_PIN" + + # load user variables if any + if [ -n "{{._username_}}" ] + then + if [ -n "$OPS_{{._username_}}_USERNAME"] + then OPS_USERNAME="$OPS_{{._username_}}_USERNAME" + echo Using username from $OPS_{{._username_}}_USERNAME for login + fi + if [ -n "$OPS_{{._username_}}_APIHOST"] + then OPS_APIHOST="$OPS_{{._username_}}_APIHOST" + echo Using apihost from $OPS_{{._username_}}_APIHOST for login + fi + if [ -n "$OPS_{{._username_}}_PASSWORD"] + then OPS_PASSWORD="$OPS_{{._username_}}_PASSWORD" + echo Using password from $OPS_{{._username_}}_PASSWORD for login + fi + IS_LOCAL="$IS_LOCAL$OPS_{{._username_}}_LOCAL" + IS_PIN="$IS_PIN$OPS_{{._username_}}_PIN" + fi + if test -n "{{._apihost_}}" then OPSDEV_APIHOST="{{._apihost_}}" fi + echo "*** Configuring Access to OpenServerless ***" if test -z "{{._apihost_}}" then @@ -180,6 +214,16 @@ tasks: if test -n "$OPS_PASSWORD" then export "OPS_PASSWORD" fi + + if test -n "$IS_LOCAL" + then export WSK_CONFIG_FILE="$OPS_PWD/.wskprops" + fi + + if test -n "$WSK_CONFIG_FILE" + then echo Using local credentials: "$WSK_CONFIG_FILE" + else echo Using global credentials: "$WSK_CONFIG_FILE", use `--local` for local + fi + if $OPS -login "$OPSDEV_APIHOST" "$OPSDEV_USERNAME" then OPSDEV_HOST_PROT="$(echo "$OPSDEV_APIHOST" | awk -F '://' '{print $1}')" @@ -187,12 +231,19 @@ tasks: config OPSDEV_APIHOST="$OPSDEV_APIHOST" config OPSDEV_USERNAME="$OPSDEV_USERNAME" config OPSDEV_HOST="$OPSDEV_HOST_PROT://$OPSDEV_USERNAME.$OPSDEV_HOST_URL" - source ~/.wskprops + source "$WSK_CONFIG_FILE" + if test -n "$IS_PIN" + then + echo "Pinning credentials to avoid deployment mistakes" + if rg .env "^AUTH_CHECK=" + then awk -v v="$AUTH" 'BEGIN{FS=OFS="="} /^AUTH_CHECK=/{ $2=v }1' .env > .env.tmp$$ && mv .env.tmp$$ .env + echo "Note: replaced existing pinned credentials" + else echo "$UTH_CHECK=$AUTH" >>.env + fi + fi else false fi - - poll: silent: true @@ -218,6 +269,9 @@ tasks: - task: prereq - | set -a + if test -e "$OPS_PWD/.wskprops" + then export WSK_CONFIG_FILE="$OPS_PWD/.wskprops" + fi if test -e $OPS_PWD/.env then source $OPS_PWD/.env fi @@ -226,22 +280,40 @@ tasks: fi if test -n "$AUTH_CHECK" then if test "$AUTH_CHECK" != "$AUTH" - then echo "WARNING: wrong deploy! You are logged in a different user than your configured AUTH_CHECK" ; exit 1 + then echo "WARNING: wrong deploy! You are logged in a different user than your pinned one and configured in .env as AUTH_CHECK" ; exit 1 fi fi + if {{.__dry_run}} then DRY="--dry-run" ; ECHO='echo' else DRY="" ; ECHO="" fi - if test -z "{{._action_}}" - then - bun {{.TASKFILE_DIR}}/deploy/index.js "$OPS_PWD" -d $DRY - OPS_UPLOAD_FOLDER=`bun {{.TASKFILE_DIR}}/deploy/info.js upload web` - echo "UPLOAD ASSETS FROM ${OPS_UPLOAD_FOLDER}" - $ECHO $OPS util upload ${OPS_UPLOAD_FOLDER:-web} - echo "URL: $OPSDEV_HOST" + + if {{.__web}} + then deploy_packages="" + else deploy_packages="1" + fi + + if {{.__packages}} + then deploy_web="" + else deploy_web="1" + fi + + if test -n "{{._action_}}" + then + bun {{.TASKFILE_DIR}}/deploy/index.js "$OPS_PWD" -s "{{._action_}}" $DRY else - bun {{.TASKFILE_DIR}}/deploy/index.js "$OPS_PWD" -s "{{._action_}}" $DRY + if [ -n "$deploy_packages"] + then + bun {{.TASKFILE_DIR}}/deploy/index.js "$OPS_PWD" -d $DRY + fi + if [-n "$deploy_web"] + then + OPS_UPLOAD_FOLDER=`bun {{.TASKFILE_DIR}}/deploy/info.js upload web` + echo "UPLOAD ASSETS FROM ${OPS_UPLOAD_FOLDER}" + $ECHO $OPS util upload ${OPS_UPLOAD_FOLDER:-web} + echo "URL: $OPSDEV_HOST" + fi fi undeploy: @@ -254,7 +326,6 @@ tasks: then DRY="--dry-run" else DRY="" fi - # Check if an action argument is provided if test -n "{{._action_}}" then @@ -288,7 +359,6 @@ tasks: else die "no packages in current directory" fi - devel: interactive: true silent: true @@ -333,7 +403,6 @@ tasks: bun {{.TASKFILE_DIR}}/deploy/index.js "$OPS_PWD" -w $FAST $DRY true - shell: desc: open a bash shell with the current environment interactive: true diff --git a/util/docopts.md b/util/docopts.md index 3173608..72d1107 100644 --- a/util/docopts.md +++ b/util/docopts.md @@ -24,6 +24,7 @@ OpenServerless Utilities ```text Usage: + util apihost util system util update-cli util check-operator-version @@ -48,6 +49,7 @@ Usage: ## Commands ``` +- apihost current apihost - system system info (- in Go format) - update-cli update the cli downloading the binary - check-operator-version check if you need to update the operator diff --git a/util/opsfile.yml b/util/opsfile.yml index 0358cc0..28e35c7 100644 --- a/util/opsfile.yml +++ b/util/opsfile.yml @@ -47,6 +47,12 @@ tasks: cmds: - echo "{{OS}}-{{ARCH}}" + apihost: + desc: current apihost`` + silent: true + cmds: + - ops -wsk property get | awk '/whisk API host/{print $4}' + update-cli: desc: update CLI silent: true