From 0d1962de1e8a92a18cdc78275e869c0736d1fbb1 Mon Sep 17 00:00:00 2001 From: Alex Ellis Date: Wed, 6 Sep 2017 13:05:00 +0100 Subject: [PATCH] Add GCC/C example. Signed-off-by: Alex Ellis --- sample-functions/CHelloWorld/.gitignore | 3 +++ sample-functions/CHelloWorld/README.md | 20 ++++++++++++++++ sample-functions/CHelloWorld/src/Dockerfile | 26 +++++++++++++++++++++ sample-functions/CHelloWorld/src/main.c | 9 +++++++ sample-functions/CHelloWorld/stack.yml | 9 +++++++ 5 files changed, 67 insertions(+) create mode 100644 sample-functions/CHelloWorld/.gitignore create mode 100644 sample-functions/CHelloWorld/README.md create mode 100644 sample-functions/CHelloWorld/src/Dockerfile create mode 100644 sample-functions/CHelloWorld/src/main.c create mode 100644 sample-functions/CHelloWorld/stack.yml diff --git a/sample-functions/CHelloWorld/.gitignore b/sample-functions/CHelloWorld/.gitignore new file mode 100644 index 00000000..745051a1 --- /dev/null +++ b/sample-functions/CHelloWorld/.gitignore @@ -0,0 +1,3 @@ +template +build +master.zip diff --git a/sample-functions/CHelloWorld/README.md b/sample-functions/CHelloWorld/README.md new file mode 100644 index 00000000..23bfa671 --- /dev/null +++ b/sample-functions/CHelloWorld/README.md @@ -0,0 +1,20 @@ +Hello World in C +=================== + +This is hello world in C using GCC and Alpine Linux. + +It also makes use of a multi-stage build and a `scratch` container for the runtime. + +``` +$ faas-cli build -f ./stack.yml +``` + +If pushing to a remote registry change the name from `alexellis` to your own Hub account. + +``` +$ faas-cli push -f ./stack.yml +$ faas-cli deploy -f ./stack.yml +``` + +Then invoke via `curl`, `faas-cli` or the UI. + diff --git a/sample-functions/CHelloWorld/src/Dockerfile b/sample-functions/CHelloWorld/src/Dockerfile new file mode 100644 index 00000000..d62c1197 --- /dev/null +++ b/sample-functions/CHelloWorld/src/Dockerfile @@ -0,0 +1,26 @@ +FROM alpine:3.6 as builder +RUN apk add --no-cache curl \ + && curl -SL https://github.com/alexellis/faas/releases/download/0.6.4/fwatchdog > /usr/bin/fwatchdog \ + && chmod +x /usr/bin/fwatchdog \ + && apk --no-cache del curl + +WORKDIR /root/ + +RUN apk add --no-cache gcc \ + musl-dev +COPY main.c . + +RUN gcc main.c -static -o /main \ + && chmod +x /main \ + && /main + +FROM scratch + +COPY --from=builder /main / +COPY --from=builder /usr/bin/fwatchdog / +COPY --from=builder /tmp /tmp + +ENV fprocess="/main" + +CMD ["/fwatchdog"] + diff --git a/sample-functions/CHelloWorld/src/main.c b/sample-functions/CHelloWorld/src/main.c new file mode 100644 index 00000000..413a749c --- /dev/null +++ b/sample-functions/CHelloWorld/src/main.c @@ -0,0 +1,9 @@ +#include + +int main() { + + printf("Hello world\n"); + + return 0; +} + diff --git a/sample-functions/CHelloWorld/stack.yml b/sample-functions/CHelloWorld/stack.yml new file mode 100644 index 00000000..93bb128e --- /dev/null +++ b/sample-functions/CHelloWorld/stack.yml @@ -0,0 +1,9 @@ +provider: + name: faas + gateway: http://localhost:8080 + +functions: + helloc: + lang: Dockerfile + handler: ./src + image: alexellis/helloc