Skip to content

Commit

Permalink
ic -> ibmcloud
Browse files Browse the repository at this point in the history
Signed-off-by: Doug Davis <[email protected]>
  • Loading branch information
Doug Davis committed Oct 27, 2020
1 parent 5c24be3 commit af5bf38
Show file tree
Hide file tree
Showing 15 changed files with 111 additions and 111 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ It is assumed that the following are installed:
It is also assumed that you have a Code Engine project already created and
selected, e.g.:
```
$ ic ce project create --name demos --select
$ ibmcloud ce project create --name demos --select
```

## Samples
Expand Down
14 changes: 7 additions & 7 deletions app-n-job/run
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
function clean() {
set +x
echo Cleaning...
ic ce app delete -n myapp -f --wto=0 > /dev/null 2>&1 || true
ic ce jobrun delete -n myjob -f > /dev/null 2>&1 || true
ibmcloud ce app delete -n myapp -f --wto=0 > /dev/null 2>&1 || true
ibmcloud ce jobrun delete -n myjob -f > /dev/null 2>&1 || true
rm -f out
}

Expand All @@ -21,10 +21,10 @@ export REPOSITORY=${REPOSITORY:-ibmcom}
export NUM=${NUM:-10}

# First create an app based on our image
ic ce app create -n myapp --image ${REPOSITORY}/app-n-job
ibmcloud ce app create -n myapp --image ${REPOSITORY}/app-n-job

# Get the URL of the app
URL=$(ic ce app get -n myapp -o jsonpath={.status.url})
URL=$(ibmcloud ce app get -n myapp -o jsonpath={.status.url})

# And call it
curl -Ls $URL | tee out
Expand All @@ -35,15 +35,15 @@ if ! grep "Hello from.*app" out > /dev/null ; then
fi

# And now use the same image as a batch job
ic ce jobrun submit --name myjob --ai=1-$NUM --image ${REPOSITORY}/app-n-job
ibmcloud ce jobrun submit --name myjob --ai=1-$NUM --image ${REPOSITORY}/app-n-job

# Wait for it to finish...
until ic ce jobrun get --name myjob -o jsonpath={.status.succeeded} | grep $NUM
until ibmcloud ce jobrun get --name myjob -o jsonpath={.status.succeeded} | grep $NUM
do
sleep 3
done

ic ce jobrun logs --instance myjob-1-0 | tee out
ibmcloud ce jobrun logs --instance myjob-1-0 | tee out

if ! grep "Hello from.*job" out > /dev/null ; then
echo "Missing expected outout"
Expand Down
14 changes: 7 additions & 7 deletions app2job/run
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
function clean() {
set +x
echo Cleaning...
ic ce job delete -n myjob -f > /dev/null 2>&1 || true
ic ce app delete -n app -f --wto=0 > /dev/null 2>&1 || true
ibmcloud ce job delete -n myjob -f > /dev/null 2>&1 || true
ibmcloud ce app delete -n app -f --wto=0 > /dev/null 2>&1 || true
rm -f out
}

Expand All @@ -21,24 +21,24 @@ export REPOSITORY=${REPOSITORY:-ibmcom}
export COUNT=${COUNT:-50}

# Create the app
ic ce app create -n app --image ${REPOSITORY}/a2j-app
ibmcloud ce app create -n app --image ${REPOSITORY}/a2j-app

# Get metadata about the app for later use
URL=$(ic ce app get -n app -o jsonpath={.status.url})
URL=$(ibmcloud ce app get -n app -o jsonpath={.status.url})

# Create the job definition
ic ce job create -n myjob --ai=1-${COUNT} --image ${REPOSITORY}/a2j-job
ibmcloud ce job create -n myjob --ai=1-${COUNT} --image ${REPOSITORY}/a2j-job

# Now, curl the app and see if it creates the job
curl -s ${URL/http/https}/myjob -X PUT | tee out
jobrun=$(cat out)

while ! ic ce jobrun get -n ${jobrun} | grep "Succeeded.*${COUNT}" ; do
while ! ibmcloud ce jobrun get -n ${jobrun} | grep "Succeeded.*${COUNT}" ; do
sleep 2
done

