Move core actions to a subpackage

Signed-off-by: Helder Correia <174525+helderco@users.noreply.github.com>
This commit is contained in:
Helder Correia
2022-03-26 14:09:21 -01:00
parent 9f042800da
commit b3bdd347e7
121 changed files with 469 additions and 340 deletions

View File

@@ -1,4 +1,4 @@
package dagger
package core
// Execute a command in a container
#Exec: {

View File

@@ -1,4 +1,4 @@
package dagger
package core
// Access the source directory for the current CUE package
// This may safely be called from any package

View File

@@ -1,4 +1,4 @@
package dagger
package core
// Push a directory to a git remote
#GitPush: {
@@ -11,7 +11,7 @@ package dagger
}
// Pull a directory from a git remote
// Warning: do NOT embed credentials in the remote url as this will expose them in logs.
// Warning: do NOT embed credentials in the remote url as this will expose them in logs.
// By using username and password Dagger will handle this for you in a secure manner.
#GitPull: {
$dagger: task: _name: "GitPull"

View File

@@ -1,4 +1,4 @@
package dagger
package core
// HTTP operations

View File

@@ -1,31 +1,6 @@
package dagger
package core
import (
"list"
)
// Upload a container image to a remote repository
#Push: {
$dagger: task: _name: "Push"
// Target repository address
dest: #Ref
// Filesystem contents to push
input: #FS
// Container image config
config: #ImageConfig
// Authentication
auth?: {
username: string
secret: #Secret
}
// Complete ref of the pushed image, including digest
result: #Ref
}
import "list"
// A ref is an address for a remote container image
//
@@ -62,6 +37,29 @@ import (
retries?: int
}
// Upload a container image to a remote repository
#Push: {
$dagger: task: _name: "Push"
// Target repository address
dest: #Ref
// Filesystem contents to push
input: #FS
// Container image config
config: #ImageConfig
// Authentication
auth?: {
username: string
secret: #Secret
}
// Complete ref of the pushed image, including digest
result: #Ref
}
// Download a container image from a remote repository
#Pull: {
$dagger: task: _name: "Pull"

View File

@@ -1,4 +1,4 @@
package dagger
package core
// A core action that does nothing
// Useful to work around bugs in the DAG resolver.

View File

@@ -1,4 +1,4 @@
package dagger
package core
// A special kind of program which `dagger` can execute.
#Plan: {

View File

@@ -1,4 +1,4 @@
package dagger
package core
// Decode the contents of a secrets without leaking it.
// Supported formats: json, yaml

View File

@@ -1,4 +1,4 @@
package dagger
package core
// A reference to a filesystem tree.
// For example:

View File

@@ -0,0 +1,26 @@
package dagger
import "dagger.io/dagger/core"
#Plan: core.#Plan
// Types
#FS: core.#FS
#Scratch: core.#Scratch
#Secret: core.#Secret
#Service: core.#Service
#Address: core.#Address
// Image
#Ref: core.#Ref
#ImageConfig: core.#ImageConfig
#HealthCheck: core.#HealthCheck
// Mounts
#CacheDir: core.#CacheDir
#TempDir: core.#TempDir

View File

@@ -31,7 +31,7 @@ var (
UniverseModule,
}
DaggerPackage = fmt.Sprintf("%s/dagger", DaggerModule)
DaggerPackage = fmt.Sprintf("%s/dagger/core", DaggerModule)
lockFilePath = "dagger.lock"
)

View File

@@ -2,6 +2,7 @@ package alpine
import (
"dagger.io/dagger"
"dagger.io/dagger/core"
"universe.dagger.io/alpine"
"universe.dagger.io/docker"
@@ -16,7 +17,7 @@ dagger.#Plan & {
version: "3.10.9"
}
verify: dagger.#Readfile & {
verify: core.#ReadFile & {
input: build.output.rootfs
path: "/etc/alpine-release"
contents: "3.10.9\n"

