Compile and release a Go application
Using Codefresh pipelines
Goreleaser is a helper utility that allows you to easily create the following for Go applications:
- Binary packages for each OS/arch
- Archives
- GitHub releases
- Docker images
- Snap/RPM/deb/Homebrew
Codefresh can also create Docker images on its own, but Goreleaser is still useful for the binary artifact creation capability.
Run Goreleaser with docker
You can see the example project at https://github.com/codefresh-contrib/goreleaser-sample-app. The repository contains a simple Golang web application with a goreleaser configuration.
There is already a Docker image for Goreleaser so it is very easy to use it in Codefresh pipeline. In the most simple case you case run goreleaser in a freestyle step.
YAML
More typically however you also need to provide a GitHub token so that GitHub releases are also available. There are two ways to do that.
Create a CI pipeline that compiles/releases Go
In most cases you want to just reuse the Git integration already defined in Codefresh. This pipeline is using the GitHub token from Git integration in order to allow GitHub access.
codefresh.yml
Note that GoReleaser requires a GitHub API token (GITHUB_TOKEN
) with the repo
scope to deploy artifacts to GitHub.
Here we use cf_export and the codefresh CLI in order to ask Codefresh about the existing token (that was used in git integrations). In your case you need to change github-1
with the name of your GitHub integration.
It also possible to pass a GITHUB_TOKEN directly in the pipeline, if you don’t want to re-use the existing one. This is an alternative way of allowing Goreleaser to create GitHub releases.
You could also store the token in shared configuration. Regardless of the way you choose to pass the GitHub token, the final step is to make sure that your pipeline is only executed for tag events.
This means that this pipeline will not run on normal commits. It is also possible to use step conditionals for more complex cases.
Related articles
Codefresh YAML for pipeline definitions
Steps in pipelines
Creating pipelines
How Codefresh pipelines work