|
| 1 | +#!/bin/bash |
| 2 | +set -e |
| 3 | + |
| 4 | +CLI="faas-cli" |
| 5 | + |
| 6 | +build_template() { |
| 7 | + template=$1 |
| 8 | + |
| 9 | + echo Building $template |
| 10 | + func_name=$template-ci |
| 11 | + $CLI new $func_name --lang $template 2>/dev/null 1>&2 |
| 12 | + $CLI build -f stack.yaml |
| 13 | +} |
| 14 | + |
| 15 | +verify_and_clean() { |
| 16 | + image=$1 |
| 17 | + tag_name=latest |
| 18 | + |
| 19 | + echo Verifying $template |
| 20 | + container=$(docker run -d -p 8080:8080 $func_name:$tag_name) |
| 21 | + sleep 5 # wait for slower templates to start |
| 22 | + output=$(curl -s -d "testing" http://127.0.0.1:8080) |
| 23 | + |
| 24 | + echo $image output: $output |
| 25 | + success=false |
| 26 | + if [ ! -z "$output" ]; then # output was not empty = good template |
| 27 | + success=true |
| 28 | + fi |
| 29 | + |
| 30 | + echo Cleaning $image |
| 31 | + docker rm $container -f 2>/dev/null 1>&2 |
| 32 | + docker rmi $func_name:$tag_name 2>/dev/null 1>&2 |
| 33 | + |
| 34 | + if [ "$success" = false ]; then |
| 35 | + echo $image template failed validation |
| 36 | + exit 1 |
| 37 | + else |
| 38 | + echo $image template validation successful |
| 39 | + fi |
| 40 | +} |
| 41 | + |
| 42 | +tmpdir=$(mktemp -d -t openfaas-XXXXXX) |
| 43 | +trap 'rm -rf $tmpdir' EXIT |
| 44 | +cp -r ./template $tmpdir |
| 45 | + |
| 46 | +if ! [ -x "$(command -v faas-cli)" ]; then |
| 47 | + mkdir -p $tmpdir/bin |
| 48 | + cd $tmpdir/bin |
| 49 | + |
| 50 | + curl -sSL https://cli.openfaas.com | sh |
| 51 | + CLI="$tmpdir/bin/faas-cli" |
| 52 | +fi |
| 53 | + |
| 54 | +cli_version=$($CLI version --short-version) |
| 55 | + |
| 56 | +echo Validating templates with faas-cli $cli_version |
| 57 | + |
| 58 | +# verify each of the templates |
| 59 | +cd $tmpdir/template |
| 60 | +for dir in ./*/; do |
| 61 | + dirname=${dir%*/} |
| 62 | + template=${dirname##*/} |
| 63 | + |
| 64 | + # skip arm templates |
| 65 | + case "$template" in |
| 66 | + *-arm*) continue ;; |
| 67 | + esac |
| 68 | + |
| 69 | + pushd ../ 2>/dev/null 1>&2 |
| 70 | + |
| 71 | + build_template $template |
| 72 | + verify_and_clean $template |
| 73 | + |
| 74 | + popd 2>/dev/null 1>&2 |
| 75 | +done |
0 commit comments