# How an app is built

> What happens between a push and a running app: the install, the build commands, the packages the running app keeps, the three shapes of an image, and the cache.

A build turns one commit of your branch into an image: your files and packages, ready to start on a replica. You do not write a Dockerfile; the image is made from your `package.json` and the [build settings](https://arrangic.com/docs/build-settings.md).

## The steps

1. **Fetch.** The commit is fetched from GitHub. Only the [root directory](https://arrangic.com/docs/repositories.md#root-directory) becomes the app, or the whole workspace for an app in one. A repository larger than the [limits](#limits) is not built.
2. **Install.** `package.json` and the lockfile are copied first and the packages are installed, so a build whose packages did not change reuses that step. The package manager follows the lockfile. See [Package manager](https://arrangic.com/docs/build-settings.md#package-manager).
3. **Build.** Your files are copied and the [build commands](https://arrangic.com/docs/build-settings.md#build-commands) run, one after the other, until the first one fails.
4. **Trim.** After a build, the packages from `devDependencies` are removed again, and what the build left behind that the app never reads goes with them.
5. **Hand over.** The files are given to the user the app runs as, which has no root rights. The build log ends with that line.

The install and the build commands run as that same user, never as root. A build line that installs system packages fails.

The build runs on a machine of its own, apart from your running app and from every other team's builds. Nothing of it reaches the app except the image.

## Packages

- **With a build command,** the install brings in everything in `package.json`, also `devDependencies` (TypeScript, a bundler). After the build they are removed: the running app does not have them, so the start command must not need one. With Yarn 2 or newer nothing is removed.
- **Without a build command,** the packages in `devDependencies` are not installed at all.
- **`NODE_ENV` is `production`** from the install on. Your build and your running app both see it.
- **Native code.** A package that has to compile native code during the install can fail, because there is no compiler. Packages that ship ready binaries are fine.

> **Scripts that run on install**
>
> A `prepare` or `postinstall` script runs during the install. Without a build command, a tool from `devDependencies` is not there (husky is the usual one), and the install fails when the script calls it. Make the script skip the tool when it is missing.

## Variables during the build

The [environment variables](https://arrangic.com/docs/environment-variables.md) you set are there for the deploy commands and for the running app. The install and the build get every Config variable too, only while they run, and none of them is stored in the image; they never get a secret. The values of Config variables show as `[hidden]` in the build log. See [During the build](https://arrangic.com/docs/environment-variables.md#during-the-build).

## The three shapes of an image

What the running app carries depends on the framework and on the start command.

| Shape | Frameworks | What the running app carries |
| --- | --- | --- |
| Your server, with its packages | Express, Fastify, Hono, Koa, Hapi, Sails, NestJS, Next.js, React Router, Node.js, SvelteKit and Astro with their Node adapters, and any app with a start command of its own | The files of your repository and the packages from `dependencies` |
| The server the build writes | Nuxt and TanStack Start started from `.output`, AdonisJS started from `build` | That folder and your `package.json`, nothing else: no `node_modules`, no source, no build tools. AdonisJS gets its production packages installed inside `build` |
| Files served by the platform | React, Vue, Angular, SvelteKit with `adapter-static`, a static Astro site | The folder of built files, your `package.json` and the platform's own small server |
| A PHP app | Laravel | The files of your repository, `vendor` without the dev packages, the built assets in `public/build`, and `node_modules` only when the start command runs Inertia's rendering process. See [Laravel](https://arrangic.com/docs/frameworks/laravel.md) |

The second and third shapes make a small image that starts from a clean folder. They apply only with the start command the dashboard fills in for the framework. With any other start command, `npm run start` for a Nuxt app or `npx serve -s dist` for a React app, the app gets the first shape: whatever that command needs has to be in `dependencies`. The guide of each framework says which shape it gets and why.

[Deploy commands](https://arrangic.com/docs/deploy-commands.md) and [cron jobs](https://arrangic.com/docs/cron-jobs.md) run from the same image as the app. With the second or third shape, they find what that image carries and nothing more.

## What is kept between builds

- **The downloads of the package manager** are kept between builds of the same app, so a build fetches only what changed since the last one.
- **The image of a recent deployment** is kept. A restart, a redeploy after a change to variables or settings, and a rollback to a recent deployment reuse it without building again. A rollback to an older deployment builds the commit again first.
- **Every app is built again** when the platform changes how images are made. The deployment log then says so: "The live image was built before the platform changed how images are made, building again".

## What the build does not use

- **Your Dockerfile.** A `Dockerfile`, `.dockerignore` or `docker-compose.yml` in the repository is ignored.
- **System packages.** Only your npm packages are installed. There is no `apt`, no ffmpeg, no ImageMagick, none of the libraries a headless browser needs.
- **A `.env` file.** It should not be committed, and it is not read. Add its content under **Settings**, **Variables**.
- **A `.node-version` file.** The Node version is read from `.nvmrc`, then from `engines.node`. See [Node version](https://arrangic.com/docs/build-settings.md#node-version).

## Software the platform does not host

Before every build, the platform looks at the commands the app is set to run, the file names at the top of its repository and its `package.json` files. A deployment that names software of a kind the platform does not host is refused before anything is built:

- a crypto miner
- a proxy or anonymizer server
- a remote shell or remote desktop
- a tunnel
- a torrent client or tracker
- a scanner or attack tool
- a phishing kit

The version that was running stays online. The deployment page starts with "This deployment was refused:" and names what was found, where, and its kind. Then: "Software of this kind may not run on the platform. The acceptable use policy says what is not allowed:", with a link to the [acceptable use policy](https://arrangic.com/acceptable-use), and "If this is a mistake, contact support."

A `package.json` that cannot be read stops the build too: one larger than 1 MB, nested too deep, a link, or not plain JSON. The page says "... could not be read (...), so the build was not started. Software that may not run on the platform is looked for in it before every build. Fix it and deploy again."

## Limits

| | Limit |
| --- | --- |
| Build time | 30 minutes |
| Repository on GitHub, with its history | 2 GB |
| Archive of the commit that is built | 512 MB |
| Repository unpacked | 4 GB or 1,000,000 files |
| A `package.json` the build reads | 1 MB |
| Build log | The first 1 MB of output is kept, then "The build printed more than 1 MB; the rest was left out." The build goes on |
| Build output | A build that prints more than 50 MB in all is stopped and fails: "The build printed more than 50 MB of output and was stopped." |
| Build log kept for | 90 days after the deployment ended |

Builds cost nothing today. If the build fails, [Failed deployments](https://arrangic.com/docs/troubleshooting/deployments.md) lists the messages and what to do about each.

---

This page on the site: https://arrangic.com/docs/builds  
All pages of the documentation: https://arrangic.com/llms.txt
