Building and pushing

We will edit the last line to be image: chanwit/hello:v1. Again, do not forget to replace my Docker ID with yours. We then build with the faas-cli build command. We use -f to specify a function definition file for the CLI. Please note that there will be two stages and 17 steps to build this Dockerfile:

$ faas-cli build -f ./hello.yml
[0] > Building: hello.
Clearing temporary build folder: ./build/hello/
Preparing ./hello/ ./build/hello/function
Building: chanwit/hello:v1 with go template. Please wait..

Sending build context to Docker daemon 6.144kB
Step 1/17 : FROM golang:1.8.3-alpine3.6
---> fd1ada53b403

...

Step 17/17 : CMD ./fwatchdog
---> Running in a904f6659c33
---> f3b8ec154ee9
Removing intermediate container a904f6659c33
Successfully built f3b8ec154ee9
Successfully tagged chanwit/hello:v1
Image: chanwit/hello:v1 built.
[0] < Builder done.

The Go function template will be copied from the template/go directory to the build/hello directory.  Then the handler file, hello/handler.go, will be copied to build/hello/function/handler.go. The program's entry point is defined in build/hello/main.go, which in turn calls the handler function. During the build process, the docker build command will be executed internally by faas-cli. Steps defined inside the Dockerfile will be used to compile and pack the function.

The following figure explains how the Dockerfile, the source files, and the template are related to each other:

Figure 4.10: OpenFaaS template and its related components for the Go language

After the build is completed, we check the directory's structure again. This time, run  tree -L 3 . to show the directory for three levels of depth because we want to inspect the contents of the build directory, which is created by the faas-cli build command:

$ tree -L 3 .
.
├── build
│ └── hello
│ ├── Dockerfile
│ ├── function
│ ├── main.go
│ └── template.yml
├── hello
│ └── handler.go
├── hello.yml
└── template

We can push the built image to a Docker repository directly, also with the faas-cli push command. Use -f to specify the specification file. The value of functions.image for the specification will be used for pushing:

$ faas-cli push -f hello.yml 
[0] > Pushing: hello.
The push refers to a repository [docker.io/chanwit/hello]
8170484ad942: Pushed
071849fe2878: Pushed
a2e6c9f93e16: Pushed
76eeaa2cc808: Pushed
3fb66f713c9f: Pushed
v1: digest: sha256:fbf493a6bb36ef92f14578508f345f055f346d0aecc431aa3f84a4f0db04e7cb size: 1367
[0] < Pushing done.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset