-
Notifications
You must be signed in to change notification settings - Fork 126
/
run
executable file
·63 lines (50 loc) · 2.23 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
#!/usr/bin/env bash
# required tools
# docker
# ibmcloud CLI with latest version of ce,is
# required env vars:
# IBMCLOUD_API_KEY: API KEY which is allowed to create VSIs in your own VPC.
# optional env vars:
# REGISTRY: name of the image registry/namespace to get the container images from, will default to icr.io/codeengine
# PROJECT: name of the project to run the sample within
# REGION your VPC is in (needs to match region in config; icr region can be different)
set -e
if [ -z "$IBMCLOUD_API_KEY" ]; then
echo "env variable IBMCLOUD_API_KEY is not set"
exit 1
fi
export REGISTRY=${REGISTRY:-icr.io/codeengine}
export PROJECT=${PROJECT:-demos}
export RESOURCEGROUP=${RESOURCEGROUP:-default}
export PREFIX=${PREFIX:-job2vsi}
export REGION=${REGION:-ca-tor}
ibmcloud login --apikey ${IBMCLOUD_API_KEY} -g ${RESOURCEGROUP} -r ${REGION}
# select an existing project, or create if not exists
set +e
ibmcloud ce project select --name ${PROJECT}
if [ $? != "0" ]; then
ibmcloud ce project create --name ${PROJECT}
fi
set -e
if [ "$1" == "clean" ]; then
ibmcloud ce secret delete --name ${PREFIX}-api-key -f -inf
ibmcloud ce cm delete -n ${PREFIX}-vsi-config -f -inf
ibmcloud ce job delete -n ${PREFIX}-job -f -inf
ibmcloud ce jr delete -n ${PREFIX}-job-run -f -inf
exit 0
fi
# create a secret in the project which contains the API KEY to access the VPC
ibmcloud ce secret delete --name ${PREFIX}-api-key -f -inf
ibmcloud ce secret create --name ${PREFIX}-api-key --from-literal IBMCLOUD_API_KEY="${IBMCLOUD_API_KEY}"
# create a config map which contains the config.yml
ibmcloud ce cm delete -n ${PREFIX}-vsi-config -f -inf
ibmcloud ce cm create -n ${PREFIX}-vsi-config --from-file vsi-proxy-config.yaml=config.yaml
# create a job which uses the secret, config and configured image
ibmcloud ce job delete -n ${PREFIX}-job -f -inf
ibmcloud ce job create -n ${PREFIX}-job -i ${REGISTRY}/job2vsi --env-from-secret ${PREFIX}-api-key \
--mount-configmap /etc/vsi-proxy/config/=${PREFIX}-vsi-config
# createa job run; modify "--ai 1" if you want multiple
ibmcloud ce jr delete -n ${PREFIX}-job-run -f -inf
ibmcloud ce jr submit --ai 1 -job ${PREFIX}-job -n ${PREFIX}-job-run
# watch what the jobrun is doing
ibmcloud ce jr logs -n ${PREFIX}-job-run -f