Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions bin/lesgo-scripts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ INVOKE=0; # serverless invoke of specific function
LOGS=0; # serverless stream log of specific function
DESTROY=0; # serverless remove entire service
FUNCTION=''; # specify function to involve
STAGE=''; # deploy specific stage/environment
ENVFILE=''; # deploy specific stage/environment
INVOKE_LOCAL=0; # default to non local execution
DATA='' # set the data parameters for invoke function
NO_QUESTION=0; # default to prompt
Expand All @@ -37,7 +37,7 @@ CONFIG='./serverless.yml'; # specify serverless config file to deploy, default
while getopts "lhs:f:t:d:c:y" OPT ; do
case ${OPT} in
f) FUNCTION=${OPTARG} ;;
s) STAGE=${OPTARG} ;;
s) ENVFILE=${OPTARG} ;;
t)
if [ ${OPTARG} == "build" ]; then
BUILD=1;
Expand Down Expand Up @@ -68,9 +68,6 @@ while getopts "lhs:f:t:d:c:y" OPT ; do
esac
done

# Set envfile to reference from
ENVFILE=${STAGE}

# Check if local env file exists
FILE=config/environments/.env.${ENVFILE}.local
if [ -f "$FILE" ]; then
Expand Down Expand Up @@ -111,7 +108,7 @@ echo -e "Current Serverless version: ${SERVERLESS_VERSION_NUMBER}\n"

function deploy_func_check ()
{
if [[ ${STAGE} == "production" ]]; then
if [[ ${STAGE} =~ ^prod ]]; then
prompt_confirmation_deploy_function
else
deploy_func
Expand All @@ -135,10 +132,10 @@ function prompt_confirmation_deploy_all ()
deploy_full;
else
while true; do
read -p "Confirm deploy service to ${STAGE} with .env.${ENVFILE} using ${CONFIG}? [Y|N] " yn
read -p "Confirm deploy service ${SERVICE} to ${STAGE} with .env.${ENVFILE} using ${CONFIG}? [Y|N] " yn
case ${yn} in
[Yy] | yes | Yes | YES ) deploy_full; break;;
[Nn] | no | No | NO ) echo -e "${YELLOW}Cancelled deploying service to [${STAGE}]${NC}"; exit;;
[Nn] | no | No | NO ) echo -e "${YELLOW}Cancelled deploying service ${SERVICE} to [${STAGE}]${NC}"; exit;;
* ) echo -e "${PURPLE}Please answer yes or no.${NC}";;
esac
done
Expand All @@ -159,7 +156,7 @@ function prompt_confirmation_deploy_function ()

function deploy_full ()
{
echo -e "${YELLOW}Deploying service to ${STAGE}${NC}"
echo -e "${YELLOW}Deploying service ${SERVICE} to ${STAGE}${NC}"
if [ ${SERVERLESS_VERSION_NUMBER} -ge ${LATEST_SERVERLESS_VERSION_NUMBER} ]; then
sls deploy --stage ${STAGE} --param="env=${ENVFILE}" --config ${CONFIG}
else
Expand Down Expand Up @@ -209,18 +206,18 @@ function build ()
function prompt_confirmation_destroy_service ()
{
while true; do
read -p "Confirm destroy service to ${STAGE} with .env.${ENVFILE} using ${CONFIG}? Note: This action will remove entire service from AWS. Ensure no other applications are using this service. [Y|N] " yn
read -p "Confirm destroy service ${SERVICE} to ${STAGE} with .env.${ENVFILE} using ${CONFIG}? Note: This action will remove entire service from AWS. Ensure no other applications are using this service. [Y|N] " yn
case ${yn} in
[Yy] | yes | Yes | YES ) destroy_service; break;;
[Nn] | no | No | NO ) echo -e "${YELLOW}Cancelled destroying service to [${STAGE}]${NC}"; exit;;
[Nn] | no | No | NO ) echo -e "${YELLOW}Cancelled destroying service ${SERVICE} to [${STAGE}]${NC}"; exit;;
* ) echo -e "${PURPLE}Please answer yes or no.${NC}";;
esac
done
}

function destroy_service ()
{
echo -e "${YELLOW}Removing service to ${STAGE}${NC}"
echo -e "${YELLOW}Removing service ${SERVICE} to ${STAGE}${NC}"
if [ ${SERVERLESS_VERSION_NUMBER} -ge ${LATEST_SERVERLESS_VERSION_NUMBER} ]; then
sls remove --stage ${STAGE} --param="env=${ENVFILE}" --config ${CONFIG}
else
Expand All @@ -234,9 +231,14 @@ function destroy_service ()
# #
###############################################################################

# Load env
export $(cat ./config/environments/.env.${ENVFILE} | sed 's/#.*//g' | xargs)

# Derive stage from envfile
STAGE=$APP_ENV
SERVICE=$APP_NAME

if [ -n "$STAGE" ]; then
# Load env
export $(cat ./config/environments/.env.${ENVFILE} | sed 's/#.*//g' | xargs)

if [ ${INVOKE} -eq 1 ]; then
if [ -n "$FUNCTION" ]; then
Expand Down Expand Up @@ -275,4 +277,4 @@ fi
# #
# ALL DONE #
# #
###############################################################################
###############################################################################
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,15 @@ describe('deleteRedisCache', () => {
expect(mockClient.del).toHaveBeenCalledWith(key);

expect(logger.debug).toHaveBeenCalledWith(
'lesgo.services.ElastiCacheRedis.deleteRedisCache::RECEIVED_RESPONSE',
{ resp: 1, keys: input }
'lesgo.services.ElastiCacheRedis.deleteRedisCache::CACHE_KEY_DELETED',
{ key: 'testKey', resp: 1 }
);
expect(logger.debug).toHaveBeenCalledWith(
'lesgo.services.ElastiCacheRedis.deleteRedisCache::ALL_KEYS_DELETED',
{ keys: input }
);

expect(result).toEqual(1);
expect(result).toBeUndefined();
});

it('should throw an exception when client.del fails', async () => {
Expand Down