|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +function clean() { |
| 4 | + set +x |
| 5 | + echo Cleaning... |
| 6 | + ic cr namespace-rm "${ICR_NS}" -f > /dev/null 2>&1 || true |
| 7 | + ic ce app delete -n s2i-buildpacks -f --wto=0 > /dev/null 2>&1 || true |
| 8 | + ic iam api-key-delete s2i-sample -f > /dev/null 2>&1 || true |
| 9 | + ic ce registry delete -n icr -f > /dev/null 2>&1 || true |
| 10 | + ic ce buildrun delete -n myrun -f > /dev/null 2>&1 || true |
| 11 | + ic ce build delete -n mybuild -f > /dev/null 2>&1 || true |
| 12 | + rm -f out || true |
| 13 | +} |
| 14 | + |
| 15 | +# Define our ICR Namespace env var for later use |
| 16 | +ID=$(ic account show | grep "Account ID:" | sed "s/^.*: *//") |
| 17 | +ICR_NS=s2i-${ID:0:25} |
| 18 | + |
| 19 | +# Clean up previous run |
| 20 | +clean |
| 21 | + |
| 22 | +set -ex |
| 23 | + |
| 24 | +# Create an ICR namespace to hold our new image |
| 25 | +ic cr namespace-add $ICR_NS |
| 26 | + |
| 27 | +# Create an apikey, put it in a registry secret. Used to push/pull image to ICR |
| 28 | +ic iam api-key-create s2i-sample | \ |
| 29 | + grep "API Key" | sed 's/^.*Key *//' | \ |
| 30 | + xargs ic ce registry create -n icr -s us.icr.io -u iamapikey -p |
| 31 | + |
| 32 | +# Define the build of this dir in this github repo |
| 33 | +ic ce build create -n mybuild -i "us.icr.io/${ICR_NS}/app" --rs icr \ |
| 34 | + --source https://github.com/IBM/CodeEngine --context-dir s2i-buildpacks --strategy buildpacks |
| 35 | + |
| 36 | +# Now kick off the build itself |
| 37 | +ic ce buildrun submit -n myrun --build mybuild |
| 38 | + |
| 39 | +# Wait for it to finish |
| 40 | +while true ; do |
| 41 | + ic ce buildrun get -n myrun > out |
| 42 | + grep Succeeded out && break |
| 43 | + grep "exited with" out && cat out && exit 1 |
| 44 | + sleep 10 |
| 45 | +done |
| 46 | + |
| 47 | +# Test the image we just built - deploy an app and 'curl' it |
| 48 | +ic ce app create -n s2i-buildpacks --image "us.icr.io/${ICR_NS}/app" --rs icr |
| 49 | +URL=$(ic ce app get -n s2i-buildpacks -o jsonpath={.status.url}) |
| 50 | +curl -s "${URL}" |
| 51 | + |
| 52 | +# Clean |
| 53 | +clean |
0 commit comments