Skip to content

Commit bb42896

Browse files
tschaeferalexellis
authored andcommitted
Create template verification
Signed-off-by: tschaefer <github@blackox.org>
1 parent 6f85a49 commit bb42896

File tree

2 files changed

+99
-0
lines changed

2 files changed

+99
-0
lines changed

.github/workflows/ci.yaml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
name: CI
3+
4+
on: # yamllint disable-line rule:truthy
5+
push:
6+
branches:
7+
- master
8+
pull_request:
9+
types:
10+
- opened
11+
- synchronize
12+
- reopened
13+
14+
jobs:
15+
build:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 1
21+
- name: Setup faas-cli
22+
run: curl -sSL https://cli.openfaas.com | sh
23+
- name: Verify all templates
24+
run: bash -x verify.sh

verify.sh

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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

Comments
 (0)