Sail Athens Swiftly Upstream with GoCenter

 

UPDATE: As of May 1, 2021 – GoCenter central repository has been sunset and all features deprecated. For more information on the sunsetting of the centers read the deprecation blog post

 

It seems as if everyone is launching their craft into the waters of Go. Developed by Google, Go (or GoLang) has been adopted by many other major companies for developing large-scale projects.

JFrog has embraced Go too, writing the JFrog CLI and JFrog Xray in Go, and making GoCenter, a public repository for Go modules, available to the community.

That growing acceptance of Go encouraged a group of engineers in support of Gophersource to launch Project Athens last year as an open source project. Athens is a Go modules repository that you can host privately on your own infrastructure. It stores immutable modules from public code and your private code, so your builds pull dependencies from Athens’ repository, instead of directly from a version control system like GitHub.

Riding the Currents

Athens and GoCenter perform some similar functions, and even acts as a kind of Artifactory Virtual Repository for both local and remote Go dependencies. For organizations working primarily in Go, Athens is a powerful and popular solution for Go modules.

An important feature of Athens is the ability to use an upstream repository for the Go modules it delivers. When the upstream repository is configured for Direct Access, Athens will try to fetch every requested Go module from the upstream repository, instead of from its source in a version control system (for example, GitHub), or its own cache.

This can be especially useful when your system uses multiple Athens servers, to keep them in sync and be certain that every build in your organization that uses a given version of a Go module has precisely the same one.

When you configure Athens to use GoCenter as an upstream repository, Athens will attempt to fulfill every request for a Go module from GoCenter’s repository of over 50,000 (and growing!) public modules. Each versioned module held by GoCenter is immutable, and will never be deleted.

In this way, you can use Athens and all of its great features for Go development, while benefiting from the guaranteed immutability and availability of the versioned modules delivered from GoCenter.

Keeping All Boats Afloat

Once Athens is configured for Direct Access mode to use GoCenter as an upstream repository, it will no longer automatically pull Go modules from their source, or from the Athens cache. If a Go module isn’t found in GoCenter, it will return a 404 Not Found error, causing the build to fail.

If the module is a public one, you can remedy this by submitting an inclusion request to GoCenter for that module. Once approved and processed, an immutable version of that Go module will be available to your build. It will also help the Go community, by making it available to everyone who uses GoCenter.

If a needed modules is in a private repository (or you can’t or don’t want to add a public module to GoCenter), then you can declare the module explicitly as a filter in the configuration file (using “+”).  When you do, Athens will bypass GoCenter to fetch that module from its source, and cache it in Athens for future requests. You can declare as many of these modules as you need for your builds to succeed.

Configuring Athens to Use GoCenter

By default, Athens fetches module code from an upstream VCS like github.com, but this can be configured to use GoCenter as your Go modules repository.

  1. Create a filter file (e.g /usr/local/lib/FilterForGoCenter) with the letter D (stands for “direct access”) on the first line. You can also declare any of your private modules that are to be found outside of GoCenter. For details, see the documentation on Filtering Modules.
    
    # FilterFile for fetching modules directly from an upstream repository (GoCenter)
    # - Specify Direct Access
    D
    # - Declare the source of all modules that won’t be found in GoCenter
    + github.com/myGoModule/my-private-module-for-go

     

  2. If you’re not using a config file, create a new config file (based on the sample config.dev.toml) and edit values to match your environment. Additionally in the current or new config file, set the following parameters as suggested:
    FilterFile = "/usr/local/lib/FilterForGoCenter"
    GlobalEndpoint = "https://gocenter.io"

     

  3. Restart Athens specifying the updated current or new config file.
    $ cd 
    $ ./proxy  -config_file myconfig.dev.toml
  4. Verify the new configuration using the “Try out Athens” walkthrough example.

Hoist the Sails and Go

GoCenter and Athens both seek to strengthen and diversify the Go ecosystem, and we know you want to be able to choose the tools you feel work best for you. If you’re already using Athens, using GoCenter as your upstream repository lets you benefit from the best features of each.

If you also use other software technologies, like Docker, Helm, npm or Maven, you might also want to give JFrog  Artifactory a try, to see how this powerful repository manager can bring insight into your software delivery supply chain. In addition to your Go modules and builds, this universal solution can help you control binaries in all the ways you use them.

We’ll continue to work with other Go projects, and we’re proud to join with Athens to help the developer community to get Go-ing.