Merge pull request #1208 from aluzzardi/engine-readfile
engine.#ReadFile
This commit is contained in:
commit
ba984c4d03
@ -66,6 +66,16 @@ _No input._
|
|||||||
|
|
||||||
_No output._
|
_No output._
|
||||||
|
|
||||||
|
## engine.#ReadFile
|
||||||
|
|
||||||
|
### engine.#ReadFile Inputs
|
||||||
|
|
||||||
|
_No input._
|
||||||
|
|
||||||
|
### engine.#ReadFile Outputs
|
||||||
|
|
||||||
|
_No output._
|
||||||
|
|
||||||
## engine.#Secret
|
## 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.
|
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
|
||||||
|
}
|
@ -7,4 +7,9 @@ setup() {
|
|||||||
@test "task: #Pull" {
|
@test "task: #Pull" {
|
||||||
cd "$TESTDIR"/tasks/pull
|
cd "$TESTDIR"/tasks/pull
|
||||||
dagger --europa up
|
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