forked from IBM/CodeEngine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun
executable file
·58 lines (44 loc) · 1.76 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
#!/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 ce-bash -f
ibmcloud ce secret delete -n bash-keys -f
ibmcloud iam api-keys | grep bash | sed "s/.*\(ApiKey\)/\1/" | while read a
do ibmcloud iam api-key-delete -f $a
done
rm -f out .apikey
) > /dev/null 2>&1
}
clean
[[ "$1" == "clean" ]] && exit 0
export REGISTRY=${REGISTRY:-icr.io/codeengine}
set -ex
# Create an API Key so that our App can use it to talk to Code Engine
ibmcloud iam api-key-create -q bash | awk '/API Key/{ print $3 }' > .apikey
# Create a 'secret' to hold our API Key, Project, Resource Group and Region
ibmcloud ce secret create -n bash-keys \
--from-file APIKEY=.apikey \
--from-literal PROJECT=$(ibmcloud ce proj current|awk '/^Name:/{print $2}') \
--from-literal GROUP=$(ibmcloud target | awk '/Resource group:/{print $3}') \
--from-literal REGION=$(ibmcloud target | awk '/Region:/{print $2}')
rm .apikey # erase it since we don't need it any more
# Create our application that will invoke:
# - "init" script upon each instance's startup
# - "app" script when an incoming request is received
# Notice we mount our "bash-keys" secret into the app at the "/keys" directory.
# Each name/value pair in the secret appears as a separate file in the dir.
ibmcloud ce app create -n ce-bash --image $REGISTRY/ce-bash \
--mount-secret /keys=bash-keys
# Save App's URL for later
APP=$(ibmcloud ce app get -n ce-bash -o url)
# Call the app - if it works it should return the output of the 'app list' cmd
curl -w "\n%{http_code}\n" -fs $APP/ | tee out
[[ "${PIPESTATUS[0]}" == "0" ]]
# Verify we see our App in the output
grep "^ce-bash.*Ready" out
clean