Merge pull request #1842 from helderco/docker-load
Add export and load for dagger images
This commit is contained in:
@@ -117,6 +117,32 @@ import (
|
||||
config: #ImageConfig
|
||||
}
|
||||
|
||||
// Export an image as a tar archive
|
||||
#Export: {
|
||||
$dagger: task: _name: "Export"
|
||||
|
||||
// Filesystem contents to export
|
||||
input: #FS
|
||||
|
||||
// Container image config
|
||||
config: #ImageConfig
|
||||
|
||||
// Name and optionally a tag in the 'name:tag' format
|
||||
tag: string
|
||||
|
||||
// Type of export
|
||||
type: *"docker" | "oci"
|
||||
|
||||
// Path to the exported file inside `output`
|
||||
path: string | *"/image.tar"
|
||||
|
||||
// Exported image ID
|
||||
imageID: string
|
||||
|
||||
// Root filesystem with exported file
|
||||
output: #FS
|
||||
}
|
||||
|
||||
// Change image config
|
||||
#Set: {
|
||||
// The source image config
|
||||
|
112
pkg/universe.dagger.io/docker/load.cue
Normal file
112
pkg/universe.dagger.io/docker/load.cue
Normal file
@@ -0,0 +1,112 @@
|
||||
package docker
|
||||
|
||||
import (
|
||||
"dagger.io/dagger"
|
||||
)
|
||||
|
||||
// Load an image into a docker daemon
|
||||
#Load: {
|
||||
// Image to load
|
||||
image: #Image
|
||||
|
||||
// Name and optionally a tag in the 'name:tag' format
|
||||
tag: #Ref
|
||||
|
||||
// Exported image ID
|
||||
imageID: _export.imageID
|
||||
|
||||
// Root filesystem with exported file
|
||||
result: _export.output
|
||||
|
||||
_export: dagger.#Export & {
|
||||
"tag": tag
|
||||
input: image.rootfs
|
||||
config: image.config
|
||||
}
|
||||
|
||||
#_cli & {
|
||||
mounts: src: {
|
||||
dest: "/src"
|
||||
contents: _export.output
|
||||
}
|
||||
command: {
|
||||
name: "load"
|
||||
flags: "-i": "/src/image.tar"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: Move this into docker/client or
|
||||
// create a better abstraction to reuse here.
|
||||
#_cli: {
|
||||
#_socketConn | #_sshConn | #_tcpConn
|
||||
|
||||
_image: #Pull & {
|
||||
source: "docker:20.10.13-alpine3.15"
|
||||
}
|
||||
|
||||
input: _image.output
|
||||
}
|
||||
|
||||
// Connect via local docker socket
|
||||
#_socketConn: {
|
||||
host: dagger.#Service
|
||||
|
||||
#Run & {
|
||||
mounts: docker: {
|
||||
dest: "/var/run/docker.sock"
|
||||
contents: host
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Connect via HTTP/HTTPS
|
||||
#_tcpConn: {
|
||||
host: =~"^tcp://.+"
|
||||
|
||||
#Run & {
|
||||
env: DOCKER_HOST: host
|
||||
|
||||
// Directory with certificates to verify ({ca,cert,key}.pem files).
|
||||
// This enables HTTPS.
|
||||
certs?: dagger.#FS
|
||||
|
||||
if certs != _|_ {
|
||||
mounts: "certs": {
|
||||
dest: "/certs/client"
|
||||
contents: certs
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Connect via SSH
|
||||
#_sshConn: {
|
||||
host: =~"^ssh://.+"
|
||||
|
||||
ssh: {
|
||||
// Private SSH key
|
||||
key?: dagger.#Secret
|
||||
|
||||
// Known hosts file contents
|
||||
knownHosts?: dagger.#Secret
|
||||
}
|
||||
|
||||
#Run & {
|
||||
env: DOCKER_HOST: host
|
||||
|
||||
if ssh.key != _|_ {
|
||||
mounts: ssh_key: {
|
||||
dest: "/root/.ssh/id_rsa"
|
||||
contents: ssh.key
|
||||
}
|
||||
}
|
||||
|
||||
if ssh.knownHosts != _|_ {
|
||||
mounts: ssh_hosts: {
|
||||
dest: "/root/.ssh/known_hosts"
|
||||
contents: ssh.knownHosts
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
57
pkg/universe.dagger.io/docker/test/load.cue
Normal file
57
pkg/universe.dagger.io/docker/test/load.cue
Normal file
@@ -0,0 +1,57 @@
|
||||
package docker
|
||||
|
||||
import (
|
||||
"dagger.io/dagger"
|
||||
|
||||
"universe.dagger.io/alpine"
|
||||
"universe.dagger.io/bash"
|
||||
"universe.dagger.io/docker"
|
||||
)
|
||||
|
||||
dagger.#Plan & {
|
||||
client: filesystem: "/var/run/docker.sock": read: contents: dagger.#Service
|
||||
|
||||
actions: test: load: {
|
||||
_cli: alpine.#Build & {
|
||||
packages: {
|
||||
bash: {}
|
||||
"docker-cli": {}
|
||||
}
|
||||
}
|
||||
|
||||
_image: docker.#Run & {
|
||||
input: _cli.output
|
||||
command: {
|
||||
name: "touch"
|
||||
args: ["/foo.bar"]
|
||||
}
|
||||
}
|
||||
|
||||
load: docker.#Load & {
|
||||
image: _image.output
|
||||
host: client.filesystem."/var/run/docker.sock".read.contents
|
||||
tag: "dagger:load"
|
||||
}
|
||||
|
||||
verify: bash.#Run & {
|
||||
input: _cli.output
|
||||
mounts: docker: {
|
||||
contents: client.filesystem."/var/run/docker.sock".read.contents
|
||||
dest: "/var/run/docker.sock"
|
||||
}
|
||||
env: {
|
||||
IMAGE_NAME: load.tag
|
||||
IMAGE_ID: load.imageID
|
||||
// FIXME: without this forced dependency, load.command might not run
|
||||
DEP: "\(load.success)"
|
||||
}
|
||||
script: contents: #"""
|
||||
test "$(docker image inspect $IMAGE_NAME -f '{{.Id}}')" = "$IMAGE_ID"
|
||||
docker run --rm $IMAGE_NAME stat /foo.bar
|
||||
"""#
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: test remote connections with `docker:dind`
|
||||
// image when we have long running tasks
|
||||
}
|
@@ -9,4 +9,5 @@ setup() {
|
||||
dagger "do" -p ./dockerfile.cue test
|
||||
dagger "do" -p ./run.cue test
|
||||
dagger "do" -p ./image.cue test
|
||||
dagger "do" -p ./load.cue test
|
||||
}
|
||||
|
Reference in New Issue
Block a user