Skip to content

Commit

Permalink
Fixed issue with needing to pass 'stateless' in an update operation
Browse files Browse the repository at this point in the history
Abaco does not allow an actor to be updated to be stateless if it was
registered as stateful. But, the update operation currently requires
that the correct and current value for 'stateless' to be passed even
if no change is requested. We work around this by fetching the
actor's stateless key and simply sending that. In the future we may
permit toggling from stateless to stateful, but that remains to be
determined based on use cases and the Abaco road map."
  • Loading branch information
mwvaughn committed Jul 26, 2019
1 parent e2d19f5 commit 60b94b1
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 53 deletions.
3 changes: 2 additions & 1 deletion abaco-deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,8 @@ if ((verbose)); then
fi

# Prepend directory to allow for multiple concurrent CLI to coexist
ACTOR_ID=$(eval ${DIR}/$cmd | jq -r .result.id)
RESP=$(eval ${DIR}/${cmd})
ACTOR_ID=$(echo ${RESP} | jq -r .result.id)

if [[ "$ACTOR_ID" == "null" ]]; then
die "Failed to deploy actor $REACTOR_NAME"
Expand Down
110 changes: 58 additions & 52 deletions abaco-update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,119 +7,125 @@ THIS=${THIS//[-]/ }
HELP="
Usage: ${THIS} [OPTION]... [ACTORID] [IMAGE]
Updates an actor. State status and actor name
Updates an actor. State status and actor name
cannot be changed. Actor ID and Docker image
required.
Options:
-h show help message
-z api access token
-e set environment variables (key=value)
-E read environment variables from json file
-E read environment variables from json file
-p add privileged status
-f force update
-s make stateless actor
-u use actor uid
-v verbose output
-V very verbose output
"

# function usage() { echo "$0 usage:" && grep " .)\ #" $0; exit 0; }
function usage() { echo "$HELP"; exit 0; }
function usage() {
echo "$HELP"
exit 0
}

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

source "$DIR/abaco-common.sh"

privileged="false"
stateless="false"
stateless="true"
force="false"
use_uid="false"
tok=

while getopts ":he:E:pfsuvz:V" o; do
# the s and S opts are here to swallow them when passed - we do not allow
# toggling between stateless and stateful via an update operation
while getopts ":he:E:pfsSuvz:V" o; do
case "${o}" in
z) # custom token
tok=${OPTARG}
;;
e) # default environment (command line key=value)
env_args[${#env_args[@]}]=${OPTARG}
;;
E) # default environment (json file)
env_json=${OPTARG}
;;
p) # privileged
privileged=true
;;
f) # force
force=true
;;
s) # stateless
stateless="true"
;;
u) # use uid
use_uid=true
;;
v) # verbose
verbose="true"
;;
V) # verbose
very_verbose="true"
;;
h | *) # print help text
usage
;;
z) # custom token
tok=${OPTARG}
;;
e) # default environment (command line key=value)
env_args[${#env_args[@]}]=${OPTARG}
;;
E) # default environment (json file)
env_json=${OPTARG}
;;
p) # privileged
privileged=true
;;
f) # force
force=true
;;
s) # stateless
stateless="true"
;;
S) # stateful!
stateless="false"
;;
u) # use uid
use_uid=true
;;
v) # verbose
verbose="true"
;;
V) # verbose
very_verbose="true"
;;
h | *) # print help text
usage
;;
esac
done
shift $((OPTIND-1))
shift $((OPTIND - 1))
actorid="$1"
image="$2"

if [ ! -z "$tok" ]; then TOKEN=$tok; fi
if [[ "$very_verbose" == "true" ]]
then
if [[ "$very_verbose" == "true" ]]; then
verbose="true"
fi

# fail if no actorid or image
if [ -z "$actorid" ] || [ -z "$image" ]
then
if [ -z "$actorid" ] || [ -z "$image" ]; then
echo "Please specify an actor ID and a Docker image"
usage
fi

# default env
# check env vars json file (exists, have contents, be json)
file_default_env=
if [ ! -z "$env_json" ]
then
if [ ! -f "$env_json" ] || [ ! -s "$env_json" ] || ! $(is_json $(cat $env_json))
then
if [ ! -z "$env_json" ]; then
if [ ! -f "$env_json" ] || [ ! -s "$env_json" ] || ! $(is_json $(cat $env_json)); then
die "$env_json is not valid. Please ensure it exists and contains valid JSON."
fi
file_default_env=$(cat $env_json)
fi
# build command line env vars into json
args_default_env=$(build_json_from_array "${env_args[@]}")
#combine both
#combine both
default_env=$(echo "$file_default_env $args_default_env" | jq -s add)

# WORKAROUND - fetch stateless from actor records.
# TODO - File Issue: Stateless should not be mandatory for an update operation
stateless=$(${DIR}/abaco ls -v ${actorid} | jq -r .result.stateless)

# curl command
# \"stateless\":\"${stateless}\",
data="{\"stateless\":\"${stateless}\", \"image\":\"${image}\", \"privileged\":${privileged}, \"force\":${force}, \"useContainerUid\":${use_uid}, \"defaultEnvironment\":${default_env}}"
curlCommand="curl -X PUT -sk -H \"Authorization: Bearer $TOKEN\" -H \"Content-Type: application/json\" --data '$data' '$BASE_URL/actors/v2/${actorid}'"

function filter() {
# eval $@ | jq -r '.result | [.name, .id] | @tsv' | column -t
# eval $@ | jq -r '.result | [.name, .id] | @tsv' | column -t
eval $@ | jq -r '.result | [.name, .id] | "\(.[0]) \(.[1])"' | column -t
}

if [[ "$very_verbose" == "true" ]]
then
if [[ "$very_verbose" == "true" ]]; then
echo "Calling $curlCommand"
fi

if [[ "$verbose" == "true" ]]
then
if [[ "$verbose" == "true" ]]; then
eval $curlCommand
else
filter $curlCommand
Expand Down

0 comments on commit 60b94b1

Please sign in to comment.