From 647e4c898b51c12c4109662182c48c3b20105bfa Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Tue, 6 Apr 2021 21:20:21 +0000 Subject: [PATCH] stdlib: improved Docker package Signed-off-by: Solomon Hykes --- dev.cue | 7 ++-- examples/dagger-dev/dev.cue | 1 + examples/dagger-dev/main.cue | 46 ----------------------- examples/docker/main.cue | 2 +- docker.cue => stdlib/docker/container.cue | 35 +---------------- stdlib/docker/docker.cue | 39 ------------------- stdlib/docker/image.cue | 41 ++++++++++++++++++++ 7 files changed, 49 insertions(+), 122 deletions(-) create mode 120000 examples/dagger-dev/dev.cue delete mode 100644 examples/dagger-dev/main.cue rename docker.cue => stdlib/docker/container.cue (87%) delete mode 100644 stdlib/docker/docker.cue create mode 100644 stdlib/docker/image.cue diff --git a/dev.cue b/dev.cue index 675e68fd..24435677 100644 --- a/dev.cue +++ b/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" diff --git a/examples/dagger-dev/dev.cue b/examples/dagger-dev/dev.cue new file mode 120000 index 00000000..dd388aaf --- /dev/null +++ b/examples/dagger-dev/dev.cue @@ -0,0 +1 @@ +../../dev.cue \ No newline at end of file diff --git a/examples/dagger-dev/main.cue b/examples/dagger-dev/main.cue deleted file mode 100644 index 34e4dfb3..00000000 --- a/examples/dagger-dev/main.cue +++ /dev/null @@ -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"] -} diff --git a/examples/docker/main.cue b/examples/docker/main.cue index 485ff08f..8be803a6 100644 --- a/examples/docker/main.cue +++ b/examples/docker/main.cue @@ -9,6 +9,6 @@ import ( source: dagger.#Artifact // Container image -container: docker.#Build & { +container: docker.#ImageFromSource & { "source": source } diff --git a/docker.cue b/stdlib/docker/container.cue similarity index 87% rename from docker.cue rename to stdlib/docker/container.cue index 423658c4..cdf3c528 100644 --- a/docker.cue +++ b/stdlib/docker/container.cue @@ -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: { diff --git a/stdlib/docker/docker.cue b/stdlib/docker/docker.cue deleted file mode 100644 index d5cc450f..00000000 --- a/stdlib/docker/docker.cue +++ /dev/null @@ -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}, - ] - } -} diff --git a/stdlib/docker/image.cue b/stdlib/docker/image.cue new file mode 100644 index 00000000..88bc4744 --- /dev/null +++ b/stdlib/docker/image.cue @@ -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 + }, + ] +}