Convert build.sh to a multi-stage Dockerfile. (#452)
This commit is contained in:
@@ -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
|
FROM alpine:3.5
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
RUN apk update
|
RUN apk update
|
||||||
RUN apk add coreutils binutils findutils grep
|
RUN apk add coreutils binutils findutils grep
|
||||||
|
|
||||||
COPY . /app
|
COPY --from=0 /go/server /app/server
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
EXPOSE 8888
|
EXPOSE 8888
|
||||||
ENTRYPOINT ["./server"]
|
ENTRYPOINT ["./server"]
|
||||||
@@ -36,11 +36,6 @@ All output that is provided to the server over the STDOUT will be transformed in
|
|||||||
|
|
||||||
|
|
||||||
## Compiling
|
## Compiling
|
||||||
In order to build the Dockerfile, the server needs to be compiled to the right architecture.
|
|
||||||
|
|
||||||
```bash
|
|
||||||
sh ./build.sh
|
|
||||||
```
|
|
||||||
|
|
||||||
Build the Dockerfile:
|
Build the Dockerfile:
|
||||||
```bash
|
```bash
|
||||||
|
|||||||
@@ -1,4 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
GOOS=linux GOARCH=386 go build -o server .
|
|
||||||
|
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
ARG BUILDER_IMAGE=fission/builder:latest
|
||||||
|
FROM ${BUILDER_IMAGE}
|
||||||
|
|
||||||
|
ADD build.sh /usr/local/bin/build
|
||||||
Executable
+13
@@ -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}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
@@ -10,6 +11,8 @@ import (
|
|||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/fission/fission"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -31,11 +34,34 @@ func (bs *BinaryServer) SpecializeHandler(w http.ResponseWriter, r *http.Request
|
|||||||
return
|
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 err != nil {
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
w.WriteHeader(http.StatusNotFound)
|
w.WriteHeader(http.StatusNotFound)
|
||||||
w.Write([]byte(bs.fetchedCodePath + ": not found"))
|
w.Write([]byte(codePath + ": not found"))
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
panic(err)
|
panic(err)
|
||||||
@@ -45,7 +71,7 @@ func (bs *BinaryServer) SpecializeHandler(w http.ResponseWriter, r *http.Request
|
|||||||
// Future: Check if executable is correct architecture/executable.
|
// Future: Check if executable is correct architecture/executable.
|
||||||
|
|
||||||
// Copy the executable to ensure that file is executable and immutable.
|
// 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 {
|
if err != nil {
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
w.Write([]byte("Failed to read executable."))
|
w.Write([]byte("Failed to read executable."))
|
||||||
@@ -125,6 +151,7 @@ func main() {
|
|||||||
server := &BinaryServer{*codePath, absInternalCodePath}
|
server := &BinaryServer{*codePath, absInternalCodePath}
|
||||||
http.HandleFunc("/", server.InvocationHandler)
|
http.HandleFunc("/", server.InvocationHandler)
|
||||||
http.HandleFunc("/specialize", server.SpecializeHandler)
|
http.HandleFunc("/specialize", server.SpecializeHandler)
|
||||||
|
http.HandleFunc("/v2/specialize", server.SpecializeHandler)
|
||||||
|
|
||||||
fmt.Println("Listening on 8888 ...")
|
fmt.Println("Listening on 8888 ...")
|
||||||
err = http.ListenAndServe(":8888", nil)
|
err = http.ListenAndServe(":8888", nil)
|
||||||
|
|||||||
Reference in New Issue
Block a user