Search code examples
gitnginxgobitbuckethaproxy

How do you support 'go get' using bitbucket server?


I would like to support requests of the form:

go get acme.com/component

where component is a git project stored in Bitbucket Server which can be retrieved via:

git clone http://acme.dev:7600/scm/project/component

The go 1.8 client does not know how to fetch the component based on the go get parameters so it does an HTTPS get (as per https://golang.org/cmd/go/#hdr-Remote_import_paths) of:

https://acme.com/component?go-get=1

In response it expects an HTTP 200 containing the following:

<head>
  <meta name="go-import" content="acme.com/component git http://acme.dev:7600/scm/project/component">
</head>

HAProxy is attractive because the Bitbucket Server SSL termination procedure uses it. It has a monitor-uri hack to return an HTTP response if it detects that the backend is responding to a specific URI but I don't think it's sufficiently flexible to handle different component names.

Does anyone know a way to handle this using HAProxy or, perhaps, another tool like NGinx?


Solution

  • For the purpose of conversation and because flexible generation of HTTP responses is useful I gave it a try using nginx - with a switch to ssh. The non-standard part of the configuration file has a rule to point the go client to the Bitbucket server:

    location ~ "^(/[^/]+)(/[^/]+)?" {
        if ($arg_go-get = "1") {
            return 200 '<html><head><meta name="go-import" content="acme.com$1$2 git ssh://acme.dev:7999$1$2"></head></html>';
        }
    }