-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ba723d4
commit f7a6022
Showing
4 changed files
with
66 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,21 @@ | ||
FROM python:3.11-alpine | ||
FROM golang:1.20-alpine AS builder | ||
|
||
WORKDIR /usr/src/build | ||
COPY functionhandler.go . | ||
RUN GO111MODULE=off CGO_ENABLED=0 go build -o handler.bin . | ||
|
||
FROM alpine | ||
|
||
EXPOSE 8000 | ||
|
||
# Create app directory | ||
WORKDIR /usr/src/app | ||
|
||
COPY --from=builder /usr/src/build/handler.bin . | ||
|
||
COPY . . | ||
RUN rm functionhandler.go | ||
RUN mv fn/* . | ||
RUN chmod +x fn.sh | ||
|
||
CMD [ "python3", "functionhandler.py" ] | ||
CMD [ "./handler.bin" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"io" | ||
"log" | ||
"net/http" | ||
"os/exec" | ||
) | ||
|
||
func main() { | ||
port := ":8000" | ||
|
||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { | ||
switch r.Method { | ||
case http.MethodGet: | ||
if r.URL.Path == "/health" { | ||
w.WriteHeader(http.StatusOK) | ||
fmt.Fprint(w, "OK") | ||
log.Println("reporting health: OK") | ||
return | ||
} | ||
w.WriteHeader(http.StatusNotFound) | ||
return | ||
|
||
case http.MethodPost: | ||
data, err := io.ReadAll(r.Body) | ||
if err != nil { | ||
w.WriteHeader(http.StatusInternalServerError) | ||
fmt.Fprint(w, err) | ||
return | ||
} | ||
cmd := exec.Command("./fn.sh") | ||
cmd.Stdin = bytes.NewReader(data) | ||
output, err := cmd.CombinedOutput() | ||
if err != nil { | ||
w.WriteHeader(http.StatusInternalServerError) | ||
fmt.Fprint(w, err) | ||
return | ||
} | ||
w.WriteHeader(http.StatusOK) | ||
w.Write(output) | ||
return | ||
default: | ||
w.WriteHeader(http.StatusMethodNotAllowed) | ||
return | ||
} | ||
}) | ||
|
||
log.Printf("Server listening on port %s\n", port) | ||
err := http.ListenAndServe(port, nil) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,3 @@ INPUT=$(cat) | |
|
||
# echo the variable to stdout | ||
echo -n "$INPUT" | ||
|