View File

@@ -3,13 +3,14 @@ package aws
import (
"dagger.io/dagger"
"dagger.io/dagger/core"
"universe.dagger.io/docker"
)
#DefaultLinuxVersion: "amazonlinux:2.0.20220121.0@sha256:f3a37f84f2644095e2c6f6fdf2bf4dbf68d5436c51afcfbfa747a5de391d5d62"
#DefaultCliVersion: "2.4.12"
// Build provides a docker.#Image with the aws cli pre-installed to Amazon Linux 2.
// Build provides a docker.#Image with the aws cli pre-installed to Amazon Linux 2.
// Can be customized with packages, and can be used with docker.#Run for executing custom scripts.
// Used by default with aws.#Run
#Build: {
@@ -39,7 +40,7 @@ import (
]
}
_scripts: dagger.#Source & {
_scripts: core.#Source & {
path: "_scripts"
}

View File

@@ -2,6 +2,7 @@ package test
import (
"dagger.io/dagger"
"dagger.io/dagger/core"
"universe.dagger.io/aws"
"universe.dagger.io/aws/cli"
)
@@ -14,7 +15,7 @@ dagger.#Plan & {
}
actions: {
sopsSecrets: dagger.#DecodeSecret & {
sopsSecrets: core.#DecodeSecret & {
format: "yaml"
input: client.commands.sops.stdout
}

View File

@@ -3,6 +3,7 @@ package test
import (
"encoding/json"
"dagger.io/dagger"
"dagger.io/dagger/core"
"universe.dagger.io/aws"
)
@@ -20,7 +21,7 @@ dagger.#Plan & {
}
actions: {
sopsSecrets: dagger.#DecodeSecret & {
sopsSecrets: core.#DecodeSecret & {
format: "yaml"
input: client.commands.sops.stdout
}

View File

@@ -3,6 +3,7 @@ package test
import (
"encoding/json"
"dagger.io/dagger"
"dagger.io/dagger/core"
"universe.dagger.io/aws"
)
@@ -14,7 +15,7 @@ dagger.#Plan & {
}
actions: {
sopsSecrets: dagger.#DecodeSecret & {
sopsSecrets: core.#DecodeSecret & {
format: "yaml"
input: client.commands.sops.stdout
}

View File

