O.1 docs is deprecated. Let's inform user to switch the the latest version Signed-off-by: user.email <jf@dagger.io>
3.1 KiB
slug | displayed_sidebar |
---|---|
/1219/go-docker-hub | 0.2 |
Go on Docker Hub
Dagger stands as a powerful CI/CD tool that works on any environment.
For instance, you can use the Dagger Go package to control the whole CI/CD process, from testing to pushing into a remote registry.
:::tip The following examples can be used as a template for any standalone Go project. :::
Retrieve Go project
The first step is to make your Go project accessible to the Dagger plan.
You can indeed choose which files to include. Since it's a Golang project it should contain the module and all Go source files:
:::tip To make it more accessible in actions, you can set a private field that will act as an alias. :::
Build a Go base image
The universe.dagger.io/go
package provides a base image
to build your pipeline, but your project may use CGO
or any external dependencies.
You can customize the base image to install required dependencies:
Run unit tests
Before delivering your application, you certainly want to run unit tests.
Use the #Test definition:
:::tip You can also use Dagger to write integration tests. :::
Build Go binary
To put your Go project on Docker Hub, you first need to compile a binary.
Use the #Build definition to do that:
:::tip
You can control the binary platform with os
and arch
fields.
:::
Prepare docker image
To make it usable for other users, you must put your binary in an image and set an entrypoint.
For optimization purposes, you can use alpine as the base image to contain your binary:
Push to Docker Hub
To push an image to Docker Hub, you will need your private credentials.
To not hard code your docker password in the plan, you can retrieve it from your environment:
dagger.#Plan & {
client: {
// ...
env: DOCKER_PASSWORD: dagger.#Secret
}
}
You can now push your image:
Complete CI/CD
After merging all examples, you will have a complete CI/CD to deliver a Go binary on Docker Hub.
You can then use dagger do
to select which action you want to run.
Push multi-platform
Coming soon...