Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit 469e64b

Browse files
committed
docs(configuration): add configuration docs (nitric.yaml)
1 parent 3e57700 commit 469e64b

File tree

9 files changed

+266
-29
lines changed

9 files changed

+266
-29
lines changed

docs/basics/configuration.mdx

Lines changed: 236 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,236 @@
1+
---
2+
description: 'Configuring a Nitric Project using nitric.yaml'
3+
---
4+
5+
# Configuration
6+
7+
The Nitric CLI uses a configuration file named `nitric.yaml` to define the structure of your project. This file defines the name of your project, where nitric should look for the entrypoints to your application, and other project-specific settings.
8+
9+
Projects created from a template using the Nitric CLI will have a `nitric.yaml` file created for you. If you are creating a project from scratch, you can create a `nitric.yaml` file in the root of your project.
10+
11+
<Note>
12+
If you're new to Nitric and starting from a project template, you can skip
13+
this section and start building your application. The `nitric.yaml` file will
14+
be created for you. Use this section as a reference when you need to customize
15+
your project configuration or understand how the configuration works.
16+
</Note>
17+
18+
## Example `nitric.yaml`
19+
20+
```yaml
21+
name: my-project
22+
services:
23+
- match: services/*
24+
runtime: go
25+
type: ''
26+
start: go run ./$SERVICE_PATH/...
27+
runtimes:
28+
go:
29+
dockerfile: ./golang.dockerfile
30+
context: ''
31+
args: {}
32+
```
33+
34+
## Configuration Options
35+
36+
### `name`
37+
38+
The name of your project. This is used to identify your project and it used when auto-generating service and resource names during deployment.
39+
40+
### `services`
41+
42+
A list of [service](/concepts/service) types that make up your project. Typically, nitric will build each service in your project into a separate container image. Each service can have its own runtime, build configuration, and start command.
43+
44+
#### `match`
45+
46+
A glob pattern that matches service entrypoints. Each file matching this pattern will be treated as a separate service. This allows multiple services to share a single runtime configuration and `type`.
47+
48+
For example, with the following configuration:
49+
50+
```yaml
51+
services:
52+
- match: services/*
53+
runtime: go
54+
type: ''
55+
start: go run ./$SERVICE_PATH/...
56+
```
57+
58+
And the project structure below:
59+
60+
```text
61+
services/
62+
service1/
63+
main.go
64+
service2/
65+
main.go
66+
```
67+
68+
```text
69+
services/
70+
├── service1/
71+
│ └── main.go
72+
└── service2/
73+
└── main.go
74+
```
75+
76+
Both `service1/main.go` and `service2/main.go` will be treated as separate services with the same runtime configuration.
77+
78+
#### `basedir` (optional)
79+
80+
The base directory to search for service entrypoints. If not provided, the base directory is the root of the project. This is useful when you want to group services under a specific directory or you're working with a monorepo.
81+
82+
<Note>
83+
If you're using a custom [runtime configuration](#runtimes), the `basedir`
84+
value will be used as the context for the Docker build, i.e. it will override
85+
the `context` value in the runtime configuration.
86+
</Note>
87+
88+
#### `runtime` (optional)
89+
90+
The runtime to use for this service. For certain languages like JavaScript, Python and Dart the runtime can be inferred from the file extension. For other languages, you will need to specify the runtime.
91+
92+
If a runtime is provided it must match the name of a runtime configuration in the `runtimes` section.
93+
94+
#### `type` (optional)
95+
96+
Type is essentially the name for this group of services. It is used to group services together for deployment and resource management. If not provided, the service will be grouped under the 'default' type.
97+
98+
The most common use case for this is grouping service with similar deployed resource requirements together. For example, you make have a set of services that required additional vCPU or memory resources at runtime. You can group these services together under a specific type and apply resource constraints to that type in a [stack file](/concepts/stack).
99+
100+
For example, if you have a set of services that require additional memory, you can group them together under a type named `memory-intensive`, separate from the default type.
101+
102+
```yaml
103+
services:
104+
- match: services/other/*
105+
runtime: go
106+
start: go run ./$SERVICE_PATH/...
107+
- match: services/memory-intensive/*
108+
runtime: go
109+
# Group these services under the 'memory-intensive' type
110+
type: memory-intensive
111+
start: go run ./$SERVICE_PATH/...
112+
```
113+
114+
#### `start` (optional)
115+
116+
The command to start the service during local development. This command is used when running locally using the `nitric start` CLI command. This command will be executed once for each service, with the `$SERVICE_PATH` environment variable set to the path to the service entrypoint.
117+
118+
For example, with the following configuration:
119+
120+
```yaml
121+
services:
122+
- match: services/*
123+
runtime: go
124+
type: ''
125+
start: go run ./$SERVICE_PATH/...
126+
```
127+
128+
And the project structure below:
129+
130+
```text
131+
services/
132+
service1/
133+
main.go
134+
service2/
135+
main.go
136+
```
137+
138+
When running `nitric start`, the following commands will be executed:
139+
140+
```bash
141+
go run ./services/service1/main.go
142+
go run ./services/service2/main.go
143+
```
144+
145+
### `batch-services` (optional)
146+
147+
A list of [batch service](/concepts/batch-service) types that make up your project. Batch services are used to run high-performance computing tasks, data processing or tasks requiring GPUs, or a large number of vCPUs or memory.
148+
149+
Batch services are similar to services but are optimized for running batch processing tasks. You can read more about batch services in the [batch services](/concepts/service#batch) section.
150+
151+
The configuration options for `batch-services` are the same as for `services`.
152+
153+
### `runtimes` (optional)
154+
155+
A list of runtime configurations that can be used by services in your project. Each runtime configuration defines how to build a service for a specific runtime. For example, this can be used to define a custom Dockerfile for a specific runtime.
156+
157+
For example, with the following configuration:
158+
159+
```yaml
160+
runtimes:
161+
go:
162+
dockerfile: ./golang.dockerfile
163+
context: ''
164+
args: {}
165+
```
166+
167+
Nitric ships with a set of default runtime configurations for common languages. You can override these default configurations by providing your own runtime configuration. The runtime configuration must match the runtime name used in the `services` section.
168+
169+
#### `dockerfile`
170+
171+
The path to the Dockerfile _template_ used to build the services. This path is relative to the root of the project. The Dockerfile template will be provided with the following arguments:
172+
173+
- `HANDLER`: The service entrypoint path relative to the base directory.
174+
175+
Here is an example of a Dockerfile template for Go services:
176+
177+
```dockerfile
178+
FROM golang:alpine AS build
179+
180+
# Include the HANDLER argument, nitric will populate this with the service entrypoint path
181+
ARG HANDLER
182+
183+
WORKDIR /app/
184+
185+
COPY go.mod *.sum ./
186+
187+
RUN go mod download
188+
189+
# Note: Operations like COPY are relative to the `basedir` value in service configuration.
190+
# Or the root of the project if not provided.
191+
COPY . .
192+
193+
# Build the Go App from the provided HANDLER (this will be based on matches in your nitric.yaml fle)
194+
RUN go build -o /bin/main ./${HANDLER}/...
195+
196+
FROM alpine
197+
198+
COPY --from=build /bin/main /bin/main
199+
200+
RUN chmod +x-rw /bin/main
201+
RUN apk update && \
202+
apk add --no-cache tzdata ca-certificates && \
203+
update-ca-certificates
204+
205+
ENTRYPOINT ["/bin/main"]
206+
```
207+
208+
<Note>
209+
The Dockerfile only needs to start your application. The Nitric CLI will
210+
automatically wrap this Dockerfile with additional build steps to inject the
211+
Nitric runtime and build context for the target platform.
212+
</Note>
213+
214+
#### `context` (optional)
215+
216+
The build context to use when building the container image. This is the directory that will be provided to the Docker build command as the build context. If not provided, the build context will be the root of the project.
217+
218+
<Note>
219+
Any services using this runtime which have a `basedir` value set will use the
220+
`basedir` value as the build context instead of the `context` value.
221+
</Note>
222+
223+
#### `args` (optional)
224+
225+
A map of additional arguments to provide to the Docker build command. These arguments will be provided to the Docker build command as `--build-arg` arguments.
226+
227+
For example, with the following configuration:
228+
229+
```yaml
230+
runtimes:
231+
go:
232+
dockerfile: ./golang.dockerfile
233+
context: ''
234+
args:
235+
GO_VERSION: 1.16
236+
```
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

docs/configuration.mdx

Whitespace-only changes.

next-env.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/// <reference types="next" />
22
/// <reference types="next/image-types/global" />
3+
/// <reference types="next/navigation-types/compat/navigation" />
34

45
// NOTE: This file should not be edited
56
// see https://nextjs.org/docs/app/building-your-application/configuring/typescript for more information.

0 commit comments

Comments
 (0)