You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
chore: make the development environment work from a clean checkout
Setting up to work on Indiekit needed steps that were either undocumented or
documented incorrectly, and the test suite depended on ambient state.
`npm test` now needs nothing at all. It already started its own in-memory
MongoDB for most tests, but `util/test/unit/mongodb.js` connected to
`mongodb://foo:bar@localhost` — port 27017 — and asserted the error was
`Authentication failed.`. That only holds when something happens to be
listening there. `docs/development.md` tells contributors to run MongoDB on
27018, so following the documented setup exactly produced a failure after a
30-second server-selection timeout. It now starts an in-memory server with
authentication enabled, which is deterministic, needs no service, and takes
180ms rather than 30s.
The test scripts also supply development defaults for SECRET and
PASSWORD_SECRET, overridden by real environment variables when set. Without
them the suite reports 115 failures that look like broken code rather than a
missing environment. CI passes both from repository secrets, which are not
available to pull requests from forks.
`compose.yml` replaces the block of YAML that development.md asked
contributors to copy by hand. That copy pinned mongo:7.0.11 — a release the
README warns against, being affected by CVE-2025-14847 — and required
`docker volume create` first, because it declared the volume external.
Also adds `.env.example`, and corrects `npm run dev --production`, which
passes the flag to npm rather than to the script.
Copy file name to clipboardExpand all lines: docs/development.md
+24-29Lines changed: 24 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,8 @@
1
1
# Setting up a local development environment
2
2
3
-
To begin local development on the Indiekit project, clone this repository, configure a [content store](concepts#content-store), [publication preset](concepts#publication-preset) and [syndicator](concepts#syndication), and create a MongoDB database you can connect to.
3
+
To begin local development on the Indiekit project, clone this repository, run `npm install`, then copy `.env.example` to `.env`. To run the server you will also want a [content store](concepts#content-store), [publication preset](concepts#publication-preset) and [syndicator](concepts#syndication), and a MongoDB database to connect to.
4
+
5
+
Running the tests needs none of that — see [Tests](#tests).
4
6
5
7
## Project structure
6
8
@@ -32,42 +34,26 @@ Express waits for a resolved configuration file before starting the server.
32
34
33
35
## MongoDB
34
36
35
-
Indiekit uses a MongoDB database for persistence. A convenient way to run MongoDB locally is to use [Docker Compose](https://docs.docker.com/compose/). Since the filesystem of a Docker container is ephemeral, you will need to create a [Docker volume](https://docs.docker.com/storage/volumes/). You can do this with the following docker command:
37
+
Indiekit uses a MongoDB database for persistence. The repository ships a
38
+
`compose.yml` that runs one, so you do not need to install MongoDB locally:
36
39
37
40
```sh
38
-
docker volume create mongo-data
41
+
npm run db:up
39
42
```
40
43
41
-
Create a `docker-compose.yml` file that runs a service on an available port of your Docker host (e.g. 27018) and uses the Docker volume you have just created.
42
-
43
-
```yml
44
-
version: '3.9'
45
-
services:
46
-
mongo:
47
-
container_name: mongo
48
-
environment:
49
-
- MONGO_INITDB_ROOT_USERNAME
50
-
- MONGO_INITDB_ROOT_PASSWORD
51
-
image: mongo:7.0.11
52
-
network_mode: bridge
53
-
ports:
54
-
- '27018:27017'
55
-
restart: always
56
-
volumes:
57
-
- mongo-data:/data/db
58
-
volumes:
59
-
mongo-data:
60
-
external: true
61
-
```
44
+
This starts MongoDB on port 27018 of your host, storing its data in a named
45
+
Docker volume so it survives a restart. Use `npm run db:down` to stop it, or
46
+
`npm run db:reset` to stop it and discard the data.
62
47
63
-
This configuration tells Docker to run the `mongo` service on port 27017 of the `mongo` container, and expose port 27018 on the Docker host (e.g. your computer).
48
+
The port defaults to 27018 rather than 27017 so that it does not collide with
49
+
a MongoDB already installed on your machine. Set `MONGO_PORT` to change it.
64
50
65
-
You can set the necessary environment variables in a `.env` file:
51
+
Copy `.env.example` to `.env` to get a matching `MONGO_URL`:
> To inspect data stored in a MongoDB database, use the [MongoDB shell](https://www.mongodb.com/products/tools/shell) or an application like [Compass](https://www.mongodb.com/products/tools/compass).
78
64
65
+
> [!NOTE]
66
+
> MongoDB is optional. Leave `MONGO_URL` unset to run Indiekit without persistence; see the [README](https://github.com/getindiekit/indiekit#readme) for which features need a database.
67
+
79
68
## Configure a content store
80
69
81
70
Indiekit performs create, read, update and delete (CRUD) operations on files that are stored in a content store. Different content stores require different configurations and credentials.
@@ -171,6 +160,12 @@ The project uses both unit and integration tests. Run tests using the following
171
160
npm test
172
161
```
173
162
163
+
The test suite needs no setup at all: it starts its own in-memory MongoDB, so
164
+
no database has to be running, and the `test` script supplies development
165
+
defaults for `NODE_ENV`, `SECRET` and `PASSWORD_SECRET`. A clean checkout can
166
+
run `npm install && npm test` straight away. Setting `SECRET` or
167
+
`PASSWORD_SECRET` in the environment overrides the default.
168
+
174
169
To run a single test suite, use `node` followed by the path to the test. For example:
0 commit comments