Skip to content
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

Fix vendoring for golang-http #83

Merged
merged 1 commit into from
Oct 12, 2022
Merged

Fix vendoring for golang-http #83

merged 1 commit into from
Oct 12, 2022

Conversation

alexellis
Copy link
Member

@alexellis alexellis commented Oct 11, 2022

Signed-off-by: Alex Ellis (OpenFaaS Ltd) [email protected]

Description

Fix vendoring for golang-http by reverting to method prior to workspaces

How Has This Been Tested?

Tested with a private Go module which was vendored, setting GO111MODULE: off in build_args in stack.yml

I also created a nested package called pkg and referenced it as "handler/function/pkg" from handler.go which worked as expected.

Closes: #78

How are existing users impacted? What migration steps/scripts do we need?

Imports remained the same, but we will need to check docs and blog posts

https://www.openfaas.com/blog/golang-deep-dive/

https://github.com/openfaas/golang-http-template#20-golang-http

Checklist:

I have:

  • updated the documentation and/or roadmap (if required)
  • read the CONTRIBUTION guide
  • signed-off my commits with git commit -s
  • added unit tests

For the privately vendor code:

version: 1.0
provider:
  name: openfaas
  gateway: http://127.0.0.1:8080
functions:
  jwtme:
    lang: golang-http
    handler: ./jwtme
    image: alexellis2/jwtme:latest
    build_args:
      GO111MODULE: off
      GOFLAGS: -mod=vendor

For using Go modules w/o any vendoring:

package function

import (
        "fmt"
        "net/http"

        handler "github.com/openfaas/templates-sdk/go-http"
        "github.com/sirupsen/logrus"
)

// Handle a function invocation
func Handle(req handler.Request) (handler.Response, error) {
        var err error

        logrus.Info("Function started")

        message := fmt.Sprintf("Body: %s", string(req.Body))

        return handler.Response{
                Body:       []byte(message),
                StatusCode: http.StatusOK,
        }, err
}

The stack.yml file was unchanged.

@alexellis
Copy link
Member Author

@LucasRoesler @mrwormhole

@alexellis alexellis force-pushed the fix-vendoring-http branch 2 times, most recently from 7ad3f59 to f1b01c6 Compare October 11, 2022 19:21
Tested with a private Go module which was vendored, setting
GO111MODULE: off in build_args in stack.yml

I also created a nested package called pkg and referenced it
as "handler/function/pkg" from handler.go which worked as
expected.

Closes: #78

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
@mrwormhole
Copy link
Contributor

mrwormhole commented Oct 11, 2022

https://www.diffchecker.com/lhoTkAHq shall we keep remove_workspaces for ./function/go.work? does the arm build still break?

@@ -26,13 +26,16 @@ ENV CGO_ENABLED=${CGO_ENABLED}
# 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; }

RUN sh ./modules-cleanup.sh
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

found it, gotta do the shell script right before test -z

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexellis
Copy link
Member Author

@mrwormhole sorry, what question are you asking?

@mrwormhole
Copy link
Contributor

mrwormhole commented Oct 11, 2022

@alexellis is ARM build running successfully? before the changes, we did run modules-cleanup.sh right before test -z command

also second thing, dockerignore file should point to function/vendor/github.com/openfaas-incubator/go-function-sdk instead of function/vendor/github.com/openfaas/go-function-sdk

@alexellis
Copy link
Member Author

Why? There is no repo in openfaas-incubator? That's deprecated.

@alexellis alexellis merged commit f937a36 into master Oct 12, 2022
@alexellis alexellis deleted the fix-vendoring-http branch October 12, 2022 08:15
@alexellis
Copy link
Member Author

This is now available for pinning:

https://github.com/openfaas/golang-http-template/releases/tag/0.8.0

cc @willfore - this change makes vendoring private Go modules possible again with golang-http.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to use vendoring with golang-http
2 participants