2
2
3
3
# Env Vars:
4
4
# REPOSITORY: name of the image registry/namespace to get the images
5
- # COS_ID: If set, specifies the full CRN of a Cloud Object Storage instance to use
5
+ # COS_ID: If set, specifies the full CRN of a Cloud Object Storage instance to
6
+ # use
6
7
7
8
export REPOSITORY=${REPOSITORY:- ibmcom}
8
9
export PROJECT_NAME=$( ibmcloud ce project current | \
9
10
awk -F: ' /Project Name/{ print $2 }' )
10
11
export PROJECT_ID=$( ibmcloud ce project get --name ${PROJECT_NAME} | \
11
12
awk ' /^ID/{ print $2 }' )
13
+ export POLICY_ID=" "
12
14
13
15
# Clean up previous run
14
16
function clean() {
15
17
set +x
16
- DCOS=$1
17
- POLICY=$2
18
18
echo " Cleaning..."
19
19
20
20
# Delete the event subscription
21
21
ibmcloud ce sub cos delete -n cos-sub -f --wait=true > /dev/null 2>&1 || true
22
22
23
23
# Delete the IAM auth policy
24
- if [[ $POLICY != " " ]]; then
24
+ if [[ -n " $POLICY_ID " ]]; then
25
25
ibmcloud iam authorization-policy-delete $POLICY --force \
26
26
> /dev/null 2>&1 || true
27
27
fi
@@ -33,45 +33,43 @@ function clean() {
33
33
ibmcloud cos bucket-delete --bucket ${PROJECT_ID} --force \
34
34
> /dev/null 2>&1 || true
35
35
36
- # Delete the COS instance
37
- if [[ $DCOS -gt 0 ]]; then
36
+ # Delete the COS instance unless the instance was given to us
37
+ if [[ -z " $COS_ID " ]]; then
38
38
ibmcloud resource service-instance-delete codeengine-cos -f -q \
39
39
> /dev/null 2>&1 || true
40
40
fi
41
41
42
42
rm -f out
43
43
}
44
44
45
- clean 0
45
+ clean
46
46
[[ " $1 " == " clean" ]] && exit 0
47
47
48
48
set -ex
49
49
50
- # Create a COS instance unless one has been specified for use, mark it for
51
- # deletion
52
- DELETE_COS=0
53
- if [[ $COS_ID == " " ]]; then
50
+ CID= ${COS_ID}
51
+
52
+ # Create a COS instance unless one has been specified for use
53
+ if [[ $CID == " " ]]; then
54
54
ibmcloud resource service-instance-create codeengine-cos \
55
55
cloud-object-storage lite global
56
- COS_ID =$( ibmcloud resource service-instance codeengine-cos | \
56
+ CID =$( ibmcloud resource service-instance codeengine-cos | \
57
57
awk ' /^ID/{ print $2 }' )
58
- DELETE_COS=1
59
58
fi
60
59
61
60
# Set the COS config to use this instance
62
- ibmcloud cos config crn --crn $COS_ID --force
61
+ ibmcloud cos config crn --crn $CID --force
63
62
ibmcloud cos config auth --method IAM
64
63
65
- # Create the IAM authorization policy to allow us to receive notifications
66
- # from COS
64
+ # Create IAM authorization policy so we can receive notifications from COS
67
65
POLICY_ID=$( ibmcloud iam authorization-policy-create codeengine \
68
66
cloud-object-storage " Notifications Manager" \
69
67
--source-service-instance-name ${PROJECT_NAME} \
70
- --target-service-instance-id ${COS_ID } | awk ' /^Authorization/{ print $3 }' )
68
+ --target-service-instance-id ${CID } | awk ' /^Authorization/{ print $3 }' )
71
69
72
70
# Create our bucket
73
71
export BUCKET=${PROJECT_ID}
74
- ibmcloud cos bucket-create --bucket $BUCKET --ibm-service-instance-id $COS_ID
72
+ ibmcloud cos bucket-create --bucket ${ BUCKET} --ibm-service-instance-id $CID
75
73
76
74
# Create the app && save its URL for later
77
75
ibmcloud ce app create -n cos-app --image ${REPOSITORY} /cos-listen \
@@ -107,4 +105,4 @@ echo "Event stats:"
107
105
curl -Ls ${URL} /stats
108
106
109
107
# Clean up
110
- clean $DELETE_COS $POLICY_ID
108
+ clean
0 commit comments