Improve go use case example according to Gerhard's review
Signed-off-by: Vasek - Tom C <tom.chauveau@epitech.eu>
This commit is contained in:
committed by
Vasek - Tom C
parent
2d3acc61e0
commit
6fe49a0294
14
docs/tests/use-cases/ci-cd-for-go-project/base.cue.fragment
Normal file
14
docs/tests/use-cases/ci-cd-for-go-project/base.cue.fragment
Normal file
@@ -0,0 +1,14 @@
|
||||
import (
|
||||
"dagger.io/dagger"
|
||||
"universe.dagger.io/go"
|
||||
)
|
||||
|
||||
dagger.#Plan & {
|
||||
actions: {
|
||||
// Improve go base image with useful tool
|
||||
// Enable cgo by installing build-base
|
||||
_base: go.#Image & {
|
||||
packages: "build-base": version: _
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,4 @@
|
||||
// Build go project
|
||||
build: go.#Build & {
|
||||
source: _code
|
||||
}
|
@@ -1,32 +0,0 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
@@ -9,13 +9,11 @@ import (
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
@@ -23,9 +21,20 @@ dagger.#Plan & {
|
||||
// Alias to code
|
||||
_code: client.filesystem.".".read.contents
|
||||
|
||||
// Improved go base image with useful tool
|
||||
// Improve go base image with useful tool
|
||||
// Enable cgo by installing build-base
|
||||
_base: go.#Image & {
|
||||
packages: "build-base": version: _
|
||||
packages: {
|
||||
"build-base": version: _
|
||||
bash: version: _
|
||||
}
|
||||
}
|
||||
|
||||
// Run go unit test
|
||||
"unit-test": go.#Test & {
|
||||
source: _code
|
||||
package: "./..."
|
||||
input: _base.output
|
||||
}
|
||||
|
||||
// Build go project
|
||||
@@ -45,7 +54,7 @@ dagger.#Plan & {
|
||||
dest: "/usr/bin"
|
||||
},
|
||||
docker.#Set & {
|
||||
config: cmd: ["/<path>/<to>/<your>/<binary>"]
|
||||
config: cmd: ["<path/to/binary>"]
|
||||
},
|
||||
]
|
||||
}
|
||||
@@ -54,11 +63,11 @@ dagger.#Plan & {
|
||||
// Push image to remote registry (depends on image)
|
||||
push: {
|
||||
// Docker username
|
||||
_dockerUsername: "<docker username>"
|
||||
_dockerUsername: "<my_username>"
|
||||
|
||||
docker.#Push & {
|
||||
"image": image.output
|
||||
dest: "\(_dockerUsername)/<repository>:<tag>"
|
||||
dest: "\(_dockerUsername)/<my_repository>"
|
||||
auth: {
|
||||
username: "\(_dockerUsername)"
|
||||
secret: client.env.DOCKER_PASSWORD
|
22
docs/tests/use-cases/ci-cd-for-go-project/image.cue.fragment
Normal file
22
docs/tests/use-cases/ci-cd-for-go-project/image.cue.fragment
Normal file
@@ -0,0 +1,22 @@
|
||||
import (
|
||||
"universe.dagger.io/alpine"
|
||||
"universe.dagger.io/docker"
|
||||
)
|
||||
|
||||
// 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/binary>"]
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
14
docs/tests/use-cases/ci-cd-for-go-project/push.cue.fragment
Normal file
14
docs/tests/use-cases/ci-cd-for-go-project/push.cue.fragment
Normal file
@@ -0,0 +1,14 @@
|
||||
// Push image to remote registry (depends on image)
|
||||
push: {
|
||||
// Docker username
|
||||
_dockerUsername: "<my_username>"
|
||||
|
||||
docker.#Push & {
|
||||
"image": image.output
|
||||
dest: "\(_dockerUsername)/<my_repository>"
|
||||
auth: {
|
||||
username: "\(_dockerUsername)"
|
||||
secret: client.env.DOCKER_PASSWORD
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,18 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"dagger.io/dagger"
|
||||
)
|
||||
|
||||
dagger.#Plan & {
|
||||
// Retrieve go source code
|
||||
client: filesystem: ".": read: {
|
||||
contents: dagger.#FS
|
||||
include: ["go.mod", "go.sum", "**/*.go"]
|
||||
}
|
||||
|
||||
actions: {
|
||||
// Alias to code directory
|
||||
_code: client.filesystem.".".read.contents
|
||||
}
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
// Run go unit test
|
||||
"unit-test": go.#Test & {
|
||||
source: _code
|
||||
package: "./..."
|
||||
input: _base.output
|
||||
}
|
@@ -1,34 +0,0 @@
|
||||
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