engine.#ReadFile
Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
parent
b25984dad9
commit
dd2fef8a2d
@ -66,6 +66,16 @@ _No input._
|
||||
|
||||
_No output._
|
||||
|
||||
## engine.#ReadFile
|
||||
|
||||
### engine.#ReadFile Inputs
|
||||
|
||||
_No input._
|
||||
|
||||
### engine.#ReadFile Outputs
|
||||
|
||||
_No output._
|
||||
|
||||
## engine.#Secret
|
||||
|
||||
A reference to an external secret, for example: - A password - A SSH private key - An API token Secrets are never merged in the Cue tree. They can only be used by a special filesystem mount designed to minimize leak risk.
|
||||
|
46
plan/task/readfile.go
Normal file
46
plan/task/readfile.go
Normal file
@ -0,0 +1,46 @@
|
||||
package task
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
|
||||
"cuelang.org/go/cue"
|
||||
"go.dagger.io/dagger/compiler"
|
||||
"go.dagger.io/dagger/plancontext"
|
||||
"go.dagger.io/dagger/solver"
|
||||
)
|
||||
|
||||
func init() {
|
||||
Register("ReadFile", func() Task { return &readFileTask{} })
|
||||
}
|
||||
|
||||
type readFileTask struct {
|
||||
}
|
||||
|
||||
func (t *readFileTask) Run(ctx context.Context, pctx *plancontext.Context, s solver.Solver, v *compiler.Value) (*compiler.Value, error) {
|
||||
path, err := v.Lookup("path").String()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
input, err := pctx.FS.FromValue(v.Lookup("input"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
inputFS := solver.NewBuildkitFS(input.Result())
|
||||
|
||||
// FIXME: we should create an intermediate image containing only `path`.
|
||||
// That way, on cache misses, we'll only download the layer with the file contents rather than the entire FS.
|
||||
contents, err := fs.ReadFile(inputFS, path)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("ReadFile %s: %w", path, err)
|
||||
}
|
||||
|
||||
output := compiler.NewValue()
|
||||
if err := output.FillPath(cue.ParsePath("contents"), string(contents)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return output, nil
|
||||
}
|
10
stdlib/europa/dagger/engine/fs.cue
Normal file
10
stdlib/europa/dagger/engine/fs.cue
Normal file
@ -0,0 +1,10 @@
|
||||
package engine
|
||||
|
||||
#ReadFile: {
|
||||
_type: "ReadFile"
|
||||
|
||||
input: #FS
|
||||
path: string
|
||||
contents: string
|
||||
output: #FS
|
||||
}
|
@ -8,3 +8,8 @@ setup() {
|
||||
cd "$TESTDIR"/tasks/pull
|
||||
dagger --europa up
|
||||
}
|
||||
|
||||
@test "task: #ReadFile" {
|
||||
cd "$TESTDIR"/tasks/readfile
|
||||
dagger --europa up
|
||||
}
|
1
tests/tasks/readfile/cue.mod/module.cue
Normal file
1
tests/tasks/readfile/cue.mod/module.cue
Normal file
@ -0,0 +1 @@
|
||||
module: ""
|
3
tests/tasks/readfile/cue.mod/pkg/.gitignore
vendored
Normal file
3
tests/tasks/readfile/cue.mod/pkg/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
# generated by dagger
|
||||
alpha.dagger.io
|
||||
dagger.lock
|
21
tests/tasks/readfile/readfile.cue
Normal file
21
tests/tasks/readfile/readfile.cue
Normal file
@ -0,0 +1,21 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"alpha.dagger.io/europa/dagger/engine"
|
||||
)
|
||||
|
||||
engine.#Plan & {
|
||||
actions: {
|
||||
image: engine.#Pull & {
|
||||
source: "alpine:3.15.0@sha256:e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3"
|
||||
}
|
||||
|
||||
readfile: engine.#ReadFile & {
|
||||
input: image.output
|
||||
path: "/etc/alpine-release"
|
||||
} & {
|
||||
// assert result
|
||||
contents: "3.15.0\n"
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user