# DanubeData CLI

The DanubeData CLI (`danube`) lets you manage your entire DanubeData infrastructure from the terminal — VPS instances, object storage, static sites, and serverless containers. Built with Node.js, it provides interactive prompts, real-time build tracking, and CI/CD-friendly configuration.

## Installation

Requires Node.js 18 or later.

```bash
npm install -g @danubedata/cli
```

Verify the installation:

```bash
danube --version
```

## Authentication

### Browser auth (recommended)

```bash
danube auth
```

Opens your browser to log in and authorize the CLI automatically — no manual token copying.

### Interactive login

```bash
danube login
```

You will be prompted to enter your API token. To create a token:

1. Log in to the DanubeData dashboard
2. Go to **Settings > API Tokens**
3. Click **Create New Token** and copy the token

### Token flag

```bash
danube login --token YOUR_API_TOKEN
```

### Environment variable

Set the `DANUBE_TOKEN` environment variable to skip the login step entirely. This is the recommended method for CI/CD pipelines.

```bash
export DANUBE_TOKEN="your-api-token"
```

### Check your identity

```bash
danube whoami
```

Shows your name, email, and team memberships.

### Log out

```bash
danube logout
```

Removes stored credentials from `~/.danube/config.json`.

## Configuration

### Credentials

Stored at `~/.danube/config.json` with `0600` permissions:

```json
{
  "token": "your-api-token"
}
```

### Project configuration

Created by `danube pages link`, stored at `.danube/project.json`:

```json
{
  "siteId": 42,
  "teamId": 1,
  "siteName": "my-portfolio",
  "defaultDomain": "my-portfolio-abc.pages.danubedata.ro"
}
```

### Build configuration

Optional `danube.json` in your project root:

```json
{
  "outputDir": "dist",
  "ignore": ["*.map", "test/**"]
}
```

- **outputDir** — Directory to deploy (default: current directory)
- **ignore** — Additional file patterns to exclude from the deployment

### Environment variables

| Variable | Description |
|----------|-------------|
| `DANUBE_TOKEN` | API token (alternative to `danube login`) |
| `DANUBE_API_BASE` | Override API base URL (default: `https://danubedata.ro`) |
| `DANUBE_SITE_ID` | Site ID for headless CI/CD (skips interactive linking) |
| `DANUBE_TEAM_ID` | Team ID for headless CI/CD |
| `DANUBE_SITE_NAME` | Site name for headless CI/CD |
| `CI` | Suppresses update notifications |
| `DANUBE_NO_UPDATE_CHECK` | Suppresses update notifications |

## Commands overview

### General

| Command | Description |
|---------|-------------|
| `danube auth` | Authenticate via browser (recommended) |
| `danube login` | Authenticate with an API token |
| `danube logout` | Remove stored credentials |
| `danube whoami` | Show current user and teams |

### VPS Instances (`danube vps`)

| Command | Description |
|---------|-------------|
| `danube vps ls` | List all VPS instances |
| `danube vps create` | Create a new VPS (interactive or flags) |
| `danube vps get <id>` | Show VPS details and connection info |
| `danube vps update <id>` | Update VPS config (must be stopped) |
| `danube vps delete <id>` | Delete a VPS instance |
| `danube vps start <id>` | Start a stopped VPS |
| `danube vps stop <id>` | Stop a running VPS |
| `danube vps reboot <id>` | Reboot a running VPS |
| `danube vps reinstall <id>` | Reinstall OS (destroys all data) |
| `danube vps status <id>` | Show current status and capabilities |
| `danube vps metrics <id>` | Show CPU/memory/storage/network usage |
| `danube vps password <id>` | Show SSH password (with confirmation) |
| `danube vps images` | List available OS images |

### Object Storage (`danube storage`)