@@ -3,6 +3,7 @@ package bash
import (
"dagger.io/dagger"
"dagger.io/dagger/core"
"universe.dagger.io/docker"
)
@@ -26,7 +27,7 @@ import (
contents: string
_filename: "run.sh"
_write: dagger.#WriteFile & {
_write: core.#WriteFile & {
input: dagger.#Scratch
path: _filename
"contents": contents

View File

@@ -2,6 +2,7 @@ package bash
import (
"dagger.io/dagger"
"dagger.io/dagger/core"
"universe.dagger.io/docker"
"universe.dagger.io/bash"
@@ -19,7 +20,7 @@ dagger.#Plan & {
runFile: {
dir: _load.output
_load: dagger.#Source & {
_load: core.#Source & {
path: "./data"
include: ["*.sh"]
}

View File

@@ -2,6 +2,7 @@ package docker
import (
"dagger.io/dagger"
"dagger.io/dagger/core"
)
// Modular build API for Docker containers
@@ -46,7 +47,7 @@ import (
dest: string | *"/"
// Execute copy operation
_copy: dagger.#Copy & {
_copy: core.#Copy & {
"input": input.rootfs
"contents": contents
"source": source
@@ -83,7 +84,7 @@ import (
label: [string]: string
hosts: [string]: string
_build: dagger.#Dockerfile & {
_build: core.#Dockerfile & {
"source": source
"auth": auth
"dockerfile": dockerfile

View File

@@ -1,7 +1,7 @@
package cli
import (
"dagger.io/dagger"
"dagger.io/dagger/core"
"universe.dagger.io/docker"
)
@@ -19,7 +19,7 @@ import (
// Root filesystem with exported file
result: _export.output
_export: dagger.#Export & {
_export: core.#Export & {
"tag": tag
input: image.rootfs
config: image.config

View File

@@ -3,6 +3,7 @@ package docker
import (
"dagger.io/dagger"
"dagger.io/dagger/core"
)
// Download an image from a remote registry
@@ -16,7 +17,7 @@ import (
secret: dagger.#Secret
}
_op: dagger.#Pull & {
_op: core.#Pull & {
"source": source
if auth != _|_ {
"auth": auth

View File

@@ -2,6 +2,7 @@ package docker
import (
"dagger.io/dagger"
"dagger.io/dagger/core"
)
// Upload an image to a remote repository
@@ -21,7 +22,7 @@ import (
// Image to push
image: #Image
_push: dagger.#Push & {
_push: core.#Push & {
"dest": dest
if auth != _|_ {
"auth": auth

View File

@@ -4,6 +4,7 @@ import (
"list"
"dagger.io/dagger"
"dagger.io/dagger/core"
)
// Run a command in a container
@@ -14,7 +15,7 @@ import (
always: bool | *false
// Filesystem mounts
mounts: [name=string]: dagger.#Mount
mounts: [name=string]: core.#Mount
// Expose network ports
// FIXME: investigate feasibility
@@ -70,7 +71,7 @@ import (
// Add defaults to image config
// This ensures these values are present
_defaults: dagger.#Set & {
_defaults: core.#Set & {
"input": {
entrypoint: []
cmd: []
@@ -81,7 +82,7 @@ import (
}
// Override with user config
_config: dagger.#Set & {
_config: core.#Set & {
input: _defaults.output
config: {
if entrypoint != _|_ {
@@ -123,7 +124,7 @@ import (
for path, _ in files {
"\(path)": {
contents: string & _read.contents
_read: dagger.#ReadFile & {
_read: core.#ReadFile & {
input: _exec.output
"path": path
}
@@ -139,7 +140,7 @@ import (
for path, _ in directories {
"\(path)": {
contents: dagger.#FS & _subdir.output
_subdir: dagger.#Subdir & {
_subdir: core.#Subdir & {
input: _exec.output
"path": path
}
@@ -159,7 +160,7 @@ import (
}
// Actually execute the command
_exec: dagger.#Exec & {
_exec: core.#Exec & {
"input": input.rootfs
"always": always
"mounts": mounts
@@ -167,7 +168,7 @@ import (
workdir: _config.output.workdir
user: _config.output.user
"env": env
// env may contain secrets so we can't use dagger.#Set
// env may contain secrets so we can't use core.#Set
if input.config.env != _|_ {
for key, val in input.config.env {
if env[key] == _|_ {

View File

@@ -2,6 +2,7 @@ package docker
import (
"dagger.io/dagger"
"dagger.io/dagger/core"
)
// Change image config
@@ -12,7 +13,7 @@ import (
// The image config to change
config: dagger.#ImageConfig
_set: dagger.#Set & {
_set: core.#Set & {
"input": input.config
"config": config
}

View File

@@ -2,6 +2,7 @@ package docker
import (
"dagger.io/dagger"
"dagger.io/dagger/core"
"universe.dagger.io/alpine"
"universe.dagger.io/docker"
@@ -26,7 +27,7 @@ dagger.#Plan & {
]
}
verify: dagger.#ReadFile & {
verify: core.#ReadFile & {
input: image.output.rootfs
path: "/test.txt"
}
@@ -59,7 +60,7 @@ dagger.#Plan & {
]
}
verify: dagger.#ReadFile & {
verify: core.#ReadFile & {
input: image.output.rootfs
path: "/test.txt"
}

View File

@@ -2,6 +2,7 @@ package docker
import (
"dagger.io/dagger"
"dagger.io/dagger/core"
"universe.dagger.io/docker"
)
@@ -16,7 +17,7 @@ dagger.#Plan & {
source: dagger.#Scratch
dockerfile: contents: """
FROM alpine:3.15
RUN echo -n hello world >> /test.txt
"""
},
@@ -33,7 +34,7 @@ dagger.#Plan & {
]
}
verify: dagger.#ReadFile & {
verify: core.#ReadFile & {
input: build.output.rootfs
path: "/test.txt"
} & {
@@ -58,7 +59,7 @@ dagger.#Plan & {
]
}
verify: dagger.#ReadFile & {
verify: core.#ReadFile & {
input: build.output.rootfs
path: "/test.txt"
} & {

View File

@@ -2,6 +2,7 @@ package docker
import (
"dagger.io/dagger"
"dagger.io/dagger/core"
"universe.dagger.io/docker"
)
@@ -43,7 +44,7 @@ dagger.#Plan & {
// Test: image config behavior is correct
config: {
build: dagger.#Dockerfile & {
build: core.#Dockerfile & {
source: dagger.#Scratch
dockerfile: contents: """
FROM alpine:3.15.0
@@ -71,7 +72,7 @@ dagger.#Plan & {
contents: """
#!/bin/sh
echo -n "hello from $HELLO_FROM" > /dagger.txt
"""
}
}

View File

@@ -2,6 +2,7 @@ package docker
import (
"dagger.io/dagger"
"dagger.io/dagger/core"
"universe.dagger.io/docker"
"universe.dagger.io/alpine"
@@ -24,7 +25,7 @@ dagger.#Plan & {
}
}
verify: dagger.#ReadFile & {
verify: core.#ReadFile & {
input: run.output.rootfs
path: "/output.txt"
}
@@ -59,7 +60,7 @@ dagger.#Plan & {
export: directories: "/test": _
}
verify: dagger.#ReadFile & {
verify: core.#ReadFile & {
input: run.export.directories."/test"
path: "/output.txt"
}

View File

@@ -56,11 +56,11 @@ dagger.#Plan & {
}
actions: {
runtimeImage: dagger.#Pull & {
runtimeImage: core.#Pull & {
source: runtime_image_ref
}
depsCache: dagger.#CacheDir & {
depsCache: core.#CacheDir & {
id: "depsCache"
}
@@ -69,7 +69,7 @@ dagger.#Plan & {
contents: depsCache
}
buildCacheTest: dagger.#CacheDir & {
buildCacheTest: core.#CacheDir & {
id: "buildCacheTest"
}
@@ -78,7 +78,7 @@ dagger.#Plan & {
contents: buildCacheTest
}
buildCacheProd: dagger.#CacheDir & {
buildCacheProd: core.#CacheDir & {
id: "buildCacheProd"
}
@@ -87,7 +87,7 @@ dagger.#Plan & {
contents: buildCacheProd
}
nodeModulesCache: dagger.#CacheDir & {
nodeModulesCache: core.#CacheDir & {
id: "nodeModulesCache"
}
@@ -96,20 +96,20 @@ dagger.#Plan & {
contents: nodeModulesCache
}
appImage: dagger.#Copy & {
appImage: core.#Copy & {
input: runtimeImage.output
contents: inputs.directories.app.contents
dest: "/app"
}
deps: dagger.#Exec & {
deps: core.#Exec & {
input: appImage.output
mounts: depsCacheMount
workdir: "/app"
args: ["bash", "-c", " mix deps.get"]
}
assetsCompile: dagger.#Exec & {
assetsCompile: core.#Exec & {
input: depsCompileProd.output
mounts: depsCacheMount & nodeModulesCacheMount
workdir: "/app/assets"
@@ -117,7 +117,7 @@ dagger.#Plan & {
args: ["bash", "-c", "yarn install --frozen-lockfile && yarn run compile"]
}
#depsCompile: dagger.#Exec & {
#depsCompile: core.#Exec & {
input: deps.output
mounts: depsCacheMount
workdir: "/app"
@@ -134,7 +134,7 @@ dagger.#Plan & {
mounts: buildCacheProdMount
}
assetsDigest: dagger.#Exec & {
assetsDigest: core.#Exec & {
input: assetsCompile.output
mounts: depsCacheMount & buildCacheProdMount & nodeModulesCacheMount
env: MIX_ENV: "prod"
@@ -142,20 +142,20 @@ dagger.#Plan & {
args: ["bash", "-c", "mix phx.digest"]
}
imageProdCacheCopy: dagger.#Exec & {
imageProdCacheCopy: core.#Exec & {
input: assetsDigest.output
mounts: (depsCacheMount & {depsCache: dest: "/mnt/app/deps/"} )
mounts: (buildCacheProdMount & {buildCacheProd: dest: "/mnt/app/_build/prod"} )
args: ["bash", "-c", "cp -Rp /mnt/app/deps/* /app/deps/ && cp -Rp /mnt/app/_build/prod/* /app/_build/prod/"]
}
imageProdDockerCopy: dagger.#Copy & {
imageProdDockerCopy: core.#Copy & {
input: imageProdCacheCopy.output
source: root: inputs.directories.docker.contents
dest: "/"
}
imageProd: dagger.#Build & {
imageProd: core.#Dockerfile & {
source: imageProdDockerCopy.output
dockerfile: path: "/docker/Dockerfile.production"
buildArg: {

View File

@@ -19,7 +19,7 @@ actions: {
// workdir: _
// // FIXME: remove copy-pasta
// mounts: nodeModules: {
// contents: dagger.#CacheDir & {
// contents: core.#CacheDir & {
// // FIXME: do we need an ID here?
// id: "\(mix.app)_assets_node_modules"
// // FIXME: does this command need write access to node_modules cache?
@@ -55,7 +55,7 @@ actions: {
// }
// // FIXME: move this to a reusable def (yarn package? or private?)
// mounts: nodeModules: {
// contents: dagger.#CacheDir & {
// contents: core.#CacheDir & {
// // FIXME: do we need an ID here?
// id: "\(mix.app)_assets_node_modules"
// // FIXME: will there be multiple writers?

View File

@@ -67,7 +67,7 @@ import (
}
if cache.deps != null {
mounts: deps: {
contents: dagger.#CacheDir & {
contents: core.#CacheDir & {
id: "\(app.name)_deps"
concurrency: cache.deps
}
@@ -76,7 +76,7 @@ import (
}
if cache.build != null {
mounts: buildCache: {
contents: dagger.#CacheDir & {
contents: core.#CacheDir & {
id: "\(app.name)_build_\(env)"
concurrency: cache.build
}

View File

@@ -2,6 +2,7 @@ package todoapp
import (
"dagger.io/dagger"
"dagger.io/dagger/core"
"universe.dagger.io/alpine"
"universe.dagger.io/bash"
"universe.dagger.io/docker"
@@ -9,7 +10,7 @@ import (
)
dagger.#Plan & {
_nodeModulesMount: "/src/node_modules": dagger.#Mount & {
_nodeModulesMount: "/src/node_modules": {
dest: "/src/node_modules"
type: "cache"
contents: dagger.#CacheDir & {
@@ -53,7 +54,7 @@ dagger.#Plan & {
bash.#Run & {
workdir: "/src"
mounts: {
"/cache/yarn": dagger.#Mount & {
"/cache/yarn": {
dest: "/cache/yarn"
type: "cache"
contents: dagger.#CacheDir & {
@@ -89,7 +90,7 @@ dagger.#Plan & {
"""#
}
contents: dagger.#Subdir & {
contents: core.#Subdir & {
input: run.output.rootfs
path: "/src/build"
}

View File

@@ -1,7 +1,8 @@
package git
import (
"dagger.io/dagger/core"
)
#Pull: dagger.#GitPull
#Push: dagger.#GitPush
#Pull: core.#GitPull
#Push: core.#GitPush

View File

@@ -2,6 +2,7 @@ package go
import (
"dagger.io/dagger"
"dagger.io/dagger/core"
"universe.dagger.io/go"
"universe.dagger.io/docker"
"universe.dagger.io/alpine"
@@ -32,7 +33,7 @@ dagger.#Plan & {
}
}
verify: dagger.#ReadFile & {
verify: core.#ReadFile & {
input: exec.output.rootfs
path: "/output.txt"
} & {

View File

@@ -4,6 +4,7 @@ package netlify
import (
"dagger.io/dagger"
"dagger.io/dagger/core"
"universe.dagger.io/alpine"
"universe.dagger.io/docker"
@@ -60,7 +61,7 @@ import (
container: bash.#Run & {
input: *_build.output | docker.#Image
script: {
_load: dagger.#Source & {
_load: core.#Source & {
path: "."
include: ["*.sh"]
}

View File

@@ -2,6 +2,7 @@ package netlify
import (
"dagger.io/dagger"
"dagger.io/dagger/core"
"universe.dagger.io/docker"
"universe.dagger.io/netlify"
@@ -20,7 +21,7 @@ dagger.#Plan & {
// Configuration common to all tests
common: {
testSecrets: dagger.#DecodeSecret & {
testSecrets: core.#DecodeSecret & {
input: client.commands.sops.stdout
format: "yaml"
}
@@ -29,7 +30,7 @@ dagger.#Plan & {
marker: "hello world"
data: dagger.#WriteFile & {
data: core.#WriteFile & {
input: dagger.#Scratch
path: "index.html"
contents: marker

View File

@@ -3,6 +3,7 @@ package powershell
import (
"dagger.io/dagger"
"dagger.io/dagger/core"
"universe.dagger.io/docker"
)
@@ -26,7 +27,7 @@ import (
contents: string
_filename: "run.ps1"
_write: dagger.#WriteFile & {
_write: core.#WriteFile & {
input: dagger.#Scratch
path: _filename
"contents": contents

View File

@@ -2,6 +2,7 @@ package powershell
import (
"dagger.io/dagger"
"dagger.io/dagger/core"
"universe.dagger.io/docker"
"universe.dagger.io/powershell"
@@ -19,7 +20,7 @@ dagger.#Plan & {
runFile: {
dir: _load.output
_load: dagger.#Source & {
_load: core.#Source & {
path: "./data"
include: ["*.ps1"]
}

View File

@@ -2,6 +2,7 @@ package yarn
import (
"dagger.io/dagger"
"dagger.io/dagger/core"
"universe.dagger.io/docker"
"universe.dagger.io/yarn"
@@ -78,7 +79,7 @@ dagger.#Plan & {
path: string
contents: string
_read: dagger.#ReadFile & {
_read: core.#ReadFile & {
"input": input
"path": path
}

View File

@@ -5,6 +5,7 @@ import (
"strings"
"dagger.io/dagger"
"dagger.io/dagger/core"
"universe.dagger.io/alpine"
"universe.dagger.io/bash"
@@ -78,7 +79,7 @@ import (
mounts: "yarn cache": {
dest: "/cache/yarn"
contents: dagger.#CacheDir & {
contents: core.#CacheDir & {
// FIXME: are there character limitations in cache ID?
id: "universe.dagger.io/yarn.#Run \(name)"
}
@@ -109,7 +110,7 @@ import (
mounts: "yarn cache": {
dest: "/cache/yarn"
contents: dagger.#CacheDir & {
contents: core.#CacheDir & {
// FIXME: are there character limitations in cache ID?
id: "universe.dagger.io/yarn.#Run \(name)"
}
@@ -135,7 +136,7 @@ import (
}
// The final contents of the package after run
_output: dagger.#Subdir & {
_output: core.#Subdir & {
input: _run.output.rootfs
path: "/build"
}