-
Notifications
You must be signed in to change notification settings - Fork 126
/
run
executable file
·67 lines (53 loc) · 1.63 KB
/
run
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
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash
# Env Vars:
# REGISTRY: name of the image registry/namespace to get the images
# Clean up previous run
function clean() {
set +ex
echo Cleaning...
(
ibmcloud ce app delete -n sec-app-env -f
ibmcloud ce secret delete -n sec-secret-env -f
rm -f out
) > /dev/null 2>&1
}
clean
[[ "$1" == "clean" ]] && exit 0
set -ex
export REGISTRY=${REGISTRY:-icr.io/codeengine}
# Create a Secret with all possible ways of populating the data:
# 1 - literal name/value pair from command line
# 2 - name/value pairs read from a file
# 3 - name/value pair wherer 'value' is the contents of a file (twice)
ibmcloud ce secret create --name sec-secret-env \
--from-literal MY_SECRET_VALUE=42 \
--from-env-file data \
--from-file file \
--from-file MY_FILE=file
# Create the app
ibmcloud ce app create -n sec-app-env --image ${REGISTRY}/ce-secret-env --cpu 0.125 --memory 0.25G \
--env-from-secret sec-secret-env
# Get the URL of the app for later use
URL=$(ibmcloud ce app get -n sec-app-env -o url)
# Just force it to log something by hitting it
curl -fs $URL
# Extract the instance name from `ibmcloud ce app get`
ibmcloud ce app get -n sec-app-env | tee out
name=$(cat out | awk '/sec-app-env.*Running/{ print $1 }')
echo Instance name: $name
clean
exit 0
# Now check the logs to see if the env vars were set
ibmcloud ce app logs --instance $name | tee out
grep MY_ out
if (( $(grep MY_ out | wc -l) != 4 )); then
echo "Unexpected output"
exit 1
fi
# Check to see if the context of "file" are assign to the "file" env var.
if (( $(grep '^file=In Congress' out | wc -l) != 1 )); then
echo "Unexpected output"
exit 1
fi
# Clean up
clean