This repository has been archived by the owner on May 30, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
/
deploy.sh
55 lines (41 loc) · 1.58 KB
/
deploy.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/bash
if [ -z "$1" ]
then
echo "No unique string provided across region in IBM Cloud"
exit 1
fi
UNIQUE_IDENTIFIER="${1}"
###################
# Deployment Code
###################
bx api <API_ENDPOINT>
# i.e.:
# for us-south: https://api.ng.bluemix.net
# for europe: https://api.eu-gb.bluemix.net
bx login -u <YOUR_USERNAME> -p <YOUR_PASSWORD>
bx target -o <YOUR_ORG_NAME> -s <YOUR_SPACE_NAME>
bx cf create-service iotf-service iotf-service-free <YOUR_IOT_PLATFORM_SERVICE_NAME>
bx cf create-service cloudantNoSQLDB Lite <YOUR_CLOUDANT_SERVICE_NAME>
bx cf create-service-key <YOUR_CLOUDANT_SERVICE_NAME> <YOUR_APP_NAME>
CLOUDANT_CREDENTIALS=`bx cf service-key <YOUR_CLOUDANT_SERVICE_NAME> <YOUR_APP_NAME> | tail -n +5`
export CLOUDANT_USERNAME=`echo $CLOUDANT_CREDENTIALS | jq -r .username`
export CLOUDANT_PASSWORD=`echo $CLOUDANT_CREDENTIALS | jq -r .password`
export CLOUDANT_HOST=`echo $CLOUDANT_CREDENTIALS | jq -r .host`
if [ -z "$CLOUDANT_DB" ]; then
echo 'CLOUDANT_DB was not set in the pipeline. Using default value.'
export CLOUDANT_DB=<YOUR_CLOUDANT_SERVICE_NAME>-${UNIQUE_IDENTIFIER}
fi
echo 'Creating '$CLOUDANT_db' database...'
curl -s -X PUT "https://$CLOUDANT_USERNAME:$CLOUDANT_PASSWORD@$CLOUDANT_HOST/$CLOUDANT_DB"
bx cf push <YOUR_APP_NAME> --no-start
RUN_RESULT=$?
bx cf bind-service <YOUR_APP_NAME> <YOUR_IOT_PLATFORM_SERVICE_NAME>
bx cf restage <YOUR_APP_NAME>
bx cf start <YOUR_APP_NAME>
RUN_RESULT=$?
if [ ${RUN_RESULT} -ne 0 ]; then
echo "Service failed to start successfully. Check logs."
bx cf logs <YOUR_APP_NAME> --recent
exit 1
fi
bx cf apps