# Verify job ran ok
ic ce jobrun logs -i ${jobrun}-${COUNT}-0 | grep "JOB_INDEX.*${COUNT}"
ibmcloud ce jobrun logs -i ${jobrun}-${COUNT}-0 | grep "JOB_INDEX.*${COUNT}"

# Clean up
clean
12 changes: 6 additions & 6 deletions bind-app/run
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
function clean() {
set +x
echo Cleaning...
ic ce app delete -n app -f --wto=0 > /dev/null 2>&1 || true
ic resource service-instance-delete mydb -f > /dev/null 2>&1 || true
ibmcloud ce app delete -n app -f --wto=0 > /dev/null 2>&1 || true
ibmcloud resource service-instance-delete mydb -f > /dev/null 2>&1 || true
rm -f out
}

Expand All @@ -20,16 +20,16 @@ set -ex
export REPOSITORY=${REPOSITORY:-ibmcom}

# Create an instance of DB2
ic resource service-instance-create mydb dashdb-for-transactions free us-south
ibmcloud resource service-instance-create mydb dashdb-for-transactions free us-south

# Create the app
ic ce app create -n app --image ${REPOSITORY}/bind-app
ibmcloud ce app create -n app --image ${REPOSITORY}/bind-app

# Get the URL of the app for later use
URL=$(ic ce app get -n app -o jsonpath={.status.url})
URL=$(ibmcloud ce app get -n app -o jsonpath={.status.url})

# Bind the service credentials to the app
ic ce app bind --name app --service-instance mydb
ibmcloud ce app bind --name app --service-instance mydb

# Curl the app to make sure it had the creds
curl -Ls ${URL} | tee out
Expand Down
18 changes: 9 additions & 9 deletions bind-job/run
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
function clean() {
set +x
echo Cleaning...
ic ce job delete -n myjob -f > /dev/null 2>&1 || true
ic ce jobrun delete -n myjobrun -f > /dev/null 2>&1 || true
ic resource service-instance-delete mydb -f > /dev/null 2>&1 || true
ibmcloud ce job delete -n myjob -f > /dev/null 2>&1 || true
ibmcloud ce jobrun delete -n myjobrun -f > /dev/null 2>&1 || true
ibmcloud resource service-instance-delete mydb -f > /dev/null 2>&1 || true
rm -f out
}

Expand All @@ -23,26 +23,26 @@ export REPOSITORY=${REPOSITORY:-ibmcom}
export NUM=${COUNT:-10}

# Create an instance of DB2
ic resource service-instance-create mydb dashdb-for-transactions free us-south
ibmcloud resource service-instance-create mydb dashdb-for-transactions free us-south

# Create a Job definition
ic ce job create --name myjob --array-indices=1-${NUM} \
ibmcloud ce job create --name myjob --array-indices=1-${NUM} \
--image ${REPOSITORY}/bind-job

# Bind the service instance to the job
ic ce job bind --name myjob --service-instance mydb
ibmcloud ce job bind --name myjob --service-instance mydb

# Now submit the job using that definition
ic ce jobrun submit --name myrun --job myjob
ibmcloud ce jobrun submit --name myrun --job myjob

# Wait for it to finish...
until ic ce jobrun get --name myrun -o jsonpath={.status.succeeded} | grep $NUM
until ibmcloud ce jobrun get --name myrun -o jsonpath={.status.succeeded} | grep $NUM
do
sleep 3
done

# Now look at a view of the logs to make sure it worked
ic ce jobrun logs --instance myrun-1-0 | tee out
ibmcloud ce jobrun logs --instance myrun-1-0 | tee out

if ! grep VCAP_SERVICES out > /dev/null ; then
echo "Missing VCAP_SERVICES in App's env vars"
Expand Down
16 changes: 8 additions & 8 deletions configmaps/run
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
function clean() {
set +x
echo Cleaning...
ic ce app delete -n configapp -f --wto=0 > /dev/null 2>&1 || true
ic ce configmap delete -n myconfig -f > /dev/null 2>&1 || true
ibmcloud ce app delete -n configapp -f --wto=0 > /dev/null 2>&1 || true
ibmcloud ce configmap delete -n myconfig -f > /dev/null 2>&1 || true
rm -f out
}

Expand All @@ -23,29 +23,29 @@ export REPOSITORY=${REPOSITORY:-ibmcom}
# 2 - name/value pairs read from a file
# 3 - name/value pair wherer 'value' is the contents of a file (twice)

