doc: Improve wording on “Go on Docker Hub” use case
Signed-off-by: Helder Correia <174525+helderco@users.noreply.github.com>
This commit is contained in:
parent
d8fbbf5055
commit
995881ffb5
@ -30,8 +30,8 @@ dagger.#Plan & {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run go unit test
|
// Run go unit tests
|
||||||
"unit-test": go.#Test & {
|
unitTest: go.#Test & {
|
||||||
source: _code
|
source: _code
|
||||||
package: "./..."
|
package: "./..."
|
||||||
input: _base.output
|
input: _base.output
|
||||||
@ -43,21 +43,17 @@ dagger.#Plan & {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Build docker image (depends on build)
|
// Build docker image (depends on build)
|
||||||
image: {
|
image: docker.#Build & {
|
||||||
_base: alpine.#Build & {}
|
steps: [
|
||||||
|
alpine.#Build,
|
||||||
docker.#Build & {
|
docker.#Copy & {
|
||||||
steps: [
|
contents: build.output
|
||||||
docker.#Copy & {
|
dest: "/usr/bin"
|
||||||
input: _base.output
|
},
|
||||||
contents: build.output
|
docker.#Set & {
|
||||||
dest: "/usr/bin"
|
config: cmd: ["<path/to/binary>"]
|
||||||
},
|
},
|
||||||
docker.#Set & {
|
]
|
||||||
config: cmd: ["<path/to/binary>"]
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Push image to remote registry (depends on image)
|
// Push image to remote registry (depends on image)
|
||||||
@ -69,7 +65,7 @@ dagger.#Plan & {
|
|||||||
"image": image.output
|
"image": image.output
|
||||||
dest: "\(_dockerUsername)/<my_repository>"
|
dest: "\(_dockerUsername)/<my_repository>"
|
||||||
auth: {
|
auth: {
|
||||||
username: "\(_dockerUsername)"
|
username: _dockerUsername
|
||||||
secret: client.env.DOCKER_PASSWORD
|
secret: client.env.DOCKER_PASSWORD
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,19 +4,16 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Build docker image (depends on build)
|
// Build docker image (depends on build)
|
||||||
image: {
|
image: docker.#Build & {
|
||||||
_base: alpine.#Build & {}
|
steps: [
|
||||||
|
alpine.#Build,
|
||||||
docker.#Build & {
|
docker.#Copy & {
|
||||||
steps: [
|
input: _base.output
|
||||||
docker.#Copy & {
|
contents: build.output
|
||||||
input: _base.output
|
dest: "/usr/bin"
|
||||||
contents: build.output
|
},
|
||||||
dest: "/usr/bin"
|
docker.#Set & {
|
||||||
},
|
config: cmd: ["</path/to/binary>"]
|
||||||
docker.#Set & {
|
},
|
||||||
config: cmd: ["</path/to/binary>"]
|
]
|
||||||
},
|
}
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -7,8 +7,8 @@ push: {
|
|||||||
"image": image.output
|
"image": image.output
|
||||||
dest: "\(_dockerUsername)/<my_repository>"
|
dest: "\(_dockerUsername)/<my_repository>"
|
||||||
auth: {
|
auth: {
|
||||||
username: "\(_dockerUsername)"
|
username: _dockerUsername
|
||||||
secret: client.env.DOCKER_PASSWORD
|
secret: client.env.DOCKER_PASSWORD
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// Run go unit test
|
// Run go unit tests
|
||||||
"unit-test": go.#Test & {
|
unitTest: go.#Test & {
|
||||||
source: _code
|
source: _code
|
||||||
package: "./..."
|
package: "./..."
|
||||||
input: _base.output
|
input: _base.output
|
||||||
|
@ -5,22 +5,21 @@ displayed_sidebar: europa
|
|||||||
|
|
||||||
# Go on Docker Hub
|
# Go on Docker Hub
|
||||||
|
|
||||||
Dagger stand as a powerful CI/CD tool that works on any environment.
|
Dagger stands as a powerful CI/CD tool that works on any environment.
|
||||||
|
|
||||||
For instance, you can use [go package](https://github.com/dagger/dagger/tree/main/pkg/universe.dagger.io/go)
|
For instance, you can use the [Dagger Go package](https://github.com/dagger/dagger/tree/main/pkg/universe.dagger.io/go)
|
||||||
to control the whole CI/CD process, from test to push into a remote registry.
|
to control the whole CI/CD process, from testing to pushing into a remote registry.
|
||||||
|
|
||||||
:::tip
|
:::tip
|
||||||
Following examples can be used as a template for any standalone go project.
|
The following examples can be used as a template for any standalone Go project.
|
||||||
:::
|
:::
|
||||||
|
|
||||||
## Retrieve Go project
|
## Retrieve Go project
|
||||||
|
|
||||||
First important step is to make go project accessible in dagger plan.
|
The first step is to make your Go project accessible to the Dagger plan.
|
||||||
|
|
||||||
You can indeed choose which files to include in the filesystem.
|
You can indeed choose which files to include. Since it's a Golang project
|
||||||
Since it's a Golang project, filesystem should contain module and every go
|
it should contain the module and all Go source files:
|
||||||
source files:
|
|
||||||
|
|
||||||
```cue file=../tests/use-cases/ci-cd-for-go-project/retrieve-go-project/dagger.cue
|
```cue file=../tests/use-cases/ci-cd-for-go-project/retrieve-go-project/dagger.cue
|
||||||
```
|
```
|
||||||
@ -32,60 +31,59 @@ act as an alias.
|
|||||||
|
|
||||||
## Build a Go base image
|
## Build a Go base image
|
||||||
|
|
||||||
[Dagger go universe](https://github.com/dagger/dagger/tree/main/pkg/universe.dagger.io/go)
|
The [universe.dagger.io/go](https://github.com/dagger/dagger/tree/main/pkg/universe.dagger.io/go)
|
||||||
provide a [base image](https://github.com/dagger/dagger/blob/main/pkg/universe.dagger.io/go/image.cue)
|
package provides a [base image](https://github.com/dagger/dagger/blob/main/pkg/universe.dagger.io/go/image.cue)
|
||||||
to build your pipeline but your project may use `CGO` or any external dependencies.
|
to build your pipeline, but your project may use `CGO` or any external dependencies.
|
||||||
|
|
||||||
You can customize that base image to install required dependencies:
|
You can customize the base image to install required dependencies:
|
||||||
|
|
||||||
```cue file=../tests/use-cases/ci-cd-for-go-project/base.cue.fragment
|
```cue file=../tests/use-cases/ci-cd-for-go-project/base.cue.fragment
|
||||||
```
|
```
|
||||||
|
|
||||||
## Run unit test
|
## Run unit tests
|
||||||
|
|
||||||
Before deliver your application, you certainly want to run unit test.
|
Before delivering your application, you certainly want to run unit tests.
|
||||||
|
|
||||||
By using previous steps, you can use the [test](https://github.com/dagger/dagger/blob/main/pkg/universe.dagger.io/go/test.cue)
|
Use the [#Test](https://github.com/dagger/dagger/blob/main/pkg/universe.dagger.io/go/test.cue)
|
||||||
definition to run your unit test:
|
definition:
|
||||||
|
|
||||||
```cue file=../tests/use-cases/ci-cd-for-go-project/test.cue.fragment
|
```cue file=../tests/use-cases/ci-cd-for-go-project/test.cue.fragment
|
||||||
```
|
```
|
||||||
|
|
||||||
<!-- FIXME(TomChv): we should write a bunch of documentation about TDD with dagger -->
|
<!-- FIXME(TomChv): we should write a bunch of documentation about TDD with dagger -->
|
||||||
:::tip
|
:::tip
|
||||||
You can also use dagger to write integration tests
|
You can also use Dagger to write integration tests.
|
||||||
:::
|
:::
|
||||||
|
|
||||||
## Build Go binary
|
## Build Go binary
|
||||||
|
|
||||||
To put your go project on docker hub, you first need to compile a binary.
|
To put your Go project on Docker Hub, you first need to compile a binary.
|
||||||
|
|
||||||
Go universe expose a [build](https://github.com/dagger/dagger/blob/main/pkg/universe.dagger.io/go/build.cue)
|
Use the [#Build](https://github.com/dagger/dagger/blob/main/pkg/universe.dagger.io/go/build.cue)
|
||||||
definition so you can build a binary:
|
definition to do that:
|
||||||
|
|
||||||
```cue file=../tests/use-cases/ci-cd-for-go-project/build.cue.fragment
|
```cue file=../tests/use-cases/ci-cd-for-go-project/build.cue.fragment
|
||||||
```
|
```
|
||||||
|
|
||||||
:::tip
|
:::tip
|
||||||
You can control the binary platform with `os` and `arch` field.
|
You can control the binary platform with `os` and `arch` fields.
|
||||||
:::
|
:::
|
||||||
|
|
||||||
## Prepare docker image
|
## Prepare docker image
|
||||||
|
|
||||||
To make it usable by other user, you must put your binary in an image and set an entrypoint.
|
To make it usable for other users, you must put your binary in an image and set an entrypoint.
|
||||||
|
|
||||||
For optimisation purpose, you can use alpine as base image to contain your binary:
|
For optimization purposes, you can use alpine as the base image to contain your binary:
|
||||||
|
|
||||||
```cue file=../tests/use-cases/ci-cd-for-go-project/image.cue.fragment
|
```cue file=../tests/use-cases/ci-cd-for-go-project/image.cue.fragment
|
||||||
```
|
```
|
||||||
|
|
||||||
## Push to Docker Hub
|
## Push to Docker Hub
|
||||||
|
|
||||||
To push an image to docker hub, you will need to forward credential to allow
|
To push an image to Docker Hub, you will need your private credentials.
|
||||||
dagger push.
|
|
||||||
|
|
||||||
To not hard code your docker password in the plan, you can retrieve it as an
|
To not hard code your docker password in the plan, you can retrieve it
|
||||||
environment value:
|
from your environment:
|
||||||
|
|
||||||
```cue
|
```cue
|
||||||
dagger.#Plan & {
|
dagger.#Plan & {
|
||||||
@ -104,7 +102,7 @@ You can now push your image:
|
|||||||
|
|
||||||
## Complete CI/CD
|
## Complete CI/CD
|
||||||
|
|
||||||
After merging all examples, you will have a complete CI/CD to deliver a go
|
After merging all examples, you will have a complete CI/CD to deliver a Go
|
||||||
binary on Docker Hub.
|
binary on Docker Hub.
|
||||||
|
|
||||||
```cue file=../tests/use-cases/ci-cd-for-go-project/complete-ci-cd/dagger.cue
|
```cue file=../tests/use-cases/ci-cd-for-go-project/complete-ci-cd/dagger.cue
|
||||||
|
Reference in New Issue
Block a user