mirror of
https://github.com/openfaas/faas.git
synced 2025-06-09 08:46:48 +00:00
Add GCC/C example.
Signed-off-by: Alex Ellis <alexellis2@gmail.com>
This commit is contained in:
parent
fbe846aa31
commit
0d1962de1e
3
sample-functions/CHelloWorld/.gitignore
vendored
Normal file
3
sample-functions/CHelloWorld/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
template
|
||||||
|
build
|
||||||
|
master.zip
|
20
sample-functions/CHelloWorld/README.md
Normal file
20
sample-functions/CHelloWorld/README.md
Normal file
@ -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.
|
||||||
|
|
26
sample-functions/CHelloWorld/src/Dockerfile
Normal file
26
sample-functions/CHelloWorld/src/Dockerfile
Normal file
@ -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"]
|
||||||
|
|
9
sample-functions/CHelloWorld/src/main.c
Normal file
9
sample-functions/CHelloWorld/src/main.c
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#include<stdio.h>
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
|
||||||
|
printf("Hello world\n");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
9
sample-functions/CHelloWorld/stack.yml
Normal file
9
sample-functions/CHelloWorld/stack.yml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
provider:
|
||||||
|
name: faas
|
||||||
|
gateway: http://localhost:8080
|
||||||
|
|
||||||
|
functions:
|
||||||
|
helloc:
|
||||||
|
lang: Dockerfile
|
||||||
|
handler: ./src
|
||||||
|
image: alexellis/helloc
|
Loading…
x
Reference in New Issue
Block a user