debian-mirror-gitlab/doc/user/packages/go_proxy/index.md

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

181 lines
6.8 KiB
Markdown
Raw Normal View History

2020-06-23 00:09:42 +05:30
---
stage: Package
group: Package
2021-02-22 17:27:13 +05:30
info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/engineering/ux/technical-writing/#assignments
2020-06-23 00:09:42 +05:30
---
2021-03-11 19:13:27 +05:30
# Go proxy for GitLab **(FREE)**
2020-06-23 00:09:42 +05:30
2021-12-11 22:18:48 +05:30
> - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/27376) in GitLab 13.1.
2020-06-23 00:09:42 +05:30
> - It's deployed behind a feature flag, disabled by default.
2021-01-29 00:20:46 +05:30
> - It's disabled for GitLab.com.
2020-10-24 23:57:45 +05:30
> - To use it in GitLab self-managed instances, ask a GitLab administrator to [enable it](#enable-the-go-proxy).
2021-12-11 22:18:48 +05:30
> - [Moved](https://gitlab.com/gitlab-org/gitlab/-/issues/221259) from GitLab Premium to GitLab Free in 13.3.
2020-06-23 00:09:42 +05:30
2021-11-18 22:05:49 +05:30
WARNING:
The Go package registry for GitLab is under development and isn't ready for production use due to
limited functionality. This [epic](https://gitlab.com/groups/gitlab-org/-/epics/3043) details the remaining
work and timelines to make it production ready.
2020-06-23 00:09:42 +05:30
With the Go proxy for GitLab, every project in GitLab can be fetched with the
[Go proxy protocol](https://proxy.golang.org/).
2021-04-29 21:17:54 +05:30
For documentation of the specific API endpoints that the Go Proxy uses, see the
[Go Proxy API documentation](../../../api/packages/go_proxy.md).
2021-01-29 00:20:46 +05:30
## Enable the Go proxy
2020-06-23 00:09:42 +05:30
2021-01-29 00:20:46 +05:30
The Go proxy for GitLab is under development, and isn't ready for production use
due to [potential performance issues with large repositories](https://gitlab.com/gitlab-org/gitlab/-/issues/218083).
2020-06-23 00:09:42 +05:30
2021-01-29 00:20:46 +05:30
It's deployed behind a feature flag that is _disabled by default_.
2020-06-23 00:09:42 +05:30
[GitLab administrators with access to the GitLab Rails console](../../../administration/feature_flags.md)
can enable it for your instance.
To enable it:
```ruby
Feature.enable(:go_proxy) # or
```
To disable it:
```ruby
Feature.disable(:go_proxy)
```
To enable or disable it for specific projects:
```ruby
Feature.enable(:go_proxy, Project.find(1))
Feature.disable(:go_proxy, Project.find(2))
```
2021-02-22 17:27:13 +05:30
NOTE:
2021-01-29 00:20:46 +05:30
Even if it's enabled, GitLab doesn't display Go modules in the **Package Registry**.
Follow [this issue](https://gitlab.com/gitlab-org/gitlab/-/issues/213770) for
details.
2020-06-23 00:09:42 +05:30
## Add GitLab as a Go proxy
2021-01-29 00:20:46 +05:30
To use GitLab as a Go proxy, you must be using Go 1.13 or later.
2020-06-23 00:09:42 +05:30
2021-01-29 00:20:46 +05:30
The available proxy endpoint is for fetching modules by project: `/api/v4/projects/:id/packages/go`
2020-06-23 00:09:42 +05:30
2021-01-29 00:20:46 +05:30
To fetch Go modules from GitLab, add the project-specific endpoint to `GOPROXY`.
2020-06-23 00:09:42 +05:30
2021-01-29 00:20:46 +05:30
Go queries the endpoint and falls back to the default behavior:
2020-06-23 00:09:42 +05:30
```shell
2021-01-29 00:20:46 +05:30
go env -w GOPROXY='https://gitlab.example.com/api/v4/projects/1234/packages/go,https://proxy.golang.org,direct'
2020-06-23 00:09:42 +05:30
```
2021-01-29 00:20:46 +05:30
With this configuration, Go fetches dependencies in this order:
2020-06-23 00:09:42 +05:30
2021-01-29 00:20:46 +05:30
1. Go attempts to fetch from the project-specific Go proxy.
1. Go attempts to fetch from [proxy.golang.org](https://proxy.golang.org).
1. Go fetches directly with version control system operations (like `git clone`,
2020-06-23 00:09:42 +05:30
`svn checkout`, and so on).
2021-01-29 00:20:46 +05:30
If `GOPROXY` isn't specified, Go follows steps 2 and 3, which corresponds to
setting `GOPROXY` to `https://proxy.golang.org,direct`. If `GOPROXY`
contains only the project-specific endpoint, Go queries only that endpoint.
For details about how to set Go environment variables, see
[Set environment variables](#set-environment-variables).
For details about configuring `GOPROXY`, see
[Dependency Management in Go > Proxies](../../../development/go_guide/dependencies.md#proxies).
2020-06-23 00:09:42 +05:30
## Fetch modules from private projects
2021-01-29 00:20:46 +05:30
`go` doesn't support transmitting credentials over insecure connections. The
following steps work only if GitLab is configured for HTTPS:
2020-06-23 00:09:42 +05:30
1. Configure Go to include HTTP basic authentication credentials when fetching
from the Go proxy for GitLab.
1. Configure Go to skip downloading of checksums for private GitLab projects
from the public checksum database.
### Enable request authentication
Create a [personal access token](../../profile/personal_access_tokens.md) with
2021-01-29 00:20:46 +05:30
the scope set to `api` or `read_api`.
2020-06-23 00:09:42 +05:30
2021-04-17 20:07:23 +05:30
Open your [`~/.netrc`](https://everything.curl.dev/usingcurl/netrc) file
2021-01-29 00:20:46 +05:30
and add the following text. Replace the variables in `< >` with your values.
2022-07-16 23:28:13 +05:30
WARNING:
If you use an environment variable called `NETRC`, Go will use its value
2022-07-23 23:45:48 +05:30
as a filename and ignore `~/.netrc`. If you intend to use `~/.netrc` in
2022-07-16 23:28:13 +05:30
the GitLab CI **do not use `NETRC` as an environment variable name**.
2021-01-29 00:20:46 +05:30
```plaintext
2020-06-23 00:09:42 +05:30
machine <url> login <username> password <token>
```
2021-01-29 00:20:46 +05:30
- `<url>`: The GitLab URL, for example `gitlab.com`.
- `<username>`: Your username.
- `<token>`: Your personal access token.
2020-06-23 00:09:42 +05:30
### Disable checksum database queries
2021-01-29 00:20:46 +05:30
When downloading dependencies with Go 1.13 and later, fetched sources are
validated against the checksum database `sum.golang.org`.
If the checksum of the fetched sources doesn't match the checksum from the
database, Go doesn't build the dependency.
Private modules fail to build because `sum.golang.org` can't fetch the source
of private modules, and so it cannot provide a checksum.
To resolve this issue, set `GONOSUMDB` to a comma-separated list of private
projects. For details about setting Go environment variables, see
[Set environment variables](#set-environment-variables). For more details about
disabling this feature of Go, see
[Dependency Management in Go > Checksums](../../../development/go_guide/dependencies.md#checksums).
2020-06-23 00:09:42 +05:30
2021-01-29 00:20:46 +05:30
For example, to disable checksum queries for `gitlab.com/my/project`, set
`GONOSUMDB`:
2020-06-23 00:09:42 +05:30
```shell
go env -w GONOSUMDB='gitlab.com/my/project,<previous value>'
```
## Working with Go
2021-01-29 00:20:46 +05:30
If you're unfamiliar with managing dependencies in Go, or Go in general, review
the following documentation:
2020-06-23 00:09:42 +05:30
- [Dependency Management in Go](../../../development/go_guide/dependencies.md)
2022-01-26 12:08:38 +05:30
- [Go Modules Reference](https://go.dev/ref/mod)
- [Documentation (`golang.org`)](https://go.dev/doc/)
2021-09-30 23:02:18 +05:30
- [Learn (`go.dev/learn`)](https://go.dev/learn/)
2020-06-23 00:09:42 +05:30
### Set environment variables
2021-01-29 00:20:46 +05:30
Go uses environment variables to control various features. You can manage these
variables in all the usual ways. However, Go 1.14 reads and writes Go
environment variables to and from a special Go environment file, `~/.go/env` by
default.
- If `GOENV` is set to a file, Go reads and writes to and from that file instead.
- If `GOENV` is not set but `GOPATH` is set, Go reads and writes `$GOPATH/env`.
2020-06-23 00:09:42 +05:30
Go environment variables can be read with `go env <var>` and, in Go 1.14 and
2021-01-29 00:20:46 +05:30
later, can be written with `go env -w <var>=<value>`. For example,
`go env GOPATH` or `go env -w GOPATH=/go`.
2020-06-23 00:09:42 +05:30
### Release a module
Go modules and module versions are defined by source repositories, such as Git,
2021-01-29 00:20:46 +05:30
SVN, and Mercurial. A module is a repository that contains `go.mod` and Go
2021-02-22 17:27:13 +05:30
files. Module versions are defined by version control system (VCS) tags.
2021-01-29 00:20:46 +05:30
To publish a module, push `go.mod` and source files to a VCS repository. To
publish a module version, push a VCS tag.
See [Dependency Management in Go > Versioning](../../../development/go_guide/dependencies.md#versioning)
for more details about what constitutes a valid module or module version.