Go at Full Speed with GoCenter

JFrog GoCenter: To Boldly Go

As Go programming accelerates, becoming one of the world’s fastest growing software languages, trying to create robust and reliable pipelines without an immutable repository is challenging. That’s because Go modules (reusable Go packages of code) that applications include as dependencies must be resolved from among thousands of independent source code repositories, each of which may be maintained with varying discipline. As such, the need for Go packages to be more predictable, immutable and manageable in a publicly-accessible repository has arisen.

GoCenter solves this developer pain by serving a public central repository of Go modules which provides repeatable and fast module resolution. GoCenter automatically processes and validates Go projects directly from source code repositories into immutable, versioned modules, making them freely available to the Go developer community. In this way, we aim to empower the Go community to reliably generate reproducible builds of their Go applications.

Introducing GoCenter

GoCenter provides the ability to resolve a module through a public go proxy including the ability to search for modules via a hosted free service. At launch, GoCenter is already populated with modules for thousands of the most popular Go projects that your builds can make use of right away.

GoCenter on start

Developers can also submit their own Go projects for inclusion in GoCenter, to make them broadly available to the Go developer community.

Submitting a Go project to GoCenter

This central repository of pre-packaged, versioned modules makes it unnecessary for each developer or team to build its own library of the public modules they consume, eliminating a significant cost to adoption of the Go language.

In addition, if you have your own Artifactory instance you can configure an on-prem remote repository of GoCenter to gain full local control of reproducing builds, and as a precaution against connection outages.

Build Go projects with GoCenter

To build your Go projects you will first need to have the Go client (version 1.11.0 or newer) installed. Once you have Go installed, there are three ways to resolve a Go module from GoCenter: using goc, using the Go client, or setting up a repository manager such as Artifactory to proxy GoCenter.

Using goc

The recommended way to use GoCenter in your builds is through the goc utility. The goc utility is a wrapper for the go client that correctly builds Go applications using packages from GoCenter without the need for manual setup.

To install goc, use the following curl command or follow installation instructions in goc‘s GitHub page:

$ curl -fL https://getgoc.gocenter.io | sh

Then, from your project’s root directory, run any command as you would run go, for example:

$ goc build

The goc utility automatically assigns GOPROXY to GoCenter, so that Go dependencies will be primarily resolved from that repository. For packages not found in GoCenter, goc will attempt to resolve them from source control to better assure your build will succeed.

The go client alone will not perform this secondary fallback (see below for more explanation), so we recommend using goc at least until GoCenter grows to serve all the dependencies most  Go developers are likely to need.

Using the Go client

As noted above, we do not recommend building through the go client directly when using GoCenter, since your build will fail if a dependency is not found there. For details on this limitation of the go client, see this issue and the associated pull request. Most developers should use goc instead.

However, if you wish to use go with full awareness of this limitation, use this procedure.

To make the build of your Go project draw from GoCenter for dependent modules, set GOPROXY to the URL for GoCenter (https://gocenter.io):

$ export GOPROXY=https://gocenter.io

Now you can use the Go client to build your project:

$ go build

Setting up a repository manager to proxy GoCenter

If you are using a repository manager such as Artifactory, you only need to point GOPROXY at your repository manager and make sure GoCenter is included as a remote repository.

To define a remote repository in Artifactory to proxy GoCenter, follow the steps below:

  1. Create a new remote repository and set Go to be its Package Type
  2. Set the Repository Key value, and enter https://gocenter.io/ in the URL field
  3. Click Save & Finish

You can also create a virtual repository that aggregates packages from both your local Go registry and remote repositories.

Once Artifactory is configured to work with GoCenter, you can use go to build against Artifactory using the standard GOPROXY approach. Please note that based on the settings of your Artifactory server you’ll need to take care of a proper client authorization, which may be challenging as currently go client doesn’t send credentials when retrieving modules. As such, we recommend using JFrog CLI to build your projects when using Artifactory to proxy GoCenter. Once JFrog CLI is configured to work with Artifactory, use jfrog rt go build (or other Go commands, prefixed with jfrog rt) to retrieve dependencies from Artifactory and build your Go project.

A benefit of JFrog CLI is that it allows you to easily upload the modules which were created for a certain build to Artifactory. It also provides the built-in support for generating and publishing metadata about the build process. For more information, see the JFrog CLI documentation.

Search for modules

The search box in the GoCenter landing page helps you to search by a particular module name (for example, “iris”). When the search is performed GoCenter will list the modules that match or partially match the searched-for name.

GoCenter search

Clicking on a result displays the list of versions processed by GoCenter.

GoCenter search results

The list of processed versions is color-coded to indicate its availability status:

Green means the module version is included in GoCenter, and available.

Red means the module failed to be included, and is not available.

Gray means the module is in the process of being included, but not yet available.

The search results also display, if any, the list of versions that are found in the relevant Git repository of the Go project, but are not yet in GoCenter. If there are such missing versions, you are offered the opportunity to add them to GoCenter by clicking on the ‘Add missing version(s)’ .

Request to include your Go modules

If you want to add your Go project to GoCenter to make it available to the Go developer community, you can submit it in an inclusion request.

You can first perform a search for the module name you want to include. If your module doesn’t exist, you can then click the offered Add icon to request to add your module.

Once you do, you will be presented with the Inclusion Request form.

Here, you can enter the URL of the Go module you are requesting to be included. You can view the inclusion status of the project in the search results for that module.

GoCenter will validate the inclusion request, based on these minimum criteria:

  • The Go module is in a public Git repo belonging to either gihub.com or gopkg.in
  • The repo is not set as archived
  • The Git repo must have at least 3 stars

Keeping Go Moving

Since it was first conceived at Google in 2007, Go (also called GoLang) has quickly become one of the most popular programming languages. In fact, both Helm and Kubernetes are written in Go, and developers in a 2017 survey ranked it highest in preference, with 67 percent reporting programming in Go at work.

For this reason, we expect GoCenter will provide an essential service to the growing Go developer community, and help make Go more fully compatible with the needs of DevOps.

You can explore GoCenter through your web browser at https://gocenter.io. You will likely find the Go packages you regularly use already included and available for your builds. If not, please submit an inclusion request for the package.

As a Go registry of versioned modules, GoCenter can be referenced through any CI server or binary repository manager for your builds. But the JFrog CLI and Artifactory make it especially easy.

Want more in-depth technical information about GoCenter? Take a look at the GoCenter Github repository.

If you’re not already using Artifactory, you can start your free trial to get moving with Artifactory and Go.