# deploy

> Deploy a repository as a new app in one call: a public one on any git host, or one of your own repos.

`noclick.deploy` copies the repository (or takes your repo as it is), makes the app, sets the secrets it reads,
gives it the key to your account it asks for (or has the deploy ask the account's owner), and deploys production.
Ask with `dry_run=True` first to see what it would do, what it would cost a month and what it asks of you, with
nothing made.

```python
plan = noclick.deploy("https://github.com/acme/console", dry_run=True)
print(plan.runtime, f"${plan.estimate.monthly_usd:.2f} a month", plan.missing_secrets)

app = noclick.deploy("https://github.com/acme/console", secrets={"STRIPE_SECRET_KEY": "sk_live_..."}).wait()
print(app.url)
```

## noclick.deploy

```python
noclick.deploy(
    source, *, dry_run=False, ref=None, name=None, secrets=None, account_key=None,
    key_spend_cap_usd_per_month=None, user=..., client=None
) -> DeployPlan | RepoDeploy
```

Deploy `source` as a new app of yours: a public git repository's https URL, on any host (copied into a new
repo of yours, the one branch it deploys), or one of your own repos (a `Repo`, its id or its name, deployed as
it is). `ref` names a branch, tag or full commit sha (the default branch otherwise).

It makes the app (`name`, or the repository's own name, or the first of name-2, name-3... free), sets the
secrets its noclick.json says its code reads (NoClick makes the ones marked `generate`; `secrets` brings
the rest, by name), gives the app the key to your account it asks for when `account_key` names exactly its
scopes (only you signed in, or a key holding `keys:create`; otherwise the deploy asks the account's owner, as
every deploy does), and deploys production.

Never a private repository, a URL with a login, an `ssh://` or `git@` address, or another account's repo:
push a private one to a repo of yours with git and deploy that. What can't deploy is refused before anything is
made. Needs the `apps` and `repos` scopes.

Parameters:

- `source` (`Any`, required)
- `dry_run` (`bool`, default `False`)
- `ref` (`str | None`, default `None`)
- `name` (`str | None`, default `None`)
- `secrets` (`Mapping[str, str] | None`, default `None`)
- `account_key` (`Sequence[str] | None`, default `None`)
- `key_spend_cap_usd_per_month` (`float | None`, default `None`)
- `user` (`Any`, default: the current user): Who the call acts for. Defaults to the user set by `noclick.as_user` (none: the account itself).
- `client` (`Client | None`, default `None`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.

Returns: `DeployPlan | RepoDeploy` A `RepoDeploy` operation whose `wait()` gives a `DeployResult` (the app's `url`, where its key
stands, the passwords to read once); with `dry_run=True`, a `DeployPlan` of what it would do, what it
would cost a month and what it asks of you, with nothing made.

Usage:

See what it would do first:

```python
plan = noclick.deploy("https://github.com/acme/console", dry_run=True)
print(plan.runtime, f"${plan.estimate.monthly_usd:.2f} a month")
if plan.account_key:
    for line in plan.account_key.can:
        print("its key can", line["can"])
print("you set:", plan.missing_secrets)
```

Then deploy it, bringing the secrets you set, and read the password NoClick made once:

```python
done = noclick.deploy("https://github.com/acme/console",
                      secrets={"STRIPE_SECRET_KEY": "sk_live_..."}).wait()
print(done.url)
app = noclick.Project.from_id(done.project_id)
for name in done.to_reveal:
    print(name, app.secrets.reveal(name))
```

One of your own repos, as it is:

```python
done = noclick.deploy("console", name="console-live").wait()
```

## noclick.DeployPlan

```python
class DeployPlan
```

What a deploy would do, with nothing made: `noclick.deploy(..., dry_run=True)`.

| Attribute | Type | Description |
| --- | --- | --- |
| `source` | `dict[str, Any]` | What it read: `kind` (`url` or `repo`), the `url` or `repo_id`, and the `commit` and `branch`. |
| `name` | `str` | The app's name (and its copy's): the one you gave, or the first free one from the repository's. |
| `runtime` | `str | None` | Where the app would run (`edge` or `container`), and why; None when it won't run as it stands. |
| `framework` | `str | None` |  |
| `reason` | `str | None` |  |
| `noclick_json` | `bool` | Whether the repository has a noclick.json. |
| `account_key` | `DeployKeyAsk | None` |  |
| `secrets` | `list[DeploySecret]` |  |
| `missing_secrets` | `list[str]` | The secrets you set that the call would have to bring: a deploy without them is refused. |
| `refused` | `dict[str, str] | None` | Why it won't deploy as it stands (`message`, `next_step`); None when it will. |
| `estimate` | `Estimate` | What it would cost a month, priced for your account (usage-based: what's charged is what's used). |
| `funds` | `dict[str, Any]` | Whether your account can pay to run it now (`ok`); if not, the `refusal` a deploy would meet. |
| `makes` | `list[str]` | What it makes: `repo` (a copy) and `project` (the app). |
| `raw` | `dict[str, Any]` | The response JSON exactly as the API sent it. |

## noclick.DeployResult

```python
class DeployResult
```

A deploy that ended live: what `RepoDeploy.wait()` gives.

| Attribute | Type | Description |
| --- | --- | --- |
| `project_id` | `str` |  |
| `name` | `str` |  |
| `url` | `str | None` | Where production serves it. |
| `repo_id` | `str | None` |  |
| `deployment_id` | `str | None` |  |
| `commit` | `str | None` |  |
| `account_key` | `dict[str, Any] | None` | Where its key to the account stands (`status`: `granted`, `waiting` for the owner, `declined`...), None when the repository asks for none. |
| `to_reveal` | `list[str]` | The passwords NoClick made that nobody has read yet: read each once with `app.secrets.reveal(name)`. |
| `raw` | `dict[str, Any]` | The response JSON exactly as the API sent it. |

## noclick.DeploySecret

```python
class DeploySecret
```

A secret the repository's noclick.json says its code reads.

| Attribute | Type | Description |
| --- | --- | --- |
| `name` | `str` |  |
| `generate` | `str | None` | What NoClick makes for it (`secret` or `password`); None for one you set. |
| `description` | `str | None` | What it is, in the repository's words. |
| `required` | `bool` | For one you set: whether a deploy without it is refused. One NoClick makes is always there. |
| `given` | `bool` | For one you set: whether the call brought its value. |
| `shown_once` | `bool` | For one NoClick makes: whether it's a password you read once (`app.secrets.reveal`). |

## noclick.DeployKeyAsk

```python
class DeployKeyAsk
```

The key to your account the repository asks for, as you're shown it before you agree.

| Attribute | Type | Description |
| --- | --- | --- |
| `scopes` | `list[str]` |  |
| `can` | `list[dict[str, Any]]` | What the key can do, a line per scope (`scope`, `can`, `reads_secrets`). |
| `cannot` | `list[str]` | What no app's key can do, whatever it holds. |
| `note` | `str` | That whoever can change the app's code acts with the key. |
| `given_by` | `str` | `you`: you give it in the call (send `account_key` with these scopes); `deploy`: the deploy asks for it. |
| `at_deploy` | `str | None` | When the deploy asks: `asks_owner` (the account's owner approves it from a link), `given` or `denied`, as the account's `app_key` approval setting decides. |

## noclick.RepoDeploy

```python
class RepoDeploy(Operation)
```

A repository being deployed as a new app: the operation `noclick.deploy` returns. `wait()` gives a
`DeployResult` once it's live; `progress` shows each stage (copying, making the app, setting its secrets and
key, building and deploying). A deploy that fails after the copy keeps the app and its repo, and its error says
how to go on.

| Attribute | Type | Description |
| --- | --- | --- |
| `project_id` | `str | None` | The new app's id, once it's made. |
| `repo_id` | `str | None` | The repo it deploys: the copy, or yours. |
| `deployment_id` | `str | None` | The production deployment, once it's started. |
