-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun
61 lines (49 loc) · 1.85 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
#!/bin/bash
# Define our ICR Namespace env var for later use
ID=$(ibmcloud ce project current | sed -n "s/^Subdomain: *\([^ ]*\).*$/\1/p")
ICR_NS=s2i-d-${ID:0:12}
# Clean up previous run
function clean() {
set +ex
echo Cleaning...
(
ibmcloud cr namespace-rm "${ICR_NS}" -f
ibmcloud ce app delete -n s2i-dockerfile -f
ibmcloud ce registry delete -n s2i-dicr -f
ibmcloud ce buildrun delete -n s2i-drun -f
ibmcloud ce build delete -n s2i-dbuild -f
ibmcloud iam api-keys | grep s2i-dapi | sed "s/.*\(ApiKey\)/\1/" | while read a
do
ibmcloud iam api-key-delete -f $a
done
rm -f out .ce-reg-secret || true
) > /dev/null 2>&1
}
clean
[[ "$1" == "clean" ]] && exit 0
# Grab the ICR server location based no our region
export ICR=$(ibmcloud cr info | sed -n 's/.*Registry *\(.*icr.io\).*/\1/p')
set -ex
# Create an ICR namespace to hold our new image
ibmcloud cr namespace-add $ICR_NS
# Create an apikey, put it in a registry secret. Used to push/pull image to ICR
ibmcloud iam api-key-create s2i-dapi | \
grep "API Key" | sed 's/^.*Key *//' | sed "s/ *$//" > .ce-reg-secret
ibmcloud ce registry create -n s2i-dicr -s $ICR -u iamapikey \
--password-from-file .ce-reg-secret
# Define the build of this dir in this github repo
ibmcloud ce build create -n s2i-dbuild -i "$ICR/${ICR_NS}/app" --rs s2i-dicr \
--source https://github.com/shancs09/wxcontactcenter --context-dir s2i-dockerfile
# Now kick off the build itself
ibmcloud ce buildrun submit -n s2i-drun --build s2i-dbuild --wait
# Test the image we just built - deploy an app and 'curl' it
ibmcloud ce app create -n s2i-dockerfile --image "$ICR/${ICR_NS}/app" --rs s2i-dicr
URL=$(ibmcloud ce app get -n s2i-dockerfile -o url)
curl -fs "${URL}" | tee out
[[ "${PIPESTATUS[0]}" == "0" ]]
if ! grep "I was built" out > /dev/null ; then
echo "Missing expected outout"
exit 1
fi
# Clean
clean