stdlib: improved Docker package

Signed-off-by: Solomon Hykes <sh.github.6811@hykes.org>
This commit is contained in:
Solomon Hykes 2021-04-06 21:20:21 +00:00
parent d522fc3396
commit 647e4c898b
7 changed files with 49 additions and 122 deletions

View File

@ -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
View File

@ -0,0 +1 @@
../../dev.cue

View File

@ -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"]
}

View File

@ -9,6 +9,6 @@ import (
source: dagger.#Artifact
// Container image
container: docker.#Build & {
container: docker.#ImageFromSource & {
"source": source
}

View File

@ -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: {

View File

@ -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
View 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
},
]
}