Move snippets outside of markdown
Signed-off-by: Helder Correia <174525+helderco@users.noreply.github.com>
This commit is contained in:
parent
cf0505614f
commit
6204970d53
@ -17,37 +17,12 @@ displayed_sidebar: europa
|
|||||||
|
|
||||||
You may need to load a local directory as a `dagger.#FS` type in your plan:
|
You may need to load a local directory as a `dagger.#FS` type in your plan:
|
||||||
|
|
||||||
```cue
|
```cue file=../tests/core-concepts/client/plans/fs.cue
|
||||||
dagger.#Plan & {
|
|
||||||
// Path may be absolute, or relative to current working directory
|
|
||||||
client: filesystem: ".": read: {
|
|
||||||
// CUE type defines expected content
|
|
||||||
contents: dagger.#FS
|
|
||||||
exclude: ["node_modules"]
|
|
||||||
}
|
|
||||||
actions: {
|
|
||||||
...
|
|
||||||
copy: docker.Copy & {
|
|
||||||
contents: client.filesystem.".".read.contents
|
|
||||||
}
|
|
||||||
...
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
It’s also easy to write a file locally:
|
It’s also easy to write a file locally:
|
||||||
|
|
||||||
```cue
|
```cue file=../tests/core-concepts/client/plans/file.cue
|
||||||
dagger.#Plan & {
|
|
||||||
client: filesystem: "config.yaml": write: {
|
|
||||||
contents: yaml.Marshal(actions.pull.output.config)
|
|
||||||
}
|
|
||||||
actions: {
|
|
||||||
pull: docker.#Pull & {
|
|
||||||
source: "alpine"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Using a local socket
|
## Using a local socket
|
||||||
@ -61,59 +36,14 @@ import TabItem from '@theme/TabItem';
|
|||||||
|
|
||||||
<TabItem value="unix" label="Linux/macOS">
|
<TabItem value="unix" label="Linux/macOS">
|
||||||
|
|
||||||
```cue
|
```cue file=../tests/core-concepts/client/plans/unix.cue
|
||||||
dagger.#Plan & {
|
|
||||||
client: filesystem: "/var/run/docker.sock": read: {
|
|
||||||
contents: dagger.#Service
|
|
||||||
}
|
|
||||||
|
|
||||||
actions: {
|
|
||||||
image: alpine.#Build & {
|
|
||||||
packages: "docker-cli": {}
|
|
||||||
}
|
|
||||||
run: docker.#Run & {
|
|
||||||
input: image.output
|
|
||||||
mounts: docker: {
|
|
||||||
dest: "/var/run/docker.sock"
|
|
||||||
contents: client.filesystem."/var/run/docker.sock".read.contents
|
|
||||||
}
|
|
||||||
command: {
|
|
||||||
name: "docker"
|
|
||||||
args: ["info"]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
</TabItem>
|
</TabItem>
|
||||||
|
|
||||||
<TabItem value="windows" label="Windows">
|
<TabItem value="windows" label="Windows">
|
||||||
|
|
||||||
```cue
|
```cue file=../tests/core-concepts/client/plans/windows.cue
|
||||||
dagger.#Plan & {
|
|
||||||
client: filesystem: "//./pipe/docker_engine": read: {
|
|
||||||
contents: dagger.#Service
|
|
||||||
type: "npipe"
|
|
||||||
}
|
|
||||||
|
|
||||||
actions: {
|
|
||||||
image: alpine.#Build & {
|
|
||||||
packages: "docker-cli": {}
|
|
||||||
}
|
|
||||||
run: docker.#Run & {
|
|
||||||
input: image.output
|
|
||||||
mounts: docker: {
|
|
||||||
dest: "/var/run/docker.sock"
|
|
||||||
contents: client.filesystem."//./pipe/docker_engine".read.contents
|
|
||||||
}
|
|
||||||
command: {
|
|
||||||
name: "docker"
|
|
||||||
args: ["info"]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
</TabItem>
|
</TabItem>
|
||||||
@ -123,68 +53,23 @@ dagger.#Plan & {
|
|||||||
|
|
||||||
Environment variables can be read from the local machine as strings or secrets, just specify the type:
|
Environment variables can be read from the local machine as strings or secrets, just specify the type:
|
||||||
|
|
||||||
```cue
|
```cue file=../tests/core-concepts/client/plans/env.cue
|
||||||
dagger.#Plan & {
|
|
||||||
client: env: {
|
|
||||||
GITLAB_USER: string
|
|
||||||
GITLAB_TOKEN: dagger.#Secret
|
|
||||||
}
|
|
||||||
actions: {
|
|
||||||
pull: docker.#Pull & {
|
|
||||||
source: "registry.gitlab.com/myuser/myrepo"
|
|
||||||
auth: {
|
|
||||||
username: client.env.GITLAB_USR
|
|
||||||
secret: client.env.GITLAB_TOKEN
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Running commands
|
## Running commands
|
||||||
|
|
||||||
Sometimes you need something more advanced that only a local command can give you:
|
Sometimes you need something more advanced that only a local command can give you:
|
||||||
|
|
||||||
```cue
|
```cue file=../tests/core-concepts/client/plans/cmd.cue
|
||||||
dagger.#Plan & {
|
|
||||||
client: commands: {
|
|
||||||
os: {
|
|
||||||
name: "uname"
|
|
||||||
args: ["-s"]
|
|
||||||
}
|
|
||||||
arch: {
|
|
||||||
name: "uname"
|
|
||||||
args: ["-m"]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
actions: {
|
|
||||||
build: docker.#Run & {
|
|
||||||
env: {
|
|
||||||
CLIENT_OS: client.commands.os.stdout
|
|
||||||
CLIENT_ARCH: client.commands.arch.stdout
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
:::tip
|
||||||
You can also capture `stderr` for errors and provide `stdin` for input.
|
You can also capture `stderr` for errors and provide `stdin` for input.
|
||||||
|
:::
|
||||||
|
|
||||||
## Platform
|
## Platform
|
||||||
|
|
||||||
If you need the current platform though, there’s a more portable way than running `uname` like in the previous example:
|
If you need the current platform though, there’s a more portable way than running `uname` like in the previous example:
|
||||||
|
|
||||||
```cue
|
```cue file=../tests/core-concepts/client/plans/platform.cue
|
||||||
dagger.#Plan & {
|
|
||||||
client: platform: _
|
|
||||||
|
|
||||||
actions: {
|
|
||||||
build: docker.#Run & {
|
|
||||||
env: {
|
|
||||||
CLIENT_OS: client.platform.os
|
|
||||||
CLIENT_ARCH: client.platform.arch
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
@ -27,26 +27,7 @@ dagger.#Plan & {
|
|||||||
|
|
||||||
You may need to trim the whitespace, especially when reading from a file:
|
You may need to trim the whitespace, especially when reading from a file:
|
||||||
|
|
||||||
```cue
|
```cue file=../tests/core-concepts/secrets/plans/file.cue
|
||||||
dagger.#Plan & {
|
|
||||||
// Path may be absolute, or relative to current working directory
|
|
||||||
client: filesystem: ".registry": read: {
|
|
||||||
// CUE type defines expected content
|
|
||||||
contents: dagger.#Secret
|
|
||||||
}
|
|
||||||
actions: {
|
|
||||||
registry: dagger.#TrimSecret & {
|
|
||||||
input: client.filesystem.".registry".read.contents
|
|
||||||
}
|
|
||||||
pull: docker.#Pull & {
|
|
||||||
source: "myprivate/image"
|
|
||||||
auth: {
|
|
||||||
username: "_token_"
|
|
||||||
secret: registry.output
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## SOPS
|
## SOPS
|
||||||
@ -59,30 +40,5 @@ sops:
|
|||||||
...
|
...
|
||||||
```
|
```
|
||||||
|
|
||||||
```cue title="main.cue"
|
```cue file=../tests/core-concepts/secrets/plans/sops.cue title="main.cue"
|
||||||
dagger.#Plan & {
|
|
||||||
client: commands: sops: {
|
|
||||||
name: "sops"
|
|
||||||
args: ["-d", "./secrets.yaml"]
|
|
||||||
stdout: dagger.#Secret
|
|
||||||
}
|
|
||||||
|
|
||||||
actions: {
|
|
||||||
// Makes the yaml keys easily accessible
|
|
||||||
secrets: dagger.#DecodeSecret & {
|
|
||||||
input: client.commands.sops.stdout
|
|
||||||
format: "yaml"
|
|
||||||
}
|
|
||||||
|
|
||||||
run: docker.#Run & {
|
|
||||||
mounts: secret: {
|
|
||||||
dest: "/run/secrets/token"
|
|
||||||
contents: secrets.output.myToken
|
|
||||||
}
|
|
||||||
// Do something with `/run/secrets/token`
|
|
||||||
...
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
18
docs/tests/core-concepts/client/plans/cmd.cue
Normal file
18
docs/tests/core-concepts/client/plans/cmd.cue
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
dagger.#Plan & {
|
||||||
|
client: commands: {
|
||||||
|
os: {
|
||||||
|
name: "uname"
|
||||||
|
args: ["-s"]
|
||||||
|
}
|
||||||
|
arch: {
|
||||||
|
name: "uname"
|
||||||
|
args: ["-m"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
actions: build: go.#Build & {
|
||||||
|
os: client.commands.os.stdout
|
||||||
|
arch: client.commands.arch.stdout
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
}
|
14
docs/tests/core-concepts/client/plans/env.cue
Normal file
14
docs/tests/core-concepts/client/plans/env.cue
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
dagger.#Plan & {
|
||||||
|
client: env: {
|
||||||
|
REGISTRY_USER: string
|
||||||
|
REGISTRY_TOKEN: dagger.#Secret
|
||||||
|
}
|
||||||
|
|
||||||
|
actions: pull: docker.#Pull & {
|
||||||
|
source: "registry.example.com/image"
|
||||||
|
auth: {
|
||||||
|
username: client.env.REGISTRY_USER
|
||||||
|
secret: client.env.REGISTRY_TOKEN
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
15
docs/tests/core-concepts/client/plans/file.cue
Normal file
15
docs/tests/core-concepts/client/plans/file.cue
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import (
|
||||||
|
"encoding/yaml"
|
||||||
|
// ...
|
||||||
|
)
|
||||||
|
|
||||||
|
dagger.#Plan & {
|
||||||
|
client: filesystem: "config.yaml": write: {
|
||||||
|
// Convert a CUE value into a YAML formatted string
|
||||||
|
contents: yaml.Marshal(actions.pull.output.config)
|
||||||
|
}
|
||||||
|
|
||||||
|
actions: pull: docker.#Pull & {
|
||||||
|
source: "alpine"
|
||||||
|
}
|
||||||
|
}
|
15
docs/tests/core-concepts/client/plans/fs.cue
Normal file
15
docs/tests/core-concepts/client/plans/fs.cue
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
dagger.#Plan & {
|
||||||
|
// Path may be absolute, or relative to current working directory
|
||||||
|
client: filesystem: ".": read: {
|
||||||
|
// CUE type defines expected content
|
||||||
|
contents: dagger.#FS
|
||||||
|
exclude: ["node_modules"]
|
||||||
|
}
|
||||||
|
|
||||||
|
actions: {
|
||||||
|
copy: docker.Copy & {
|
||||||
|
contents: client.filesystem.".".read.contents
|
||||||
|
}
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
}
|
9
docs/tests/core-concepts/client/plans/platform.cue
Normal file
9
docs/tests/core-concepts/client/plans/platform.cue
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
dagger.#Plan & {
|
||||||
|
client: _
|
||||||
|
|
||||||
|
actions: build: go.#Build & {
|
||||||
|
os: client.platform.os
|
||||||
|
arch: client.platform.arch
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
}
|
20
docs/tests/core-concepts/client/plans/unix.cue
Normal file
20
docs/tests/core-concepts/client/plans/unix.cue
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
dagger.#Plan & {
|
||||||
|
client: filesystem: "/var/run/docker.sock": read: contents: dagger.#Service
|
||||||
|
|
||||||
|
actions: {
|
||||||
|
image: alpine.#Build & {
|
||||||
|
packages: "docker-cli": {}
|
||||||
|
}
|
||||||
|
run: docker.#Run & {
|
||||||
|
input: image.output
|
||||||
|
mounts: docker: {
|
||||||
|
dest: "/var/run/docker.sock"
|
||||||
|
contents: client.filesystem."/var/run/docker.sock".read.contents
|
||||||
|
}
|
||||||
|
command: {
|
||||||
|
name: "docker"
|
||||||
|
args: ["info"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
23
docs/tests/core-concepts/client/plans/windows.cue
Normal file
23
docs/tests/core-concepts/client/plans/windows.cue
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
dagger.#Plan & {
|
||||||
|
client: filesystem: "//./pipe/docker_engine": read: {
|
||||||
|
contents: dagger.#Service
|
||||||
|
type: "npipe"
|
||||||
|
}
|
||||||
|
|
||||||
|
actions: {
|
||||||
|
image: alpine.#Build & {
|
||||||
|
packages: "docker-cli": {}
|
||||||
|
}
|
||||||
|
run: docker.#Run & {
|
||||||
|
input: image.output
|
||||||
|
mounts: docker: {
|
||||||
|
dest: "/var/run/docker.sock"
|
||||||
|
contents: client.filesystem."//./pipe/docker_engine".read.contents
|
||||||
|
}
|
||||||
|
command: {
|
||||||
|
name: "docker"
|
||||||
|
args: ["info"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
fmt.Println("Hello, 世界")
|
||||||
|
}
|
@ -0,0 +1,3 @@
|
|||||||
|
module dagger.io/test
|
||||||
|
|
||||||
|
go 1.17
|
19
docs/tests/core-concepts/secrets/plans/file.cue
Normal file
19
docs/tests/core-concepts/secrets/plans/file.cue
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
dagger.#Plan & {
|
||||||
|
// Path may be absolute, or relative to current working directory
|
||||||
|
client: filesystem: ".registry": read: {
|
||||||
|
// CUE type defines expected content
|
||||||
|
contents: dagger.#Secret
|
||||||
|
}
|
||||||
|
actions: {
|
||||||
|
registry: dagger.#TrimSecret & {
|
||||||
|
input: client.filesystem.".registry".read.contents
|
||||||
|
}
|
||||||
|
pull: docker.#Pull & {
|
||||||
|
source: "registry.example.com/image"
|
||||||
|
auth: {
|
||||||
|
username: "_token_"
|
||||||
|
secret: registry.output
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
23
docs/tests/core-concepts/secrets/plans/sops.cue
Normal file
23
docs/tests/core-concepts/secrets/plans/sops.cue
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
dagger.#Plan & {
|
||||||
|
client: commands: sops: {
|
||||||
|
name: "sops"
|
||||||
|
args: ["-d", "./secrets.yaml"]
|
||||||
|
stdout: dagger.#Secret
|
||||||
|
}
|
||||||
|
|
||||||
|
actions: {
|
||||||
|
// Makes the yaml keys easily accessible
|
||||||
|
secrets: dagger.#DecodeSecret & {
|
||||||
|
input: client.commands.sops.stdout
|
||||||
|
format: "yaml"
|
||||||
|
}
|
||||||
|
|
||||||
|
run: docker.#Run & {
|
||||||
|
mounts: secret: {
|
||||||
|
dest: "/run/secrets/token"
|
||||||
|
contents: secrets.output.myToken
|
||||||
|
}
|
||||||
|
// Do something with `/run/secrets/token`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user