Skip to content

Commit 893b5c5

Browse files
committed
Allow Dockerfile language. Add imagemagick as sample.
Signed-off-by: Alex Ellis <[email protected]>
1 parent 961581e commit 893b5c5

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

builder/build.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,36 @@ func BuildImage(image string, handler string, functionName string, language stri
1515
case "node", "python", "ruby", "csharp":
1616
tempPath := createBuildTemplate(functionName, handler, language)
1717

18-
fmt.Printf("Building: %s with Docker. Please wait..\n", image)
18+
fmt.Printf("Building: %s with %s template. Please wait..\n", image, language)
1919

2020
flagStr := buildFlagString(nocache, squash, os.Getenv("http_proxy"), os.Getenv("https_proxy"))
2121

2222
builder := strings.Split(fmt.Sprintf("docker build %s-t %s .", flagStr, image), " ")
2323
fmt.Println(strings.Join(builder, " "))
2424
ExecCommand(tempPath, builder)
25+
fmt.Printf("Image: %s built.\n", image)
26+
27+
break
28+
case "Dockerfile", "dockerfile":
29+
tempPath := handler
30+
if _, err := os.Stat(handler); err != nil {
31+
fmt.Printf("Unable to build %s, %s is an invalid path\n", image, handler)
32+
fmt.Printf("Image: %s not built.\n", image)
33+
34+
break
35+
}
36+
fmt.Printf("Building: %s with Dockerfile. Please wait..\n", image)
37+
38+
flagStr := buildFlagString(nocache, squash, os.Getenv("http_proxy"), os.Getenv("https_proxy"))
39+
40+
builder := strings.Split(fmt.Sprintf("docker build %s-t %s .", flagStr, image), " ")
41+
fmt.Println(strings.Join(builder, " "))
42+
ExecCommand(tempPath, builder)
43+
fmt.Printf("Image: %s built.\n", image)
44+
2545
default:
2646
log.Fatalf("Language template: %s not supported. Build a custom Dockerfile instead.", language)
2747
}
28-
29-
fmt.Printf("Image: %s built.\n", image)
3048
}
3149

3250
// createBuildTemplate creates temporary build folder to perform a Docker build with Node template

sample/imagemagick/Dockerfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM alpine:3.6
2+
3+
# Alternatively use ADD https:// (which will not be cached by Docker builder)
4+
RUN apk --no-cache add curl ca-certificates imagemagick \
5+
&& echo "Pulling watchdog binary from Github." \
6+
&& curl -sSL https://github.com/alexellis/faas/releases/download/0.5.8-alpha/fwatchdog > /usr/bin/fwatchdog \
7+
&& chmod +x /usr/bin/fwatchdog
8+
9+
ENV fprocess="convert - -resize 50% fd:1"
10+
11+
CMD ["fwatchdog"]

samples.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ functions:
1616

1717
# curl localhost:8080/function/shrink-image --data-binary @big.png > smaller.png
1818
shrink-image:
19-
skip_build: true # this example is a binary, doesn't use a template
19+
lang: Dockerfile
20+
handler: ./sample/imagemagick
2021
image: functions/resizer
2122
fprocess: "convert - -resize 50% fd:1"
2223

0 commit comments

Comments
 (0)