This project looks interesting, and I look forward to making things wih it! One thing I'm a bit confused about is how one goes about building a function from scratch, where a template isn't available. I.e. how would I build a function in Rust? What should my Dockerfile look like? Can I just use the official Rust image and ensure that my binary launches as soon as the container comes up?
I also gather that I simply read from stdin and output to stdout. This leaves me with several unanswered questions:
A "functions from scratch" guide might be a useful addition. If such a thing already exists, then please point me to it and apologies for missing it. Thanks!
Hi @ndarilek thanks for using OpenFaaS. We do actually have a template for Rust maintained by @ericstoekl, but I'll point you in the right location. We have answers for the questions you're asking in the documentation.
I'd start by reading the documentation in the TestDrive which explains some of this and the beginner guides too.
The reference documentation for the Function Watchdog is also likely to answer lots of your questions:
Hey, thanks for the detailed response!
So I have a bit more clarity now. I didn't realize the stdin/stdout
support was part of watchdog rather than the way things were.
So, by default, a function is just a web server that listens on port
8080? I guess I didn't see that anywhere in the docs I checked. :) Is
that accurate? Should it always listen on 8080, or on the value of some
other port (I.e. one injected into the environment?)
I also stumbled a bit because it doesn't look like the watchdog supports
GET requests. Is that also accurate? I did eventually see that in the
watchdog docs, but it didn't jump out at me, and I assumed that the
watchdog gave me parity with the API gateway. I was trying to write a
more advanced echo function that not only returned the body, but also
the environment and other aspects of the context.
Thanks!
Hi @ndarilek, the latest watchdog/gateway _does_ supprt GET requests. Make sure you update your cli and Docker images to take advantage of the latest updates. It's a fast moving repo 馃槃
Also, the port 8080 is defined as environment variables for the gateway and watchdog. You can change them to whatever you'd like by mapping the ports in the docker-compose.yml file
as an example:
gateway:
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
ports:
- 8181:8080
image: functions/gateway:0.6.14
As for the "...didn't jump out at me..." we know the documentation is a bit spread out, but there is work underway to unify them into a documentation site. Please take a look and we welcome any input you may have: PR #274
You're right, I was using an old binary. I'd copy-pasted the Rust template Dockerfile into my own, and it used 0.6.4. Updated that, and now things work as expected. Thanks!