Go repositories are supported by Artifactory since version 5.11.0. To work with Go repositories you need to use JFrog CLI and the Go client.
In the root directory of the project, perform the following steps:
config
command:> jfrog rt config
> jfrog rt go build go
The build will probably error, failing to find one of the needed dependencies:
> go: rsc.io/quote@v1.5.2: unexpected status (https://username@artifactory.jfrog.io/artifactory/api/go/go/rsc.io/quote/@v/v1.5.2.info): 404 Not Found
> go: error loading module requirements
> [Error] exit status 1
That makes sense, the packages modules do not exist in the remote repository (GitHub). No despair, we can package them ourselves, and serve from a local repository instead. Whoever builds after us, won't know the difference!
--no-registry
option, to get the dependency sources from GitHub and let Go create modules out of them.> jfrog rt go build --no-registry
> jfrog rt go-publish go --self=false --deps=ALL
Now you can see the dependencies in Artifactory under go-local repository.
[Optional] to verify that you can use the modules from Artifactory now, you can delete the modules from the local cache (located at $GO_PATH/pkg/mod
). In this case they will be resolved from Artifactory in the next step.
Build the project with Go and resolve the uncached dependencies from Artifactory. If you deleted the cache, you'll see the go: downloading
messages when go downloads the missing dependencies from Artifactory. This will also declare the used dependencies in Artifactory Build Integration build-info metadata.
> jfrog rt go build go --build-name=my-build --build-number=1
Depending on your scenario, you might want to package your source files as a Go module and publish it to Artifactory to be used as a dependency, by you, or other team members.
> jfrog rt go-publish go v1.0.0 --build-name=my-build --build-number=1
> jfrog rt build-collect-env my-build 1
> jfrog rt build-publish my-build 1
Another (more common) use-case is to create a binary executable and publish it to Artifactory.
We recommend using the excellent GoReleaser tool for that. Check the documentation of GoReleaser to install it.
Although GoReleaser has a built-in support for Artifactory, we will use the JFrog CLI for actual deployment, and that to include the deployed artifacts in the build info metadata. (Note: pull request for build info support in GoReleaser is on its way)
First, you'll need a generic repository for the executables. Click Local Repository under Create Repositories in your username drop-down menu in Artifactory UI, and select Generic. We'll call it binary-releases-local
.
Next, let's init GoReleaser
> goreleaser init
--snapshot
flag to generate the binaries, but skip the deployment.> goreleaser --snapshot
> jfrog rt upload "dist/*.tar.gz" binary-releases-local --build-name=my-build --build-number=1
> jfrog rt build-collect-env my-build 1
> jfrog rt build-publish my-build 1