| Command | Description |
|---------|-------------|
| `danube storage buckets ls` | List all buckets |
| `danube storage buckets create` | Create a new bucket |
| `danube storage buckets get <id>` | Show bucket details |
| `danube storage buckets update <id>` | Update bucket settings |
| `danube storage buckets delete <id>` | Delete a bucket |
| `danube storage buckets metrics <id>` | Show current bucket metrics snapshot |
| `danube storage buckets metrics trend <id>` | Time-series trend (sparkline/table/csv/json) |
| `danube storage buckets metrics top <id>` | Top objects by size/egress/requests |
| `danube storage buckets metrics health <id>` | Pending multipart uploads, deleted versions, last check |
| `danube storage keys ls` | List all access keys |
| `danube storage keys create` | Create a new access key |
| `danube storage keys get <id>` | Show access key details |
| `danube storage keys revoke <id>` | Revoke an access key |

### Static Sites (`danube pages`)

| Command | Description |
|---------|-------------|
| `danube pages link` | Link current directory to a static site |
| `danube pages deploy` | Deploy static site files |
| `danube pages deployments ls` | List deployments |
| `danube pages deployments rollback <rev>` | Roll back to a previous deployment |
| `danube pages domains ls` | List custom domains |
| `danube pages domains add <domain>` | Add a custom domain |
| `danube pages domains remove <domain>` | Remove a custom domain |
| `danube pages domains verify <domain>` | Verify domain DNS |

### Serverless Containers (`danube rapids`)

| Command | Description |
|---------|-------------|
| `danube rapids ls` | List serverless containers |
| `danube rapids create` | Create a new container |
| `danube rapids deploy <name>` | Deploy from local directory |
| `danube rapids show <name>` | Show container details |
| `danube rapids update <name>` | Update container configuration |
| `danube rapids rm <name>` | Delete a container |
| `danube rapids deployments <name>` | List container deployments |
| `danube rapids usage <name>` | Show usage and billing |

## File exclusion

When packaging files for deployment, the CLI automatically excludes:

1. `.git`, `node_modules`, `.danube` (always excluded)
2. Patterns from `.gitignore`
3. Patterns from `.daubeignore` (custom ignore file)
4. Extra patterns from `danube.json` `ignore` field

## CI/CD usage

For automated deployments without interactive prompts, set environment variables:

```bash
export DANUBE_TOKEN="your-api-token"
export DANUBE_SITE_ID="42"
export DANUBE_TEAM_ID="1"

danube pages deploy --dir ./dist --no-wait
```

### GitHub Actions example

```yaml
name: Deploy to DanubeData
on:
  push:
    branches: [main]

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - uses: actions/setup-node@v4
        with:
          node-version: 20

      - run: npm ci && npm run build

      - run: npm install -g @danubedata/cli

      - run: danube pages deploy --dir ./dist
        env:
          DANUBE_TOKEN: ${{ secrets.DANUBE_TOKEN }}
          DANUBE_SITE_ID: ${{ secrets.DANUBE_SITE_ID }}
          DANUBE_TEAM_ID: ${{ secrets.DANUBE_TEAM_ID }}
```

## Update notifications

The CLI checks for updates automatically (once per 24 hours). Notifications are suppressed in CI environments or when `DANUBE_NO_UPDATE_CHECK` is set.

## Exit codes

| Code | Meaning |
|------|---------|
| 0 | Success |
| 1 | Error (authentication, API, validation) |
| 130 | Interrupted (Ctrl+C during polling) |

## Next steps

- [CLI: VPS Instances](https://docs.danubedata.ro/cli-vps) — Manage VPS instances
- [CLI: Object Storage](https://docs.danubedata.ro/cli-storage) — Manage buckets and access keys
- [CLI: Static Sites](https://docs.danubedata.ro/cli-pages) — Deploy and manage static sites
- [CLI: Serverless Containers](https://docs.danubedata.ro/cli-serverless) — Deploy and manage containers
- [API Authentication](https://docs.danubedata.ro/api-authentication) — Create API tokens

---

**Questions?** Contact support at support@danubedata.ro
