Add export and load for dagger images

Signed-off-by: Helder Correia <174525+helderco@users.noreply.github.com>
This commit is contained in:
Helder Correia
2022-03-24 11:59:05 -01:00
parent e46acc8053
commit 7a8153910c
15 changed files with 488 additions and 7 deletions

View 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
}
}
}
}