Build and deploy
Deploy from Git
AvailableRunOne clones your repository on a server, builds its Dockerfile, and deploys the image. This page takes a Next.js app from repository to domain.
What you need: a server that is Ready, and a repository with a Dockerfile. The server needs Docker and git, which the install command adds when you run it with --install-docker. No image registry is needed: without one the image stays on the server that built it.
1. Let RunOne read the repository
A public repository needs nothing: use its https:// address. For a private one, go to Settings, create the workspace's Git key, and give the public half read access to the repository. Then use the repository's SSH address, such as [email protected]:acme/web.git.
On GitHub, a deploy key belongs to one repository. If the build also installs private Git dependencies from other repositories, add the key to the account of a machine user that can read all of them, instead of as a deploy key.
2. Describe the service
Add a Web Service with the port the app listens on (Next.js: 3000). On its Settings tab, set Deploy from to A Git repository, built on your server and fill in:
| Field | Example | Meaning |
|---|---|---|
| Repository | [email protected]:acme/web.git | Cloned fresh for every build. |
| Branch | main | The newest commit of this branch is built. |
| Dockerfile | Dockerfile | Path in the repository. |
| Build context | (empty) | Directory the build sees. Empty means the root. |
| Env file for the build | .env.production | See step 3. |
| Secrets the build may read | NPM_TOKEN | Names of secret variables, separated by spaces. |
| Lend the Git key to the Dockerfile | On | For RUN --mount=type=ssh, when the build installs private Git dependencies. |
3. Give it its variables
On Variables, choose Import .env, pick the service as the scope, and paste the .env file. RunOne shows what it read and guesses which values are secrets; tick or untick, then apply.
A build gets variables in three ways, and a framework usually needs only one of them:
| Way | Gets | Use it for |
|---|---|---|
| Build arguments | Every plain variable, as --build-arg. | A Dockerfile that declares ARG NAME. |
| Env file | Every plain variable, plus the secrets you named, written to the path you gave before the build. | Frameworks that read build-time settings from a file. Next.js bakes NEXT_PUBLIC_* values in from .env.production during npm run build. |
| BuildKit secrets | The secrets you named. | RUN --mount=type=secret,id=NPM_TOKEN …: the value never lands in an image layer. |
When the service runs, its container gets all of its variables, secrets included, as environment variables.
The env file is written into the checkout, so a Dockerfile that does COPY . . copies it into the image. Keep secrets out of it unless the build really needs them: name no secrets, or use BuildKit secrets instead.
4. Deploy
Choose Deploy on the service. RunOne starts a pipeline run, builds, and deploys the result when the build succeeds. Follow it on Pipelines, where each run has its log; the service page turns Running when the new version passed its health check.
The first build of a large app takes a few minutes. Later builds reuse Docker's layer cache on that server.
5. Put it on a domain
On Domains, add the address for the service and create the two DNS records the page shows. The certificate is obtained by the server itself. See Domains.
6. Deploy on every push
Create the service's hook address and add it to the repository as a push webhook. See Deployments.
Where builds run
- With no registry: on the server the service runs on. The image is named
runone/<service>-<id>:<commit>and stays there. - With a registry (Settings, Add Registry) and a server in a build pool: on the build server, which pushes the image; the runtime server pulls it. This keeps builds off the machines that serve production.
- A server started with
--no-buildsnever builds.
A Next.js build needs memory. On a server with 2 GB or less, add swap or build on a separate build server.