From 0bb0c2807d7e6c1a8ace2208479fc25abde0e8d4 Mon Sep 17 00:00:00 2001 From: Akash-Nayak Date: Fri, 9 Sep 2022 15:09:10 +0530 Subject: [PATCH] fix: Update the CF deployment script to use original services name. Fix services starting timeout issue (#189) Signed-off-by: Akash Nayak --- .../enterprise-app/src/customers/manifest.yml | 3 +- samples/enterprise-app/src/deploy-to-cf.sh | 65 ++++++++++++++----- .../enterprise-app/src/frontend/manifest.yml | 6 +- .../enterprise-app/src/gateway/manifest.yml | 6 +- .../enterprise-app/src/inventory/manifest.yml | 3 +- .../enterprise-app/src/orders/manifest.yml | 3 +- 6 files changed, 58 insertions(+), 28 deletions(-) diff --git a/samples/enterprise-app/src/customers/manifest.yml b/samples/enterprise-app/src/customers/manifest.yml index b9f4534..902bf10 100644 --- a/samples/enterprise-app/src/customers/manifest.yml +++ b/samples/enterprise-app/src/customers/manifest.yml @@ -3,5 +3,6 @@ applications: - name: customers memory: 1G instances: 1 - buildpack: https://github.com/cloudfoundry/java-buildpack + buildpacks: + - https://github.com/cloudfoundry/java-buildpack path: target/ROOT.war diff --git a/samples/enterprise-app/src/deploy-to-cf.sh b/samples/enterprise-app/src/deploy-to-cf.sh index b29e6f5..292b013 100755 --- a/samples/enterprise-app/src/deploy-to-cf.sh +++ b/samples/enterprise-app/src/deploy-to-cf.sh @@ -1,8 +1,5 @@ #!/usr/bin/env bash # This script deploys the services of the enterprise-app to Cloud Foundry. -# Login to Cloud Foundry before running this script or uncomment the command below and run the script. -# cf login -# cf login --sso if [[ "$(basename "$PWD")" != 'src' ]] ; then echo 'Please run this script from the "src" directory' @@ -11,12 +8,41 @@ fi CF_CLI_TOOL="${CF_CLI_TOOL:-cf}" +echo "Note: This script requires you to be logged in to your Cloud Foundry account." +if [ "$CF_CLI_TOOL" == "cf" ]; then + echo "Hint: cf login (or cf login --sso)" +elif [ "$CF_CLI_TOOL" == "ibmcloud cf" ]; then + echo "Hint: ibmcloud login (or ibmcloud login --sso); ibmcloud target --cf -g " +fi + +echo -e "\nAll the previously deployed services (customers/inventory/orders/gateway/frontend) of the enterprise-app existing on Cloud Foundry will be deleted." +echo "Do you want to proceed? (Y/N)" +read user_input +if [ "$user_input" = "n" ] || [ "$user_input" = "N" ] || [ "$user_input" = "no" ] || [ "$user_input" = "NO" ] || [ "$user_input" = "No" ]; then + echo "Exiting ..." + exit 0 +elif [ "$user_input" = "y" ] || [ "$user_input" = "Y" ] || [ "$user_input" = "yes" ] || [ "$user_input" = "YES" ] || [ "$user_input" = "Yes" ]; then + echo "Deleting the previously deployed services (customers/inventory/orders/gateway/frontend)." +else + echo "Invalid input. Exiting ..." + exit 0 +fi + +$CF_CLI_TOOL delete customers -f +$CF_CLI_TOOL delete inventory -f +$CF_CLI_TOOL delete orders -f +$CF_CLI_TOOL delete gateway -f +$CF_CLI_TOOL delete frontend -f + working_dir="$PWD" echo "$RANDOM$RANDOM" > /dev/null # In zsh, to clear the cached $RANDOM$RANDOM value rand1="$RANDOM$RANDOM" app='enterprise-app' appname="$app-$rand1" -echo "appname is: $appname" +echo -e "\nappname is: $appname" + +export CF_STAGING_TIMEOUT=40 +export CF_STARTUP_TIMEOUT=40 trap "trap_ctrl_c" INT @@ -30,7 +56,7 @@ echo "========== Deploying Customers service to Cloud Foundry ===============" echo "=======================================================================" cd "$working_dir"/customers || exit SPRING_PROFILES_ACTIVE=dev-inmemorydb ./mvnw clean package -P dev-inmemorydb -$CF_CLI_TOOL push "$appname"-customers +$CF_CLI_TOOL push -t 180 --hostname "$appname"-customers rm -rf target echo -e "\n\n=======================================================================" @@ -38,7 +64,7 @@ echo "========== Deploying Inventory service to Cloud Foundry ===============" echo "=======================================================================" cd "$working_dir"/inventory || exit SPRING_PROFILES_ACTIVE=dev-inmemorydb ./mvnw clean package -P dev-inmemorydb -$CF_CLI_TOOL push "$appname"-inventory +$CF_CLI_TOOL push -t 180 --hostname "$appname"-inventory rm -rf target echo -e "\n\n=======================================================================" @@ -46,7 +72,7 @@ echo "========== Deploying Orders service to Cloud Foundry ==================" echo "=======================================================================" cd "$working_dir"/orders || exit SPRING_PROFILES_ACTIVE=dev-inmemorydb ./mvnw clean package -P dev-inmemorydb -$CF_CLI_TOOL push "$appname"-orders +$CF_CLI_TOOL push -t 180 --hostname "$appname"-orders rm -rf target echo -e "\n\n=======================================================================" @@ -54,10 +80,12 @@ echo "========== Deploying Gateway service to Cloud Foundry =================" echo "=======================================================================" cd "$working_dir"/gateway || exit SPRING_PROFILES_ACTIVE=dev ./mvnw clean package -P dev -$CF_CLI_TOOL push "$appname"-gateway \ - --var ENTERPRISE_APP_CUSTOMERS_URL="http://$appname-customers.mybluemix.net/customers" \ - --var ENTERPRISE_APP_INVENTORY_URL="http://$appname-inventory.mybluemix.net/products" \ - --var ENTERPRISE_APP_ORDERS_URL="http://$appname-orders.mybluemix.net/orders" +$CF_CLI_TOOL push --no-start -t 180 --hostname "$appname"-gateway +$CF_CLI_TOOL set-env gateway ENTERPRISE_APP_CUSTOMERS_URL "http://$appname-customers.mybluemix.net/customers" +$CF_CLI_TOOL set-env gateway ENTERPRISE_APP_INVENTORY_URL "http://$appname-inventory.mybluemix.net/products" +$CF_CLI_TOOL set-env gateway ENTERPRISE_APP_ORDERS_URL "http://$appname-orders.mybluemix.net/orders" +$CF_CLI_TOOL start gateway + cd "$working_dir"/gateway || exit # If the user presses ctrl-c during previous step it will take to the $working_dir rm -rf target @@ -65,7 +93,10 @@ echo -e "\n\n=================================================================== echo "========== Deploying Frontend service to Cloud Foundry ================" echo "=======================================================================" cd "$working_dir"/frontend || exit -$CF_CLI_TOOL push "$appname"-frontend --var ENTERPRISE_APP_GATEWAY_URL="http://$appname-gateway.mybluemix.net" +$CF_CLI_TOOL push --no-start -t 180 --hostname "$appname"-frontend +$CF_CLI_TOOL set-env frontend ENTERPRISE_APP_GATEWAY_URL "http://$appname-gateway.mybluemix.net" +$CF_CLI_TOOL start frontend + cd "$working_dir" || exit echo -e "\n\n=======================================================================" @@ -74,21 +105,21 @@ echo -e "\nYour appname is '$appname'" echo "You can use the appname to connect to the different components of the enterprise-app individually and test them." echo -e "\n\n=========== Testing the Cloud Foundry deployments of the enterprise-app services ===========" -echo -e "\n$appname-inventory:" +echo -e "\ninventory:" echo "curl http://$appname-inventory.mybluemix.net/products" -echo -e "\n$appname-customers:" +echo -e "\ncustomers:" echo "curl http://$appname-customers.mybluemix.net/customers" -echo -e "\n$appname-orders:" +echo -e "\norders:" echo "curl http://$appname-orders.mybluemix.net/orders" -echo -e "\n$appname-gateway:" +echo -e "\ngateway:" echo "curl http://$appname-gateway.mybluemix.net/customers" echo "curl http://$appname-gateway.mybluemix.net/orders" echo "curl http://$appname-gateway.mybluemix.net/products" -echo -e "\n$appname-frontend:\nVisit http://$appname-frontend.mybluemix.net URL on your browser. Please refresh the page if it appears blank." +echo -e "\nfrontend:\nVisit http://$appname-frontend.mybluemix.net URL on your browser. Please refresh the page if it appears blank." echo -e "\n\n=======================================================================" echo "=======================================================================" diff --git a/samples/enterprise-app/src/frontend/manifest.yml b/samples/enterprise-app/src/frontend/manifest.yml index b2ee02d..ed14b4a 100644 --- a/samples/enterprise-app/src/frontend/manifest.yml +++ b/samples/enterprise-app/src/frontend/manifest.yml @@ -2,9 +2,7 @@ applications: - name: frontend memory: 2G - buildpack: https://github.com/cloudfoundry/nodejs-buildpack + buildpacks: + - https://github.com/cloudfoundry/nodejs-buildpack command: npm run start instances: 1 - env: - CF_STAGING_TIMEOUT: 30 - ENTERPRISE_APP_GATEWAY_URL: ((ENTERPRISE_APP_GATEWAY_URL)) diff --git a/samples/enterprise-app/src/gateway/manifest.yml b/samples/enterprise-app/src/gateway/manifest.yml index 5305457..c6aceab 100644 --- a/samples/enterprise-app/src/gateway/manifest.yml +++ b/samples/enterprise-app/src/gateway/manifest.yml @@ -3,11 +3,9 @@ applications: - name: gateway memory: 1G instances: 1 - buildpack: https://github.com/cloudfoundry/java-buildpack + buildpacks: + - https://github.com/cloudfoundry/java-buildpack path: target/gateway-2.0.0-SNAPSHOT.jar env: SPRING_PROFILES_ACTIVE: dev JBP_CONFIG_SPRING_AUTO_RECONFIGURATION: '{ enabled: false }' - ENTERPRISE_APP_CUSTOMERS_URL: ((ENTERPRISE_APP_CUSTOMERS_URL)) - ENTERPRISE_APP_INVENTORY_URL: ((ENTERPRISE_APP_INVENTORY_URL)) - ENTERPRISE_APP_ORDERS_URL: ((ENTERPRISE_APP_ORDERS_URL)) diff --git a/samples/enterprise-app/src/inventory/manifest.yml b/samples/enterprise-app/src/inventory/manifest.yml index d8ec21a..f7904c5 100644 --- a/samples/enterprise-app/src/inventory/manifest.yml +++ b/samples/enterprise-app/src/inventory/manifest.yml @@ -3,5 +3,6 @@ applications: - name: inventory memory: 1G instances: 1 - buildpack: https://github.com/cloudfoundry/java-buildpack + buildpacks: + - https://github.com/cloudfoundry/java-buildpack path: target/inventory-0.0.1-SNAPSHOT.jar diff --git a/samples/enterprise-app/src/orders/manifest.yml b/samples/enterprise-app/src/orders/manifest.yml index 5f5d8f3..95c80c1 100644 --- a/samples/enterprise-app/src/orders/manifest.yml +++ b/samples/enterprise-app/src/orders/manifest.yml @@ -3,5 +3,6 @@ applications: - name: orders memory: 1G instances: 1 - buildpack: https://github.com/cloudfoundry/java-buildpack + buildpacks: + - https://github.com/cloudfoundry/java-buildpack path: target/orders-2.0.0-SNAPSHOT.jar