> ## Documentation Index
> Fetch the complete documentation index at: https://docs.blobhub.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Building an App

> One app from a git repository to a version another organization installs: build, try, commit, share.

This page takes one app from a git repository to an install in another organization, in the order a developer meets
each step. What an app is, and how an organization installs, upgrades and uninstalls one, is on
[Apps](https://docs.blobhub.io/general/apps.md); each step below links to its reference under Blob Types and in the CLI.

The example is Field Reports, `acme-corp/field-reports`: an app that turns field technicians' notes into reports, with
a workflow blob `flows` and a scheduler blob `schedules`.

```mermaid theme={null}
flowchart LR
  repo["Git repository<br/>app.yaml, blobs/,<br/>README.md, LICENSE"]
  build["build/<br/>git-ignored"]
  draft["App blob draft<br/>acme-corp/field-reports"]
  dev["Development installation<br/>reports-dev, editable"]
  ver["Version 0.2.0<br/>never reopened"]
  inst["Another organization's<br/>installation reports"]
  repo -->|build| build
  build -->|push| draft
  draft -->|"push --install"| dev
  dev -->|pull| repo
  draft -->|commit| ver
  ver -->|"share, install"| inst
```

## The repository

The repository is laid out as the app blob it fills. `app.yaml` sits at the root, each blob of the app is one folder
under `blobs/` holding its `blob.yaml` manifest, and `README.md` and `LICENSE` become the app blob's Readme and License.

```text theme={null}
field-reports/
  app.yaml                    the app: its version, what an install asks for, the accounts it acts as
  README.md  LICENSE          the app blob's Readme and License
  blobs/
    flows/                    a workflow blob: blob.yaml, definitions/, src/
    schedules/                a scheduler blob: blob.yaml
  schemas/config.json         what the config input is checked against
  build/                      git-ignored: written by build, uploaded by push
  tests/                      the repository's own; never uploaded
```

* **A folder is a blob.** Blobs are found by folder, never listed, and the folder's name is the blob's alias in the
  app: installed as `reports`, Field Reports makes `reports-flows` and `reports-schedules`.
* **`build/` is git-ignored.** `blobhub app build` writes it from the sources, and the app blob holds it file for file.
  The build warns with `BUILD_NOT_IGNORED` while git does not ignore it.
* **Everything else is the repository's own,** such as `tests/`, and is never uploaded
  ([The repository](https://docs.blobhub.io/blob-types/app/app-yaml.md#the-repository)).

`app.yaml` opens with the app itself. `app.alias` names the app blob in the organization the CLI works in, the app's
home organization, so `field-reports` is `acme-corp/field-reports` ([App](https://docs.blobhub.io/blob-types/app/app-yaml.md#app)):

```yaml theme={null}
# app.yaml
type: app
version: "1.0"                     # this format's version
app:
  alias: field-reports             # the app blob that push fills, in the home organization
  label: Field Reports
  version: 0.2.0
  description: Notes from field technicians, turned into reports.
```

Each folder's `blob.yaml` says what its blob holds once installed. The workflow blob lists its definitions, each naming
its file with `file`; `build` tells the CLI what to compile into a definition, here a code component's entry point in
`src/`:

```yaml theme={null}
# blobs/flows/blob.yaml
type: blob
version: "1.0"
blob_type: blobhub.compute.workflow
limits:                            # what this blob needs of the organization; an install checks, never raises
  - {id: blobhub.compute.workflow.executions_per_session, at_least: 400}   # a year of nightly runs, and some by hand
definitions:
  - alias: reports-compile
    category: workflow
    file: definitions/compile.json
    build: {code: {summarize: src/summarize.py}}   # component id: entry point
  - {alias: reports-migrate, category: workflow, file: definitions/migrate.json}
  - {alias: reports-desk, category: playground, file: definitions/desk.json}
```

`limits` says what the blob needs of the organization. Field Reports needs 400 executions in its `reports` session, a
year of nightly runs and some by hand; the bound assumes the organization's retention, and the app's README says so.
An install checks it and never raises it ([Limits an app needs](https://docs.blobhub.io/general/apps.md#limits-an-app-needs)). `describe`
checks that a declaration is well formed, so `push` prints its problems and `commit` refuses a version that has any,
and a plain `blobhub workflow deploy` of the same file ignores it and says so
([Limits](https://docs.blobhub.io/blob-types/app/blob-yaml.md#limits)).

[`blob.yaml`](https://docs.blobhub.io/blob-types/app/blob-yaml) has the manifest of each blob type an app holds: a
[workflow](https://docs.blobhub.io/blob-types/app/blob-yaml.md#workflow), a [scheduler](https://docs.blobhub.io/blob-types/app/blob-yaml.md#scheduler) and an
[ONNX model](https://docs.blobhub.io/blob-types/app/blob-yaml.md#onnx-model).

## Inputs, accounts and templates

One version installs in many organizations, so what differs between them is not written into the app. Four things
carry it:

* **Inputs** are what an install asks for. Field Reports asks for `config`, a document of report settings checked
  against `schemas/config.json`, and `weather_key`, an optional secret ([Inputs](https://docs.blobhub.io/blob-types/app/app-yaml.md#inputs)).
* **Accounts** are the service accounts the app acts as, so its runs are its own and not the installing admin's.
  `runner`, installed as `reports-runner`, is a member of the installation's blobs with WRITE and of nothing else
  ([Accounts](https://docs.blobhub.io/blob-types/app/app-yaml.md#accounts)).
* **Credentials** are stored on an account, where its runs find them by alias: `weather` holds the secret input,
  `blobhub` a key of the account that the platform mints, and `sync_token` starts empty for the app to fill
  ([Credentials](https://docs.blobhub.io/blob-types/app/app-yaml.md#credentials)).
* **Templates** are the values a manifest fills in at install, `{{ … }}`, from the installation's inputs, blobs,
  accounts and the installation itself ([Templates](https://docs.blobhub.io/blob-types/app/templates.md)).

```yaml theme={null}
# app.yaml, continued
inputs:                            # what an install asks for
  - {name: config, kind: document, label: Report settings, schema: schemas/config.json}
  - {name: weather_key, kind: secret, label: Weather API key, required: false}
accounts:                          # service accounts the app acts as, and the secrets they hold
  - alias: runner
    label: Field Reports runner
    credentials:
      - {alias: weather, type: api_key, body: {api_key: "{{ inputs.weather_key }}"}}
      - {alias: blobhub, account_key: true}            # a key of this account, minted by the platform
      - {alias: sync_token, writable: true}            # created empty; the app fills it
```

A manifest reads them through templates. The workflow blob writes the `config` document into its session as an
object:

```yaml theme={null}
# blobs/flows/blob.yaml, continued
sessions:                          # sessions an install makes sure exist, and the objects it writes
  - alias: reports
    objects:
      - {alias: config, value: "{{ inputs.config }}"}        # write: always (the default) or once
```

The scheduler blob's schedule fires as the app's account, `as: "{{ accounts.runner.id }}"`, and targets the
installation's own workflow blob, `"{{ blobs.flows.id }}"`, so an install applies `flows` before `schedules`
([Scheduler](https://docs.blobhub.io/blob-types/app/blob-yaml.md#scheduler)). A secret is read only by a credential's `body`: a manifest that
reads `weather_key` is a problem, and a version with a problem is not committed. Left out, the optional `weather_key`
skips the `weather` credential ([Install-time names](https://docs.blobhub.io/blob-types/app/templates.md#install-time-names)).

## The migration

An app whose data changes shape between versions names a migration workflow, last in `app.yaml`:

```yaml theme={null}
# app.yaml, continued
migration: {blob: flows, session: reports, workflow: reports-migrate, as: runner}
```

The keys say where it runs: `reports-migrate`, in the session `reports` of `reports-flows`, as `reports-runner`. Field
Reports keeps a `data_version` object in that session and one step per change of shape, so an upgrade that skips a
version, or a migration run twice, ends in the same place. The new version's workflows may run before its migration
ends, so they read the old shape too, or take their own lock: they wait until the `data_version` the migration writes
is theirs. When it runs, what it is given and what its outcome does to the installation are on
[Apps](https://docs.blobhub.io/general/apps.md#the-migration).
[Migration](https://docs.blobhub.io/blob-types/app/app-yaml.md#migration) has the keys,
[The migration workflow](https://docs.blobhub.io/blob-types/installer/overview.md#the-migration-workflow) the contract, and
[Between any two versions](https://docs.blobhub.io/blob-types/installer/overview.md#between-any-two-versions) the workflow's code.

### When an upgrade may run

An app whose long work must not be cut by an upgrade names, under `upgrade` in `app.yaml`, a session object its own
workflows write, its busy object. They write `busy: true` with an `until` before that work starts, and `busy: false`
after it. While it says busy, an upgrade or an uninstall is refused
([When the app is busy](https://docs.blobhub.io/general/apps.md#when-the-app-is-busy)). Beside it, `from` names the oldest version a version
moves from. Field Reports needs neither, and leaves `upgrade` out. [Upgrade](https://docs.blobhub.io/blob-types/app/app-yaml.md#upgrade) has the
keys, and [The busy object](https://docs.blobhub.io/blob-types/app/app-yaml.md#the-busy-object) what an app writes.

## Build and push

Two commands take the repository to the app blob. `blobhub app build` compiles the sources into `build/`; it makes no
API call, so it runs in a pre-commit hook or the first step of CI. `blobhub app push` builds, makes the app blob's
draft equal `build/` by uploading only the files that changed, and asks the platform to read the result with
[`describe`](https://docs.blobhub.io/blob-types/app/operations/describe), printing each problem it finds.

```bash theme={null}
blobhub app build
blobhub app push
```

The first push creates the app blob `acme-corp/field-reports`, private. A problem does not stop the upload, so fixing
the sources and pushing again converges; it stops a commit. [`build`](https://docs.blobhub.io/cli/app/commands/build) and
[`push`](https://docs.blobhub.io/cli/app/commands/push) have their output and errors, and the [App commands](https://docs.blobhub.io/cli/app/overview.md) the whole
loop.

![The App tab of acme-corp/field-reports: the Files card with the file tree and app.yaml open, beside the Overview rail with the app's label, version 0.3.0, its blobs flows and schedules, and its inputs](https://mintcdn.com/blobhub/0bF8AORKcnBSgJ06/general/images/building-an-app/app-blob.png?fit=max\&auto=format\&n=0bF8AORKcnBSgJ06\&q=85\&s=111c94ed76be54c954a6c03cff6fd222)

The app blob: the files a push uploaded, and what the platform read from them.

## Try it in a development installation

Before a draft becomes a version, it is installed through the same path a customer's install takes. `--install`
installs the draft over a development installation in the app blob's own organization, here `reports-dev` in
`acme-corp/installed-apps`, the installer the CLI uses unless `--installer` names another:

```bash theme={null}
# the development installation's config from a file, the secret from the environment
blobhub app push --install reports-dev --input config=@dev-config.yaml --input weather_key=env:WEATHER_API_KEY
```

![blobhub app push --install reports-dev in a terminal: the build, the upload, the plan's lines, and the development installation reports-dev installed](https://mintcdn.com/blobhub/0bF8AORKcnBSgJ06/general/images/building-an-app/push-install.svg?fit=max\&auto=format\&n=0bF8AORKcnBSgJ06\&q=85\&s=b8d9867df9b9572ab4ed2584843f0572)

The recorded run of push --install: the build, the upload, the plan and the installation it made.

Its blobs, `reports-dev-flows` and `reports-dev-schedules`, stay editable, so the workflow editor and the playground
work on them as on any blob. `blobhub app pull` copies graph and layout edits back into `blobs/flows/definitions/`,
and the sources keep what was drawn:

```bash theme={null}
blobhub app pull reports-dev
```

![The Installations tab of acme-corp/installed-apps with reports-dev open: its record with Development set to Yes, which marks a development installation, and below it its JSON and its Log](https://mintcdn.com/blobhub/0bF8AORKcnBSgJ06/general/images/building-an-app/development-installation.png?fit=max\&auto=format\&n=0bF8AORKcnBSgJ06\&q=85\&s=5d3cd27ea75508f000bf848365120ab4)

The development installation: its record marked Development, with its JSON and its Log.

Manifests are written by hand and never pulled, and code lives in `src/`: an edit that is not pulled is replaced by the
next install, which applies the draft again. `push --install` confirms by itself over a new or development
installation unless the plan deletes a blob; with a deletion, it prints the plan and refuses until `--yes`. Over a
`ready` or `failed` installation of a committed version it is refused with `development_mismatch`, and `--yes` does not
change that: a development installation takes only the draft, and any other only committed versions. Over an
`uninstalled` one, `push --install --yes` makes the record again, as a development installation.
[Development installations](https://docs.blobhub.io/blob-types/installer/overview.md#development-installations) and
[`pull`](https://docs.blobhub.io/cli/app/commands/pull) have the rules.

## Commit a version

When the draft is right, `blobhub app commit` makes it the version `app.yaml` names, `0.2.0`, which is never reopened
([Versions](https://docs.blobhub.io/blob-types/app/overview.md#versions)):

```bash theme={null}
blobhub app commit -m "First version"
```

The commit is refused while `describe` reports a problem, or when the app blob already holds `0.2.0`.
[`commit`](https://docs.blobhub.io/cli/app/commands/commit) has its checks, and [`blobhub app ls`](https://docs.blobhub.io/cli/app/commands/ls) lists the versions.

## Release the next version

A fix or a feature is the next version. Bump `app.version` in `app.yaml` from `0.2.0` to `0.3.0`, push and try it over
`reports-dev`, which keeps its inputs and credentials ([Upgrading](https://docs.blobhub.io/general/apps.md#upgrading)), then commit:

```bash theme={null}
blobhub app push --install reports-dev
blobhub app commit -m "Report templates keyed by site"
```

The first push after a commit opens a new draft, and `0.2.0` stays as it was. Committing without the bump is refused
with `APP_VERSION_EXISTS`, and committing a bump that was never pushed with `APP_NO_DRAFT` or `APP_DRAFT_STALE`, whose
hint is `blobhub app push`. The version must be a semantic version ([`app.version`](https://docs.blobhub.io/blob-types/app/app-yaml#app)).
Installations move forward only, so a repair is the next version: a repair of `0.3.0` is `0.3.1`, not a `0.2.x`,
which an installation already at `0.3.0` refuses with `version_downgrade`. A version that changes the shape of the
data adds a step to the migration, as `0.3.0` reshapes the report templates. An installation moves to the new version
by [upgrading](https://docs.blobhub.io/general/apps.md#upgrading).

## Share it and install it

The app blob starts private ([who may install it](https://docs.blobhub.io/general/apps.md#private-apps)). To offer it to another organization,
either:

* **Share it.** An ADMIN of the app blob adds a person, or a service account, as a member with READ. Members are
  users: no organization is a member of anything.
* **Make it public.** A person with WRITE on the app blob changes its visibility.

[App access](https://docs.blobhub.io/blob-types/app/overview.md#access) has who may do what. The other organization then installs a committed
version, first without `--yes` and then with it; on Apps, [Installing](https://docs.blobhub.io/general/apps.md#installing) has what the first
command prints and who makes the first install, and [Upgrading](https://docs.blobhub.io/general/apps.md#upgrading) the migration's run.

```bash theme={null}
blobhub installer install acme-corp/field-reports --installer <org>/installed-apps --alias reports \
  --version 0.2.0 --input config=@config.yaml --input weather_key=env:WEATHER_API_KEY
blobhub installer install acme-corp/field-reports --installer <org>/installed-apps --alias reports \
  --version 0.2.0 --input config=@config.yaml --input weather_key=env:WEATHER_API_KEY --yes
```

[`plan`](https://docs.blobhub.io/blob-types/installer/operations/plan) and [`install`](https://docs.blobhub.io/blob-types/installer/operations/install) are the
operations behind the web and the terminal alike, and [`blobhub installer install`](https://docs.blobhub.io/cli/installer/commands/install)
has the command's output.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.