Last active
June 9, 2020 20:48
-
-
Save jacobweinstock/374dad068d0a3b6ca512c086eeb54781 to your computer and use it in GitHub Desktop.
another idea for serverless and cake
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
echo -e "what's the full path to the cake spec.yaml file?" | |
read cakespec | |
echo -e "what's the full path to the cake-linux binary?" | |
read cakebinary | |
echo -e "run nuclio server" | |
docker run -d -p 8070:8070 -v /var/run/docker.sock:/var/run/docker.sock -v /tmp:/tmp --name nuclio-dashboard quay.io/nuclio/dashboard:stable-amd64 | |
echo -e "download nuclio cli" | |
wget -O /usr/local/bin/nuctl https://github.com/nuclio/nuclio/releases/download/1.4.6/nuctl-1.4.6-$(go env GOHOSTOS)-$(go env GOHOSTARCH) | |
chmod +x /usr/local/bin/nuctl | |
echo -e "deploy the function" | |
cat <<EOF > nuclio_spec.yaml | |
--- | |
spec: | |
description: cake | |
handler: cakefn.sh | |
runtime: shell | |
volumes: | |
- volume: | |
hostPath: | |
path: "${cakebinary}" | |
volumeMount: | |
mountPath: "/usr/local/bin/cake-linux" | |
build: | |
baseImage: golang | |
noCache: true | |
commands: | |
- apt update && apt -y install jq | |
- GO111MODULE=on go get github.com/mikefarah/yq/v3 | |
EOF | |
cat <<EOF > cakefn.sh | |
#!/usr/bin/env bash | |
myVar=\$(tee) | |
echo \$myVar > spec.json | |
/go/bin/yq r spec.json --prettyPrint > spec.yaml | |
cake-linux deploy rancher -f /go/spec.yaml -j > result.file | |
jq -s . result.file | |
EOF | |
nuctl deploy cake --namespace nuclio --platform local --path cakefn.sh -f nuclio_spec.yaml | |
echo -e "convert the cake spec to json" | |
GO111MODULE=on go get github.com/mikefarah/yq/v3 | |
$(go env GOPATH)/bin/yq r ${cakespec} -j > spec.json | |
echo -e "Post to the cake function" | |
curl -X POST -H "Content-Type: application/json" -d @spec.json http://localhost:$(nuctl get function --platform local cake | tail -n1 | cut -d"|" -f5 | xargs) | jq |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment