From 9d85bab9e7ea92cbbc19178b8dd73f9e65cb82f4 Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Wed, 9 Jun 2021 18:37:05 +0000 Subject: [PATCH] os.#File: simplify API Signed-off-by: Solomon Hykes --- docs/reference/universe/os.md | 2 +- stdlib/.dagger/env/os/.gitignore | 2 ++ stdlib/.dagger/env/os/plan/main.cue | 26 ++++++++++++++++++ stdlib/.dagger/env/os/values.yaml | 21 +++++++++++++++ stdlib/aws/ecr/ecr.cue | 2 +- stdlib/dagger/op/op.cue | 3 ++- stdlib/netlify/netlify.cue | 6 ++--- stdlib/os/file.cue | 42 ++++++++++++++++------------- stdlib/universe.bats | 7 ++++- 9 files changed, 86 insertions(+), 25 deletions(-) create mode 100644 stdlib/.dagger/env/os/.gitignore create mode 100644 stdlib/.dagger/env/os/plan/main.cue create mode 100644 stdlib/.dagger/env/os/values.yaml diff --git a/docs/reference/universe/os.md b/docs/reference/universe/os.md index 73de74c9..c1e7ef37 100644 --- a/docs/reference/universe/os.md +++ b/docs/reference/universe/os.md @@ -34,7 +34,7 @@ _No output._ ## os.#File -Built-in file implementation, using buildkit +Built-in file implementation, using buildkit A single file ### os.#File Inputs diff --git a/stdlib/.dagger/env/os/.gitignore b/stdlib/.dagger/env/os/.gitignore new file mode 100644 index 00000000..01ec19b0 --- /dev/null +++ b/stdlib/.dagger/env/os/.gitignore @@ -0,0 +1,2 @@ +# dagger state +state/** diff --git a/stdlib/.dagger/env/os/plan/main.cue b/stdlib/.dagger/env/os/plan/main.cue new file mode 100644 index 00000000..bb6a6c7b --- /dev/null +++ b/stdlib/.dagger/env/os/plan/main.cue @@ -0,0 +1,26 @@ +package main + +import ( + "dagger.io/os" + "dagger.io/alpine" +) + +// Write a file to an empty dir +EmptyDir: { + f: os.#File & { + path: "/foo.txt" + write: data: "hello world!" + } + f: contents: "hello world!" +} + +// Read from a pre-existing file +Read: { + f: os.#File & { + from: alpine.#Image & { + version: "3.13.4" + } + path: "/etc/alpine-release" + } + f: contents: "3.13.4\n" +} diff --git a/stdlib/.dagger/env/os/values.yaml b/stdlib/.dagger/env/os/values.yaml new file mode 100644 index 00000000..1ad4a012 --- /dev/null +++ b/stdlib/.dagger/env/os/values.yaml @@ -0,0 +1,21 @@ +name: os +sops: + kms: [] + gcp_kms: [] + azure_kv: [] + hc_vault: [] + age: + - recipient: age1gxwmtwahzwdmrskhf90ppwlnze30lgpm056kuesrxzeuyclrwvpsupwtpk + enc: | + -----BEGIN AGE ENCRYPTED FILE----- + YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSA0bDM5blE0cC9LNHkxZmEy + bitYcjhMOHhrWE5pRm90Qyt4S200ZTN0Q1d3Clh2VmdKQjdGUGdKaThmaktwN1F6 + aXZpellwbHpkb3pMb1NMNXVJYnFUMmMKLS0tIFNiZGlBNjE3UjlXWnBjZ3hwSWto + STlrbFNHZGFRUVQ1S1RIaGVyWktNV0kKo9AFURi/BKI+JuGYVuOrsw3eJU3s66Im + FCc5YCzrsjX+Y26Su+XW81fTWkcC910e/g+tlZbEFWKZYa8qu1VkqA== + -----END AGE ENCRYPTED FILE----- + lastmodified: "2021-06-09T18:19:29Z" + mac: ENC[AES256_GCM,data:G/D+9UqwJXhqVHAq8rXP7YxubzGKNxjguUVuVpnxKN7awzYaAD2E5plBFDqCw++5qFSZ7HMlWZUseyKOfaOxtkT0CTRAZf8cYLXHIjzKKCFP632nLN0zCPQCMqdrhOLtWkLovtHJ94Xvd3C3Mb+bVi1YmOC6nQHhpglwTVjDw9I=,iv:0GN4vAO5QMXUTODDKYpPD/UmxjfI+RyCdYz9UXQNCso=,tag:RacQNrAUhJHtKeu5ugUadA==,type:str] + pgp: [] + encrypted_suffix: secret + version: 3.7.1 diff --git a/stdlib/aws/ecr/ecr.cue b/stdlib/aws/ecr/ecr.cue index 2ee4d7cc..4739af01 100644 --- a/stdlib/aws/ecr/ecr.cue +++ b/stdlib/aws/ecr/ecr.cue @@ -28,5 +28,5 @@ import ( from: ctr path: "/out" } - }.read.data @dagger(output) + }.contents @dagger(output) } diff --git a/stdlib/dagger/op/op.cue b/stdlib/dagger/op/op.cue index abcb023e..8fff9c31 100644 --- a/stdlib/dagger/op/op.cue +++ b/stdlib/dagger/op/op.cue @@ -107,7 +107,8 @@ package op } #WriteFile: { - do: "write-file" + do: "write-file" + // FIXME: "contents" to follow english convention content: string | bytes dest: string mode: int | *0o644 diff --git a/stdlib/netlify/netlify.cue b/stdlib/netlify/netlify.cue index 3710a225..ea2a0f9b 100644 --- a/stdlib/netlify/netlify.cue +++ b/stdlib/netlify/netlify.cue @@ -40,7 +40,7 @@ import ( from: ctr path: "/netlify/url" } - }.read.data @dagger(output) + }.contents @dagger(output) // Unique Deploy URL deployUrl: { @@ -48,7 +48,7 @@ import ( from: ctr path: "/netlify/deployUrl" } - }.read.data @dagger(output) + }.contents @dagger(output) // Logs URL for this deployment logsUrl: { @@ -56,7 +56,7 @@ import ( from: ctr path: "/netlify/logsUrl" } - }.read.data @dagger(output) + }.contents @dagger(output) ctr: os.#Container & { image: alpine.#Image & { diff --git a/stdlib/os/file.cue b/stdlib/os/file.cue index 5714c010..40ae675d 100644 --- a/stdlib/os/file.cue +++ b/stdlib/os/file.cue @@ -7,30 +7,36 @@ import ( ) // Built-in file implementation, using buildkit +// A single file #File: { - from: dagger.#Artifact + from: dagger.#Artifact | *[op.#Mkdir & {dir: "/", path: "/"}] path: string - read: { - // FIXME: support different data schemas for different formats - format: "string" - data: { - string - #up: [ - op.#Load & {"from": from}, - op.#Export & {source: path, "format": format}, - ] - } + // Optionally write data to the file + write: *null | { + data: string + // FIXME: append + // FIXME: create + mode } - write: *null | { - // FIXME: support encoding in different formats - data: string + // The contents of the file + // If a write operation is specified, it is applied first. + contents: { + string + #up: [ - op.#Load & {"from": from}, - op.#WriteFile & { - dest: path - contents: data + op.#Load & { + "from": from + }, + if write != null { + op.#WriteFile & { + dest: path + content: write.data + } + }, + op.#Export & { + source: path + format: "string" }, ] } diff --git a/stdlib/universe.bats b/stdlib/universe.bats index 66d6a965..577cb4ef 100644 --- a/stdlib/universe.bats +++ b/stdlib/universe.bats @@ -4,6 +4,11 @@ setup() { common_setup } + +@test "os" { + dagger -e os up +} + @test "go" { dagger -e go up } @@ -130,4 +135,4 @@ setup() { # Unset input run dagger -w "$DAGGER_SANDBOX" -e terraform input unset TestTerraform.apply.tfvars.input assert_success -} \ No newline at end of file +}