stdlib: improved Docker package
Signed-off-by: Solomon Hykes <sh.github.6811@hykes.org>
This commit is contained in:
parent
d522fc3396
commit
647e4c898b
7
dev.cue
7
dev.cue
@ -3,14 +3,15 @@ package main
|
||||
import (
|
||||
"dagger.io/dagger"
|
||||
"dagger.io/alpine"
|
||||
"dagger.io/docker"
|
||||
)
|
||||
|
||||
// Dagger source code
|
||||
source: dagger.#Artifact
|
||||
|
||||
// Build the dagger binaries
|
||||
build: #Container & {
|
||||
image: #ImageFromRef & {ref: "docker.io/golang:1.16-alpine"}
|
||||
build: docker.#Container & {
|
||||
image: docker.#ImageFromRef & {ref: "docker.io/golang:1.16-alpine"}
|
||||
|
||||
setup: [
|
||||
"apk add --no-cache file",
|
||||
@ -45,7 +46,7 @@ build: #Container & {
|
||||
}
|
||||
|
||||
// Execute `dagger help`
|
||||
usage: #Container & {
|
||||
usage: docker.#Container & {
|
||||
image: alpine.#Image
|
||||
|
||||
command: "dagger help"
|
||||
|
1
examples/dagger-dev/dev.cue
Symbolic link
1
examples/dagger-dev/dev.cue
Symbolic link
@ -0,0 +1 @@
|
||||
../../dev.cue
|
@ -1,46 +0,0 @@
|
||||
package main
|
||||
|
||||
// A dagger configuration to build and test the dagger source code.
|
||||
// This configuration can easily be adapted to build and test any go project.
|
||||
//
|
||||
//
|
||||
// Example:
|
||||
// dagger compute ./examples/dagger-dev --input-dir repository=/path/to/go/project
|
||||
|
||||
import (
|
||||
"dagger.io/dagger"
|
||||
"dagger.io/go"
|
||||
"dagger.io/docker"
|
||||
)
|
||||
|
||||
repository: dagger.#Artifact
|
||||
|
||||
// Build `dagger` using Go
|
||||
build: go.#Build & {
|
||||
source: repository
|
||||
packages: "./cmd/dagger"
|
||||
output: "/usr/local/bin/dagger"
|
||||
}
|
||||
|
||||
// Run go tests
|
||||
test: go.#Test & {
|
||||
source: repository
|
||||
packages: "./..."
|
||||
}
|
||||
|
||||
// Run a command with the binary we just built
|
||||
help: docker.#Run & {
|
||||
image: build
|
||||
args: ["dagger", "-h"]
|
||||
}
|
||||
|
||||
// Build dagger using the (included) Dockerfile
|
||||
buildWithDocker: docker.#Build & {
|
||||
source: repository
|
||||
}
|
||||
|
||||
// Run a command in the docker image we just built
|
||||
helpFromDocker: docker.#Run & {
|
||||
image: buildWithDocker.image
|
||||
args: ["dagger", "-h"]
|
||||
}
|
@ -9,6 +9,6 @@ import (
|
||||
source: dagger.#Artifact
|
||||
|
||||
// Container image
|
||||
container: docker.#Build & {
|
||||
container: docker.#ImageFromSource & {
|
||||
"source": source
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
// docker: build and run Docker containers
|
||||
// https://docker.com
|
||||
package main
|
||||
|
||||
package docker
|
||||
|
||||
import (
|
||||
"strings"
|
||||
@ -9,38 +10,6 @@ import (
|
||||
"dagger.io/dagger/op"
|
||||
)
|
||||
|
||||
#ImageFromSource: {
|
||||
source: dagger.#Artifact
|
||||
|
||||
#up: [
|
||||
op.#DockerBuild & {
|
||||
context: source
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
#ImageFromRef: {
|
||||
ref: string
|
||||
|
||||
#up: [
|
||||
op.#FetchContainer & {
|
||||
"ref": ref
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
#ImageFromDockerfile: {
|
||||
dockerfile: string
|
||||
context: dagger.#Artifact
|
||||
|
||||
#up: [
|
||||
op.#DockerBuild & {
|
||||
"context": context
|
||||
"dockerfile": dockerfile
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
// Run a Docker container
|
||||
#Container: {
|
||||
|
@ -1,39 +0,0 @@
|
||||
package docker
|
||||
|
||||
import (
|
||||
"dagger.io/dagger"
|
||||
"dagger.io/dagger/op"
|
||||
)
|
||||
|
||||
#Image: dagger.#Artifact
|
||||
|
||||
#Ref: string
|
||||
|
||||
// Build a docker container image
|
||||
#Build: {
|
||||
source: dagger.#Artifact
|
||||
|
||||
image: #up: [
|
||||
op.#DockerBuild & {context: source},
|
||||
]
|
||||
}
|
||||
|
||||
#Run: {
|
||||
args: [...string]
|
||||
|
||||
// image may be a remote image ref, or a computed artifact
|
||||
{
|
||||
image: #Ref
|
||||
out: #up: [
|
||||
op.#FetchContainer & {ref: image},
|
||||
op.#Exec & {"args": args},
|
||||
]
|
||||
|
||||
} | {
|
||||
image: _
|
||||
out: #up: [
|
||||
op.#Load & {from: image},
|
||||
op.#Exec & {"args": args},
|
||||
]
|
||||
}
|
||||
}
|
41
stdlib/docker/image.cue
Normal file
41
stdlib/docker/image.cue
Normal file
@ -0,0 +1,41 @@
|
||||
package docker
|
||||
|
||||
import (
|
||||
"dagger.io/dagger"
|
||||
"dagger.io/dagger/op"
|
||||
)
|
||||
|
||||
// Build a Docker image from source, using included Dockerfile
|
||||
#ImageFromSource: {
|
||||
source: dagger.#Artifact
|
||||
|
||||
#up: [
|
||||
op.#DockerBuild & {
|
||||
context: source
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
// Fetch an image from a remote registry
|
||||
#ImageFromRegistry: {
|
||||
ref: string
|
||||
|
||||
#up: [
|
||||
op.#FetchContainer & {
|
||||
"ref": ref
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
// Build a Docker image from the provided Dockerfile contents
|
||||
#ImageFromDockerfile: {
|
||||
dockerfile: string
|
||||
context: dagger.#Artifact
|
||||
|
||||
#up: [
|
||||
op.#DockerBuild & {
|
||||
"context": context
|
||||
"dockerfile": dockerfile
|
||||
},
|
||||
]
|
||||
}
|
Reference in New Issue
Block a user