# Vary Course

## Push and Test an App on Via

Create the first operator session, connect a local Vary project, test it, push a deploy, and inspect deploy output.

### Provision

#### Create an operator and app on the server

Mint a one-time admin token and create the app record that will receive source pushes.

```bash
# Create a one-time admin token for the first operator.
via admin create alice

# Create the server-side app record and bare Git repo.
via app ensure my-api --owner alice

```

Run: `via app ensure my-api --owner alice`

Expected output:

```text
(?i)created|exists|ensured|my-api
```

#### Log in from your workstation

Exchange the one-time admin token for workstation credentials.

```bash
# Exchange the one-time admin token for workstation credentials.
vary login https://vary.example.com --name alice --token-stdin

```

Run: `vary login https://vary.example.com --name alice --token-stdin`

Expected output:

```text
(?i)session|credentials|logged in|expires
```

#### Connect a local project

Record the Via server and app id in the project's `vary.toml`.

```bash
# Work from the local Vary project you want to deploy.
cd my-api

# Record the Via server URL and app name in vary.toml.
vary app init --server https://vary.example.com --app my-api

# Confirm only the deployment config changed.
git status --short

# Commit the config so deploys can push a clean tree.
git add vary.toml
git commit -m "Configure Via deployment"

```

Run: `vary app init --server https://vary.example.com --app my-api`

Expected output:

```text
(?m)^.*vary\.toml.*$
```

### Test and push

#### Test locally and deploy committed source

Run the project's tests, push the current Git commit to Via, and wait for the deploy result.

```bash
# Run local tests before pushing source to Via.
vary test

# Via deploys expect committed source by default.
git status --short

# Push the current commit and wait for the deploy result.
vary app deploy

# Confirm the app's current deploy and runtime state.
vary app status

```

Run: `vary app deploy`

Expected output:

```text
(?i)\brunning\b
```

#### Inspect build output from your workstation

Find the build id, inspect the build detail, and stream test logs for the deploy.

```bash
# List recent server builds for the app.
vary app builds --app my-api

# Inspect one build record in detail.
vary app build <build-id> --app my-api

# Stream the test logs when a result needs detail.
vary app logs --tests <build-id> --app my-api

```

Run: `vary app builds --app my-api`

Expected output:

```text
(?i)build|running|passed|failed
```

#### Read the test result on the server

Confirm the server saw the same test result by reading Via's local state directory.

```bash
# Read the server-side test result directly from the Via state directory.
vary app tests <build-id> --app my-api --local --state-dir /var/lib/via

```

Run: `vary app tests <build-id> --app my-api --local --state-dir /var/lib/via`

Expected output:

```text
(?i)passed|failed|tests
```

### Route and observe

#### Attach traffic and read logs

Request a hostname, verify ownership, add a route, and stream runtime logs.

```bash
# Ask Via to create a domain ownership challenge.
vary app domain request my-api my-api.apps.example.com --target prod

# Confirm the required DNS record is visible.
vary app domain verify my-api my-api.apps.example.com --target prod

# Attach the verified hostname to the running app target.
vary app route add my-api my-api.apps.example.com --target prod --port 8080

# Stream runtime logs from the active container.
vary app logs --runtime

```

Run: `vary app logs --runtime`

Expected output:

```text
(?m)^.*my-api.*$
```

