Add dagger golang use case
Signed-off-by: Vasek - Tom C <tom.chauveau@epitech.eu>
This commit is contained in:
committed by
Vasek - Tom C
parent
21c6af0678
commit
2d3acc61e0
32
docs/tests/use-cases/ci-cd-for-go-project/build/dagger.cue
Normal file
32
docs/tests/use-cases/ci-cd-for-go-project/build/dagger.cue
Normal file
@@ -0,0 +1,32 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"dagger.io/dagger"
|
||||
"universe.dagger.io/go"
|
||||
)
|
||||
|
||||
dagger.#Plan & {
|
||||
client: {
|
||||
// Retrieve go source code
|
||||
filesystem: ".": read: {
|
||||
contents: dagger.#FS
|
||||
include: ["go.mod", "go.sum", "**/*.go"]
|
||||
}
|
||||
}
|
||||
|
||||
actions: {
|
||||
// Alias to code directory
|
||||
_code: client.filesystem.".".read.contents
|
||||
|
||||
// Improved go base image with useful tool
|
||||
// Enable cgo by installing build-base
|
||||
_base: go.#Image & {
|
||||
packages: "build-base": version: _
|
||||
}
|
||||
|
||||
// Build go project
|
||||
build: go.#Build & {
|
||||
source: _code
|
||||
}
|
||||
}
|
||||
}
|
69
docs/tests/use-cases/ci-cd-for-go-project/push/dagger.cue
Normal file
69
docs/tests/use-cases/ci-cd-for-go-project/push/dagger.cue
Normal file
@@ -0,0 +1,69 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"dagger.io/dagger"
|
||||
"universe.dagger.io/go"
|
||||
"universe.dagger.io/docker"
|
||||
"universe.dagger.io/alpine"
|
||||
)
|
||||
|
||||
dagger.#Plan & {
|
||||
client: {
|
||||
// Retrieve go source code
|
||||
filesystem: ".": read: {
|
||||
contents: dagger.#FS
|
||||
include: ["go.mod", "go.sum", "**/*.go"]
|
||||
}
|
||||
|
||||
// Retrieve docker password from environment
|
||||
env: DOCKER_PASSWORD: dagger.#Secret
|
||||
}
|
||||
|
||||
actions: {
|
||||
// Alias to code
|
||||
_code: client.filesystem.".".read.contents
|
||||
|
||||
// Improved go base image with useful tool
|
||||
_base: go.#Image & {
|
||||
packages: "build-base": version: _
|
||||
}
|
||||
|
||||
// Build go project
|
||||
build: go.#Build & {
|
||||
source: _code
|
||||
}
|
||||
|
||||
// Build docker image (depends on build)
|
||||
image: {
|
||||
_base: alpine.#Build & {}
|
||||
|
||||
docker.#Build & {
|
||||
steps: [
|
||||
docker.#Copy & {
|
||||
input: _base.output
|
||||
contents: build.output
|
||||
dest: "/usr/bin"
|
||||
},
|
||||
docker.#Set & {
|
||||
config: cmd: ["/<path>/<to>/<your>/<binary>"]
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
// Push image to remote registry (depends on image)
|
||||
push: {
|
||||
// Docker username
|
||||
_dockerUsername: "<docker username>"
|
||||
|
||||
docker.#Push & {
|
||||
"image": image.output
|
||||
dest: "\(_dockerUsername)/<repository>:<tag>"
|
||||
auth: {
|
||||
username: "\(_dockerUsername)"
|
||||
secret: client.env.DOCKER_PASSWORD
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
34
docs/tests/use-cases/ci-cd-for-go-project/test/dagger.cue
Normal file
34
docs/tests/use-cases/ci-cd-for-go-project/test/dagger.cue
Normal file
@@ -0,0 +1,34 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"dagger.io/dagger"
|
||||
"universe.dagger.io/go"
|
||||
)
|
||||
|
||||
dagger.#Plan & {
|
||||
client: {
|
||||
// Retrieve go source code
|
||||
filesystem: ".": read: {
|
||||
contents: dagger.#FS
|
||||
include: ["go.mod", "go.sum", "**/*.go"]
|
||||
}
|
||||
}
|
||||
|
||||
actions: {
|
||||
// Alias to code directory
|
||||
_code: client.filesystem.".".read.contents
|
||||
|
||||
// Improved go base image with useful tool
|
||||
// Enable cgo by installing build-base
|
||||
_base: go.#Image & {
|
||||
packages: "build-base": version: _
|
||||
}
|
||||
|
||||
// Run go unit test
|
||||
"unit-test": go.#Test & {
|
||||
source: _code
|
||||
package: "./..."
|
||||
input: _base.output
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user