Skip to content

Commit

Permalink
Allow Dockerfile language. Add imagemagick as sample.
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Ellis <[email protected]>
  • Loading branch information
alexellis committed Aug 27, 2017
1 parent 961581e commit 893b5c5
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
24 changes: 21 additions & 3 deletions builder/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,36 @@ func BuildImage(image string, handler string, functionName string, language stri
case "node", "python", "ruby", "csharp":
tempPath := createBuildTemplate(functionName, handler, language)

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

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

builder := strings.Split(fmt.Sprintf("docker build %s-t %s .", flagStr, image), " ")
fmt.Println(strings.Join(builder, " "))
ExecCommand(tempPath, builder)
fmt.Printf("Image: %s built.\n", image)

break
case "Dockerfile", "dockerfile":
tempPath := handler
if _, err := os.Stat(handler); err != nil {
fmt.Printf("Unable to build %s, %s is an invalid path\n", image, handler)
fmt.Printf("Image: %s not built.\n", image)

break
}
fmt.Printf("Building: %s with Dockerfile. Please wait..\n", image)

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

builder := strings.Split(fmt.Sprintf("docker build %s-t %s .", flagStr, image), " ")
fmt.Println(strings.Join(builder, " "))
ExecCommand(tempPath, builder)
fmt.Printf("Image: %s built.\n", image)

default:
log.Fatalf("Language template: %s not supported. Build a custom Dockerfile instead.", language)
}

fmt.Printf("Image: %s built.\n", image)
}

// createBuildTemplate creates temporary build folder to perform a Docker build with Node template
Expand Down
11 changes: 11 additions & 0 deletions sample/imagemagick/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM alpine:3.6

# Alternatively use ADD https:// (which will not be cached by Docker builder)
RUN apk --no-cache add curl ca-certificates imagemagick \
&& echo "Pulling watchdog binary from Github." \
&& curl -sSL https://github.com/alexellis/faas/releases/download/0.5.8-alpha/fwatchdog > /usr/bin/fwatchdog \
&& chmod +x /usr/bin/fwatchdog

ENV fprocess="convert - -resize 50% fd:1"

CMD ["fwatchdog"]
3 changes: 2 additions & 1 deletion samples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ functions:

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

Expand Down

0 comments on commit 893b5c5

Please sign in to comment.