-
Notifications
You must be signed in to change notification settings - Fork 223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Go template capability for creating functions #145
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
223482c
Added Go language templates
nicholasjackson d99355a
Update dockerfile to exclude templates from tests
nicholasjackson 41b6340
Updated Dockerfiles to handle GoFmt for go templates, updated Makefil…
nicholasjackson e6868da
Added non-root user to Go tempate Dockerfile
nicholasjackson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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,28 @@ | ||
FROM golang:1.8.3-alpine | ||
|
||
RUN apk --no-cache add curl \ | ||
&& echo "Pulling watchdog binary from Github." \ | ||
&& curl -sSL https://github.com/openfaas/faas/releases/download/0.6.5/fwatchdog > /usr/bin/fwatchdog \ | ||
&& chmod +x /usr/bin/fwatchdog \ | ||
&& apk del curl --no-cache | ||
|
||
WORKDIR /go/src/handler | ||
COPY . . | ||
|
||
# Run a gofmt and exclude all vendored code. | ||
RUN test -z "$(gofmt -l $(find . -type f -name '*.go' -not -path "./vendor/*"))" | ||
|
||
RUN CGO_ENABLED=0 GOOS=linux \ | ||
go build --ldflags "-s -w" -a -installsuffix cgo -o handler . | ||
RUN go test ./... -cover | ||
|
||
FROM alpine:latest | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please pin to 3.6 - tracking |
||
RUN apk --no-cache add ca-certificates | ||
|
||
WORKDIR /root/ | ||
|
||
COPY --from=0 /go/src/handler/handler . | ||
COPY --from=0 /usr/bin/fwatchdog . | ||
ENV fprocess="./handler" | ||
|
||
CMD ["./fwatchdog"] |
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,10 @@ | ||
package function | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
// Handle a serverless request | ||
func Handle(req []byte) string { | ||
return fmt.Sprintf("Hello, Go. You said: %s", string(req)) | ||
} |
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,12 @@ | ||
package function | ||
|
||
import "testing" | ||
|
||
func TestHandleReturnsCorrectResponse(t *testing.T) { | ||
expected := "Hello, Go. You said: Hello World ss" | ||
resp := Handle([]byte("Hello World")) | ||
|
||
if resp != expected { | ||
t.Fatalf("Expected: %v, Got: %v", expected, resp) | ||
} | ||
} |
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,19 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"log" | ||
"os" | ||
|
||
"handler/function" | ||
) | ||
|
||
func main() { | ||
input, err := ioutil.ReadAll(os.Stdin) | ||
if err != nil { | ||
log.Fatalf("Unable to read standard input: %s", err.Error()) | ||
} | ||
|
||
fmt.Println(function.Handle(input)) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one quick suggestion, some other pull requests that are pending are opting to run the functions as non-root users. some examples here by @ericstoekl #91.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ha, I should know that I was one of the guilty parties behind caninothazroot.
Not even following my own advice
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have just added an additional commit which corrects this issue