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
- GitHub releases
- Docker images
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.
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
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.