2022-03-07 14:12:39 +01:00
|
|
|
|
---
|
|
|
|
|
slug: /1203/client
|
2022-04-13 15:58:51 +02:00
|
|
|
|
displayed_sidebar: '0.2'
|
2022-03-07 14:12:39 +01:00
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
# Interacting with the client
|
|
|
|
|
|
|
|
|
|
`dagger.#Plan` has a `client` field that allows interaction with the local machine where the `dagger` command line client is run. You can:
|
|
|
|
|
|
|
|
|
|
- Read and write files and directories;
|
|
|
|
|
- Use local sockets;
|
|
|
|
|
- Load environment variables;
|
|
|
|
|
- Run commands;
|
|
|
|
|
- Get current platform.
|
|
|
|
|
|
|
|
|
|
## Accessing the file system
|
|
|
|
|
|
|
|
|
|
You may need to load a local directory as a `dagger.#FS` type in your plan:
|
|
|
|
|
|
2022-03-10 13:50:21 +01:00
|
|
|
|
```cue file=../tests/core-concepts/client/plans/fs.cue
|
2022-04-13 15:58:51 +02:00
|
|
|
|
|
2022-03-07 14:12:39 +01:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
It’s also easy to write a file locally:
|
|
|
|
|
|
2022-03-10 13:50:21 +01:00
|
|
|
|
```cue file=../tests/core-concepts/client/plans/file.cue
|
2022-04-13 15:58:51 +02:00
|
|
|
|
|
2022-03-07 14:12:39 +01:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Using a local socket
|
|
|
|
|
|
|
|
|
|
You can use a local socket in an action:
|
|
|
|
|
|
|
|
|
|
import Tabs from '@theme/Tabs';
|
|
|
|
|
import TabItem from '@theme/TabItem';
|
2022-03-24 19:55:24 +01:00
|
|
|
|
import BrowserOnly from '@docusaurus/BrowserOnly';
|
2022-03-07 14:12:39 +01:00
|
|
|
|
|
2022-03-24 19:55:24 +01:00
|
|
|
|
<BrowserOnly>
|
|
|
|
|
{() =>
|
|
|
|
|
<Tabs defaultValue={ window.navigator.userAgent.indexOf('Win') != -1 ? 'windows': 'unix'} groupId="client-env">
|
2022-03-07 14:12:39 +01:00
|
|
|
|
|
|
|
|
|
<TabItem value="unix" label="Linux/macOS">
|
|
|
|
|
|
2022-03-10 13:50:21 +01:00
|
|
|
|
```cue file=../tests/core-concepts/client/plans/unix.cue
|
2022-04-13 15:58:51 +02:00
|
|
|
|
|
2022-03-07 14:12:39 +01:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
</TabItem>
|
|
|
|
|
|
|
|
|
|
<TabItem value="windows" label="Windows">
|
|
|
|
|
|
2022-03-10 13:50:21 +01:00
|
|
|
|
```cue file=../tests/core-concepts/client/plans/windows.cue
|
2022-04-13 15:58:51 +02:00
|
|
|
|
|
2022-03-07 14:12:39 +01:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
</TabItem>
|
|
|
|
|
</Tabs>
|
2022-03-24 19:55:24 +01:00
|
|
|
|
}
|
|
|
|
|
</BrowserOnly>
|
2022-03-07 14:12:39 +01:00
|
|
|
|
|
|
|
|
|
## Environment variables
|
|
|
|
|
|
|
|
|
|
Environment variables can be read from the local machine as strings or secrets, just specify the type:
|
|
|
|
|
|
2022-03-10 13:50:21 +01:00
|
|
|
|
```cue file=../tests/core-concepts/client/plans/env.cue
|
2022-04-13 15:58:51 +02:00
|
|
|
|
|
2022-03-07 14:12:39 +01:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Running commands
|
|
|
|
|
|
|
|
|
|
Sometimes you need something more advanced that only a local command can give you:
|
|
|
|
|
|
2022-03-10 13:50:21 +01:00
|
|
|
|
```cue file=../tests/core-concepts/client/plans/cmd.cue
|
2022-04-13 15:58:51 +02:00
|
|
|
|
|
2022-03-07 14:12:39 +01:00
|
|
|
|
```
|
|
|
|
|
|
2022-03-10 13:50:21 +01:00
|
|
|
|
:::tip
|
2022-03-07 14:12:39 +01:00
|
|
|
|
You can also capture `stderr` for errors and provide `stdin` for input.
|
2022-03-10 13:50:21 +01:00
|
|
|
|
:::
|
2022-03-07 14:12:39 +01:00
|
|
|
|
|
|
|
|
|
## Platform
|
|
|
|
|
|
|
|
|
|
If you need the current platform though, there’s a more portable way than running `uname` like in the previous example:
|
|
|
|
|
|
2022-03-10 13:50:21 +01:00
|
|
|
|
```cue file=../tests/core-concepts/client/plans/platform.cue
|
2022-04-13 15:58:51 +02:00
|
|
|
|
|
2022-03-07 14:12:39 +01:00
|
|
|
|
```
|