-
Notifications
You must be signed in to change notification settings - Fork 227
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
Support go modules #194
Merged
alexellis
merged 1 commit into
openfaas:master
from
LucasRoesler:feature-go-mod-support-via-build-args
Feb 4, 2020
Merged
Support go modules #194
Changes from all commits
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module handler | ||
|
||
go 1.13 | ||
|
||
replace handler/function => ./function |
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 |
---|---|---|
@@ -1,32 +1,41 @@ | ||
FROM openfaas/classic-watchdog:0.18.1 as watchdog | ||
FROM golang:1.12-alpine3.11 as builder | ||
FROM golang:1.13-alpine3.11 as builder | ||
|
||
# Allows you to add additional packages via build-arg | ||
ARG ADDITIONAL_PACKAGE | ||
ARG CGO_ENABLED=0 | ||
ARG GO111MODULE="off" | ||
ARG GOPROXY="" | ||
ARG GOFLAGS="" | ||
|
||
COPY --from=watchdog /fwatchdog /usr/bin/fwatchdog | ||
RUN chmod +x /usr/bin/fwatchdog | ||
|
||
ENV CGO_ENABLED=0 | ||
|
||
WORKDIR /go/src/handler | ||
COPY . . | ||
|
||
# Add user overrides to the root go.mod, which is the only place "replace" can be used | ||
RUN cat function/GO_REPLACE.txt >> ./go.mod || exit 0 | ||
|
||
# Run a gofmt and exclude all vendored code. | ||
RUN test -z "$(gofmt -l $(find . -type f -name '*.go' -not -path "./vendor/*" -not -path "./function/vendor/*"))" || { echo "Run \"gofmt -s -w\" on your Golang code"; exit 1; } | ||
|
||
WORKDIR /go/src/handler/function | ||
|
||
RUN go test ./... -cover | ||
|
||
WORKDIR /go/src/handler | ||
|
||
RUN CGO_ENABLED=${CGO_ENABLED} GOOS=linux \ | ||
go build --ldflags "-s -w" -a -installsuffix cgo -o handler . && \ | ||
go test $(go list ./... | grep -v /vendor/) -cover | ||
go build --ldflags "-s -w" -a -installsuffix cgo -o handler . | ||
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. Should the 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. This ENV variable is read by the go command automatically https://golang.org/cmd/go/#hdr-Environment_variables |
||
|
||
FROM alpine:3.11 | ||
RUN apk --no-cache add \ | ||
ca-certificates | ||
|
||
# Add non root user | ||
RUN addgroup -S app && adduser -S -g app app | ||
RUN mkdir -p /home/app | ||
RUN apk --no-cache add ca-certificates \ | ||
&& addgroup -S app && adduser -S -g app app \ | ||
&& mkdir -p /home/app \ | ||
&& chown app /home/app | ||
|
||
WORKDIR /home/app | ||
|
||
|
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,5 @@ | ||
module handler | ||
|
||
go 1.13 | ||
|
||
replace handler/function => ./function |
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
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.
I find the GO_REPLACE pattern a bit confusing, have you consider merging
go.mod
instead? That way the function writer still has a regulargo.mod
that can be linted / validated. This project seems like it could do the trick: https://github.com/brendanjryan/modmergeThere 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.
Or maybe even go the multi-module approach and have the
main
code can be a module and the function code a different one? If a package name is enforced we might not even need the replace. https://github.com/golang/go/wiki/Modules#faqs--multi-module-repositories has an overview of that approach.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.
This multi-module approach is what we are doing here, but ... go does not follow replaces in modules, so if you need to use a replace in your function handler module, it will not be respected in the parent template module. This GO_REPLACE is a way for us to explicitly allow overriding the replaces in the parent function module.
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.
#194 (comment)