-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
x/pkgsite: local setup - tracking issue #40371
Comments
Hello @julieqiu If I can add color to the pain points of running locally, having to start a proxy isn't too much trouble, but the constraint of requiring https is a bigger barrier:
What do you think about relaxing this constraint? |
Change https://golang.org/cl/245639 mentions this issue: |
Rather than validating the URL in proxy.New, assume that the URL that is passed in is valid. This allows users to connect to a proxy running locally in direct proxy mode. For golang/go#40371 Change-Id: Id51cb27148987e58d214cef1c805b26b5138a6de Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/245639 Run-TryBot: Julie Qiu <julie@golang.org> TryBot-Result: kokoro <noreply+kokoro@google.com> Reviewed-by: Jonathan Amsterdam <jba@google.com>
@achille-roussel - done! Thanks for the feedback. |
To run Executables in docker containers can more easily publish their services on the host's networking interface if bound to https://github.com/golang/pkgsite/blob/ef183200d192b20102bb1246a86ae11de2d0738e/cmd/frontend/main.go#L170 to use a variable that is assigned by a flag instead of the |
We had to solve for this as well in the fork we maintain at https://github.com/segmentio/pkgsite: diff --git a/cmd/frontend/main.go b/cmd/frontend/main.go
index 5773d8e..e81022b 100644
--- a/cmd/frontend/main.go
+++ b/cmd/frontend/main.go
@@ -42,6 +42,7 @@ var (
"for direct proxy mode and frontend fetches")
directProxy = flag.Bool("direct_proxy", false, "if set to true, uses the module proxy referred to by this URL "+
"as a direct backend, bypassing the database")
+ httpAddr = flag.String("http", "localhost:8080", "address to listen for incoming requests on")
)
func main() {
@@ -167,7 +168,7 @@ func main() {
middleware.Timeout(54*time.Second),
middleware.Experiment(experimenter),
)
- addr := cfg.HostAddr("localhost:8080")
+ addr := cfg.HostAddr(*httpAddr)
log.Infof(ctx, "Listening on addr %s", addr)
log.Fatal(ctx, http.ListenAndServe(addr, mw(router)))
} Taking a closer look at the way the configuration is setup, it appears that if the // HostAddr returns the network on which to serve the primary HTTP service.
func (c *Config) HostAddr(dflt string) string {
if c.Port != "" {
return fmt.Sprintf(":%s", c.Port)
}
return dflt
} |
Change https://golang.org/cl/260779 mentions this issue: |
Create -local and -gopath_mode flags to enable using a local datasource and loading local modules to memory. Updates golang/go#40371 Fixes golang/go#40159 Change-Id: I36941adde9c6b186d95b5792051854ac3d1a2ac8 Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/260779 Run-TryBot: Jonathan Amsterdam <jba@google.com> Trust: Jonathan Amsterdam <jba@google.com> TryBot-Result: kokoro <noreply+kokoro@google.com> Reviewed-by: Julie Qiu <julie@golang.org>
Functionality for running the pkgsite frontend locally is moved from cmd/frontend to cmd/pkgsite, since cmd/frontend is currently overloaded with flag options and running locally does not need all the dependencies for running cmd/frontend. Additional functionality will be added to cmd/pkgsite in future CLs. For golang/go#40371 Change-Id: I4230aa9539c94e01a68eda33cc6492ae377debff Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/290134 Reviewed-by: Jamal Carvalho <jamal@golang.org> Trust: Julie Qiu <julie@golang.org>
Change https://golang.org/cl/290134 mentions this issue: |
Change https://golang.org/cl/290135 mentions this issue: |
A -http flag is added which allows the user to specify which HTTP addr to listen in on. For golang/go#40371 Change-Id: Ibfe32281e9a821444df5e538fd7057f39318c546 Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/290135 Reviewed-by: Jonathan Amsterdam <jba@google.com> Trust: Julie Qiu <julie@golang.org>
I was redirected here from an issue requesting a flag in godoc for showing internal packages (for use during internal/company development purposes, to make it possible to easily browse internal APIs) - #12092 (comment). Thus (per the request for use cases in the main comment above), that's a use case me and several other people expressed interest in. If godoc is seen as "in maintenance mode" (which was quite a surprise to me), it would be nice if the plan for the new replacement tool was outlined here (?) more clearly, or something. Currently, the situation & status may appear unclear to community members (like me). |
A major stumbling Block for us is the inferior Support of private modules and APIs in turn. In our past, a dev-system local godoc helped us, even if that required developers to check out the API repo. godoc already was problematic when viewed from a typical private GitHub and Gitlab use case, as you can't get any static pages to be hosted. gopkg seems to make the situation even worse, as it now requires more and more infrastructure and doesn't scale down. |
Adding to the injury of pkgsite is that it doesn't support hot reloading when the local documentation changes as part of writing, updating, and maintaining module documentation, before tagging and pushing to a public repository. godoc did. |
@achille-roussel - how are you running your patched version of |
#!/bin/bash
set -e
if ! command -v pkgsite &>/dev/null; then
export PATH="$(go env GOPATH)/bin:$PATH"
if ! command -v pkgsite &>/dev/null; then
go install golang.org/x/pkgsite/cmd/pkgsite@master
fi
fi
# In case the user hasn't set an explicit installation location, avoid polluting
# our own project...
NPMBIN=$(cd $HOME && npm bin)
export PATH="$NPMBIN:$PATH"
if ! command -v browser-sync &>/dev/null; then
(cd $HOME && npm install browser-sync)
fi
if ! command -v nodemon &>/dev/null; then
(cd $HOME && npm install nodemon)
fi
# https://stackoverflow.com/a/2173421
trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT
# https://mdaverde.com/posts/golang-local-docs
browser-sync start --port 6060 --proxy localhost:6061 --reload-delay 2000 --reload-debounce 5000 --no-ui --no-open &
PKGSITE=$(which pkgsite)
nodemon --signal SIGTERM --watch './**/*' -e go --exec "browser-sync --port 6060 reload && $PKGSITE -http=localhost:6061 ."
|
I tried using pkgsite as a local/private documentation viewer and found that it was a poor replacement for godoc currently. In addition to the issues already listed here (and #57742 and #50229) I noticed:
|
Change https://go.dev/cl/474295 mentions this issue: |
Change https://go.dev/cl/475755 mentions this issue: |
This change adds a new goPackagesModuleGetter, which uses x/tools/go/packages to query package information for modules requested by the pkgsite command. Additionally, add new extension interfaces that allow getters to add support for search and content invalidation. The go/packages getter uses these extensions to implement search (via a simple fuzzy-matching algorithm copied from x/tools), and invalidation via statting package files. Along the way, refactor slightly for testing ergonomics. Updates golang/go#40371 Updates golang/go#50229 Fixes golang/go#54479 Change-Id: Iea91a4d6327707733cbbc4f74a9d93052f33e295 Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/474295 TryBot-Result: kokoro <noreply+kokoro@google.com> Run-TryBot: Robert Findley <rfindley@google.com> Reviewed-by: Jamal Carvalho <jamal@golang.org>
This CL contains several UI improvements when running pkgsite in local mode via cmd/pkgsite: - hide irrelevant or inaccurate content - fix a bug using -gopath_mode (trim the `go env GOPATH` output) - fix panics navigating to vuln pages - link the GO button to the root page, rather than go.dev - add quick-links to the homepage to browse local modules Also: - add -dev and -static flags, to facilitate development - replace TestBuildGetters with more cases in TestServer - fix some redundancy in setting the <title> element for pages; consolidate on using the basePage.HTMLTitle value Updates golang/go#40371 Change-Id: I459a0d0fd39897dd4f902dd023aec653a3fb12cd Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/475755 TryBot-Result: kokoro <noreply+kokoro@google.com> Reviewed-by: Jamal Carvalho <jamal@golang.org> Run-TryBot: Robert Findley <rfindley@google.com>
Hi folks. I've been using x/pkgsite/cmd/pkgsite recently and stumbled upon some of the problems cited here, so I added the following improvements:
Screencast below. I have additional plans to fix stdlib documentation to not require a network connection. Apart from that, is there anything else people need? I'd be willing to make additional changes now, while it is fresh in my mind. |
@findleyr thanks very much for your effort here! This definitely covers the bulk of the issues that I encountered when trying to use pkgsite as a local or private doc server as a replacement for godoc. I played around with it and for the most part everything looks great. I notice a couple of remaining regressions in comparison to local godoc:
Lest this sound too critical, I want to emphasize that I'm really grateful for your work on this. Your changes take pkgsite about 90% of the way from where it was to where I was hoping it would be for my use cases. Even without any further improvements I imagine I could mitigate the issues I mentioned on my end (such as by automatically triggering rebuilds when the code changes for (1) or by post-processing the HTML output for (2)). |
Thanks for testing it out, @cespare! Responses below.
I was worried about this. Yes, I squeezed the reloading logic into the existing APIs, all of which operate on modules. I will revisit this and push the reloading logic down so that it can reload packages individually. This would also make the initial rendering faster. I'm a little concerned about the additional complexity this may cause; we'll see how this works out.
Oh, interesting. I think it should be possible to fix this. I'll have a look.
This is https://go.dev/issue/58923, which I'll fix. TL;DR: the standard library has special handling in pkgsite, which cmd/pkgsite doesn't touch. As a result, when navigating to standard library packages they are downloaded rather than read from GOROOT. I plan to fix this by making the standard library handled just like any other module, at which point links should work. |
@hyangah I'd already edited the top comment. Is there something else you want me to include there? EDIT: Well, I've added #59542 to the list, which I thought would be a straightforward bug but in fact is related to being able to refresh at the package level: for vendored packages, we have no module dir. |
One other item we should add to the list is the ability to display unexported symbols on request. See for example:
|
Has anyone else gotten module versioning / browsing versions to work? Even with a local go proxy setup? |
Today, users can run pkgsite locally without setting up a local database by running:
go run cmd/frontend/main.go -direct_proxy -proxy_url=<your proxy URL>
See flags in
cmd/frontend/main.go
, and doc/frontend.md for docs.Doing so allows users to view the package documentation, overview, imports, and licenses tabs. Search and other tabs on the package page are not supported in direct proxy mode.
However, there are cases when a user might want to run pkgsite on their local machine, and be able to view a private repository that is not available via a proxy.
Tasks related to this topic:
Maybe:
This is an umbrella issue to discuss what features are needed for this to happen, so please comment on your use cases below. For discussions about hosting a private instance of pkgsite, including your own internal proxy, see #39827.
The text was updated successfully, but these errors were encountered: