Convert build.sh to a multi-stage Dockerfile. (#452)

This commit is contained in:
Justin
2018-01-28 11:49:31 +08:00
committed by Ta-Ching Chen
parent 4f7eb19b7c
commit 986b300b8c
6 changed files with 59 additions and 16 deletions
+11 -3
View File
@@ -1,10 +1,18 @@
FROM golang:onbuild
WORKDIR /go
COPY *.go /go/
RUN GOOS=linux GOARCH=386 go build -o server .
FROM alpine:3.5
WORKDIR /app
RUN apk update
RUN apk add coreutils binutils findutils grep
COPY . /app
WORKDIR /app
COPY --from=0 /go/server /app/server
EXPOSE 8888
ENTRYPOINT ["./server"]
ENTRYPOINT ["./server"]
+1 -6
View File
@@ -36,15 +36,10 @@ All output that is provided to the server over the STDOUT will be transformed in
## Compiling
In order to build the Dockerfile, the server needs to be compiled to the right architecture.
```bash
sh ./build.sh
```
Build the Dockerfile:
```bash
docker build --tag=${USER}/binary-env .
```
See the [README](../../examples/binary/README.md) in the binary examples directory for usage instructions.
See the [README](../../examples/binary/README.md) in the binary examples directory for usage instructions.
-4
View File
@@ -1,4 +0,0 @@
#!/bin/sh
GOOS=linux GOARCH=386 go build -o server .
+4
View File
@@ -0,0 +1,4 @@
ARG BUILDER_IMAGE=fission/builder:latest
FROM ${BUILDER_IMAGE}
ADD build.sh /usr/local/bin/build
+13
View File
@@ -0,0 +1,13 @@
#!/bin/sh
apk update
CWD=$(pwd)
if [ -f ${SRC_PKG}/build.sh ]; then
cd ${SRC_PKG}
./build.sh
cd ${CWD}
fi
cp -rf ${SRC_PKG} ${DEPLOY_PKG}
+30 -3
View File
@@ -1,6 +1,7 @@
package main
import (
"encoding/json"
"flag"
"fmt"
"io"
@@ -10,6 +11,8 @@ import (
"os/exec"
"path/filepath"
"strings"
"github.com/fission/fission"
)
const (
@@ -31,11 +34,34 @@ func (bs *BinaryServer) SpecializeHandler(w http.ResponseWriter, r *http.Request
return
}
_, err := os.Stat(bs.fetchedCodePath)
request := fission.FunctionLoadRequest{}
codePath := bs.fetchedCodePath
err := json.NewDecoder(r.Body).Decode(&request)
switch {
case err == io.EOF:
case err != nil:
panic(err)
}
if request.FilePath != "" {
fileStat, err := os.Stat(request.FilePath)
if err != nil {
panic(err)
}
codePath = request.FilePath
switch mode := fileStat.Mode(); {
case mode.IsDir():
codePath = filepath.Join(request.FilePath, request.FunctionName)
}
}
_, err = os.Stat(codePath)
if err != nil {
if os.IsNotExist(err) {
w.WriteHeader(http.StatusNotFound)
w.Write([]byte(bs.fetchedCodePath + ": not found"))
w.Write([]byte(codePath + ": not found"))
return
} else {
panic(err)
@@ -45,7 +71,7 @@ func (bs *BinaryServer) SpecializeHandler(w http.ResponseWriter, r *http.Request
// Future: Check if executable is correct architecture/executable.
// Copy the executable to ensure that file is executable and immutable.
userFunc, err := ioutil.ReadFile(bs.fetchedCodePath)
userFunc, err := ioutil.ReadFile(codePath)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte("Failed to read executable."))
@@ -125,6 +151,7 @@ func main() {
server := &BinaryServer{*codePath, absInternalCodePath}
http.HandleFunc("/", server.InvocationHandler)
http.HandleFunc("/specialize", server.SpecializeHandler)
http.HandleFunc("/v2/specialize", server.SpecializeHandler)
fmt.Println("Listening on 8888 ...")
err = http.ListenAndServe(":8888", nil)