ic ce configmap create --name myconfig \
ibmcloud ce configmap create --name myconfig \
--from-literal MY_CONFIG_KNOB=42 \
--from-env-file data \
--from-file file \
--from-file MY_FILE=file

# Create the app
ic ce app create -n configapp --image ${REPOSITORY}/ce-config \
ibmcloud ce app create -n configapp --image ${REPOSITORY}/ce-config \
--env-from-configmap myconfig

# Get the URL of the app for later use
URL=$(ic ce app get -n configapp -o jsonpath={.status.url})
URL=$(ibmcloud ce app get -n configapp -o jsonpath={.status.url})

# Just force it to log something by hitting it
curl -Ls $URL

# Extract the instance name from `ic ce app get`
ic ce app get -n configapp | tee out
# Extract the instance name from `ibmcloud ce app get`
ibmcloud ce app get -n configapp | tee out
name=$(grep "configapp.*Running" out | tail -1 | sed "s/ [12].*//")
echo Instance name: $name

# Now check the logs to see if the env vars were set
ic ce app logs --instance $name | tee out
ibmcloud ce app logs --instance $name | tee out
grep MY_ out
if ! [[ $(grep MY_ out | wc -l) == "4" ]]; then
echo "Unexpected output"
Expand Down
6 changes: 3 additions & 3 deletions hello/run
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
function clean() {
set +x
echo Cleaning...
ic ce app delete -n hello -f --wto=0 > /dev/null 2>&1 || true
ibmcloud ce app delete -n hello -f --wto=0 > /dev/null 2>&1 || true
}

clean
Expand All @@ -17,10 +17,10 @@ set -ex
export REPOSITORY=${REPOSITORY:-ibmcom}

# Create the app
ic ce app create -n hello --image ${REPOSITORY}/hello
ibmcloud ce app create -n hello --image ${REPOSITORY}/hello

# Get the URL of the app for later use
URL=$(ic ce app get -n hello -o jsonpath={.status.url})
URL=$(ibmcloud ce app get -n hello -o jsonpath={.status.url})

# Now call it
curl -Ls $URL
Expand Down
6 changes: 3 additions & 3 deletions helloworld/run
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
function clean() {
set +x
echo Cleaning...
ic ce app delete -n helloworld -f --wto=0 > /dev/null 2>&1 || true
ibmcloud ce app delete -n helloworld -f --wto=0 > /dev/null 2>&1 || true
}

clean
Expand All @@ -17,10 +17,10 @@ set -ex
export REPOSITORY=${REPOSITORY:-ibmcom}

# Create the app
ic ce app create -n helloworld --image ${REPOSITORY}/helloworld
ibmcloud ce app create -n helloworld --image ${REPOSITORY}/helloworld

# Get the URL of the app for later use
URL=$(ic ce app get -n helloworld -o jsonpath={.status.url})
URL=$(ibmcloud ce app get -n helloworld -o jsonpath={.status.url})

# Now call it
curl -Ls $URL
Expand Down
20 changes: 10 additions & 10 deletions job/run
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
function clean() {
set +x
echo Cleaning...
ic ce job delete -n myjob -f > /dev/null 2>&1 || true
ic ce jobrun delete -n doit -f > /dev/null 2>&1 || true
ic ce jobrun delete -n doit2 -f > /dev/null 2>&1 || true
ibmcloud ce job delete -n myjob -f > /dev/null 2>&1 || true
ibmcloud ce jobrun delete -n doit -f > /dev/null 2>&1 || true
ibmcloud ce jobrun delete -n doit2 -f > /dev/null 2>&1 || true
rm -f out
}

Expand All @@ -22,33 +22,33 @@ export REPOSITORY=${REPOSITORY:-ibmcom}
export NUM=${NUM:-10}

# Create a Job definition
ic ce job create --name myjob --array-indices=1-${NUM} \
ibmcloud ce job create --name myjob --array-indices=1-${NUM} \
--image ${REPOSITORY}/firstjob

# Now submit the job using that definition
ic ce jobrun submit --name doit --job myjob
ibmcloud ce jobrun submit --name doit --job myjob

# Wait for it to finish...
until ic ce jobrun get --name doit -o jsonpath={.status.succeeded} | grep $NUM
until ibmcloud ce jobrun get --name doit -o jsonpath={.status.succeeded} | grep $NUM
do
sleep 3
done

