Skip to content

Commit

Permalink
os.#File: simplify API
Browse files Browse the repository at this point in the history
Signed-off-by: Solomon Hykes <solomon@dagger.io>
  • Loading branch information
shykes committed Jun 23, 2021
1 parent 9984eda commit 9d85bab
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 25 deletions.
2 changes: 1 addition & 1 deletion docs/reference/universe/os.md
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions stdlib/.dagger/env/os/.gitignore
@@ -0,0 +1,2 @@
# dagger state
state/**
26 changes: 26 additions & 0 deletions 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"
}
21 changes: 21 additions & 0 deletions 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
2 changes: 1 addition & 1 deletion stdlib/aws/ecr/ecr.cue
Expand Up @@ -28,5 +28,5 @@ import (
from: ctr
path: "/out"
}
}.read.data @dagger(output)
}.contents @dagger(output)
}
3 changes: 2 additions & 1 deletion stdlib/dagger/op/op.cue
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions stdlib/netlify/netlify.cue
Expand Up @@ -40,23 +40,23 @@ import (
from: ctr
path: "/netlify/url"
}
}.read.data @dagger(output)
}.contents @dagger(output)

// Unique Deploy URL
deployUrl: {
os.#File & {
from: ctr
path: "/netlify/deployUrl"
}
}.read.data @dagger(output)
}.contents @dagger(output)

// Logs URL for this deployment
logsUrl: {
os.#File & {
from: ctr
path: "/netlify/logsUrl"
}
}.read.data @dagger(output)
}.contents @dagger(output)

ctr: os.#Container & {
image: alpine.#Image & {
Expand Down
42 changes: 24 additions & 18 deletions stdlib/os/file.cue
Expand Up @@ -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 | {
// FIXME: support encoding in different formats
data: string
// FIXME: append
// FIXME: create + mode
}

// 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"
},
]
}
Expand Down
7 changes: 6 additions & 1 deletion stdlib/universe.bats
Expand Up @@ -4,6 +4,11 @@ setup() {
common_setup
}


@test "os" {
dagger -e os up
}

@test "go" {
dagger -e go up
}
Expand Down Expand Up @@ -130,4 +135,4 @@ setup() {
# Unset input
run dagger -w "$DAGGER_SANDBOX" -e terraform input unset TestTerraform.apply.tfvars.input
assert_success
}
}

0 comments on commit 9d85bab

Please sign in to comment.