# Now submit a job w/o creating a job definition first
ic ce jobrun submit --name doit2 --array-indices=1-${NUM} \
ibmcloud ce jobrun submit --name doit2 --array-indices=1-${NUM} \
--image ${REPOSITORY}/firstjob

# Wait for it to finish...
until ic ce jobrun get --name doit2 -o jsonpath={.status.succeeded} | grep $NUM
until ibmcloud ce jobrun get --name doit2 -o jsonpath={.status.succeeded} | grep $NUM
do
sleep 3
done

# Show the stats about the job
ic ce jobrun get --name doit2
ibmcloud ce jobrun get --name doit2

# Now look at a view of the logs to make sure it worked
ic ce jobrun logs --instance doit2-1-0 | tee out
ibmcloud ce jobrun logs --instance doit2-1-0 | tee out

if ! grep "Hi from" out > /dev/null ; then
echo "Missing expected outout"
Expand Down
12 changes: 6 additions & 6 deletions job2app/run
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
function clean() {
set +x
echo Cleaning...
ic ce jobrun delete -n job -f > /dev/null 2>&1 || true
ic ce app delete -n app -f --wto=0 > /dev/null 2>&1 || true
ibmcloud ce jobrun delete -n job -f > /dev/null 2>&1 || true
ibmcloud ce app delete -n app -f --wto=0 > /dev/null 2>&1 || true
}

clean
Expand All @@ -20,16 +20,16 @@ export REPOSITORY=${REPOSITORY:-ibmcom}
export COUNT=${COUNT:-50}

# Create the app
ic ce app create -n app --min=1 --max=1 --image ${REPOSITORY}/j2a-app
ibmcloud ce app create -n app --min=1 --max=1 --image ${REPOSITORY}/j2a-app

# Get metadata about the app for later use
URL=$(ic ce app get -n app -o jsonpath={.status.url})
URL=$(ibmcloud ce app get -n app -o jsonpath={.status.url})

# Create/run the job, passing in the project/namespace
ic ce jobrun submit -n job --ai=1-${COUNT} --image ${REPOSITORY}/j2a-job
ibmcloud ce jobrun submit -n job --ai=1-${COUNT} --image ${REPOSITORY}/j2a-job

# Wait for it to finish...
until ic ce jobrun get -n job -o jsonpath={.status.succeeded} | grep $COUNT; do
until ibmcloud ce jobrun get -n job -o jsonpath={.status.succeeded} | grep $COUNT; do
sleep 3
done

Expand Down
14 changes: 7 additions & 7 deletions ping/run
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
function clean() {
set +x
echo Cleaning...
ic ce sub ping delete -n pinger -f --wait=true > /dev/null 2>&1 || true
ic ce app delete -n pingecho -f --wto=0 > /dev/null 2>&1 || true
ibmcloud ce sub ping delete -n pinger -f --wait=true > /dev/null 2>&1 || true
ibmcloud ce app delete -n pingecho -f --wto=0 > /dev/null 2>&1 || true
rm -f out
}

Expand All @@ -19,20 +19,20 @@ set -ex
export REPOSITORY=${REPOSITORY:-ibmcom}

# Create the app
ic ce app create -n pingecho --image ${REPOSITORY}/ping
ibmcloud ce app create -n pingecho --image ${REPOSITORY}/ping

# Setup the Ping (cron) Event Source, send event every minute
ic ce sub ping create -n pinger -d pingecho \
ibmcloud ce sub ping create -n pinger -d pingecho \
--data '{"mydata":"hello world"}' -s '* * * * *'

# Extract the instance name from `ic ce app get`
ic ce app get -n pingecho | tee out
# Extract the instance name from `ibmcloud ce app get`
ibmcloud ce app get -n pingecho | tee out
name=$(grep "ping.*Running" out | tail -1 | sed "s/ [12].*//")
echo Instance name: $name

# Now wait until we get the event - shouldn't take more than a minute
while true ; do
ic ce app logs --instance $name > out
ibmcloud ce app logs --instance $name > out
grep "hello world" out > /dev/null 2>&1 && break
sleep 10
done
Expand Down
Loading

0 comments on commit af5bf38

Please sign in to comment.