Browse Source

Setup VS Code Dev Container configuration

Add a .devcontainer configuration so contributors can develop Ghostfolio
inside a containerized environment with Node.js, PostgreSQL and Redis
pre-wired together, without needing to install anything locally besides
Docker and VS Code.

Closes #7380
pull/7383/head
Lewis Nixon 4 weeks ago
parent
commit
55bc3c1636
  1. 11
      .devcontainer/Dockerfile
  2. 31
      .devcontainer/devcontainer.json
  3. 13
      .devcontainer/docker-compose.yml
  4. 24
      DEVELOPMENT.md

11
.devcontainer/Dockerfile

@ -0,0 +1,11 @@
FROM node:22-slim
# Match the build tooling used by the production Dockerfile so native
# dependencies (e.g. Prisma) compile correctly inside the Dev Container
RUN apt-get update && apt-get install -y --no-install-recommends \
g++ \
git \
make \
openssl \
python3 \
&& rm -rf /var/lib/apt/lists/*

31
.devcontainer/devcontainer.json

@ -0,0 +1,31 @@
{
"name": "Ghostfolio",
"dockerComposeFile": [
"../docker/docker-compose.dev.yml",
"docker-compose.yml"
],
"service": "app",
"workspaceFolder": "/workspaces/ghostfolio",
"shutdownAction": "stopCompose",
"remoteUser": "node",
"forwardPorts": [3333, 4200],
"portsAttributes": {
"3333": {
"label": "API"
},
"4200": {
"label": "Client"
}
},
"postCreateCommand": "npm install",
"customizations": {
"vscode": {
"extensions": [
"angular.ng-template",
"esbenp.prettier-vscode",
"firsttris.vscode-jest-runner",
"nrwl.angular-console"
]
}
}
}

13
.devcontainer/docker-compose.yml

@ -0,0 +1,13 @@
services:
app:
build:
context: ..
dockerfile: .devcontainer/Dockerfile
volumes:
- ..:/workspaces/ghostfolio:cached
command: sleep infinity
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy

24
DEVELOPMENT.md

@ -18,6 +18,30 @@
1. Open https://localhost:4200/en in your browser 1. Open https://localhost:4200/en in your browser
1. Create a new user via _Get Started_ (this first user will get the role `ADMIN`) 1. Create a new user via _Get Started_ (this first user will get the role `ADMIN`)
### Dev Container
As an alternative to the manual _Setup_ above, [Visual Studio Code](https://code.visualstudio.com) users can develop inside a [Dev Container](https://containers.dev). It runs the application in a Docker container alongside [PostgreSQL](https://www.postgresql.org) and [Redis](https://redis.io), pre-installed with the required build tooling (Node.js 22, `g++`, `make`, `python3`).
#### Prerequisites
- [Docker](https://www.docker.com/products/docker-desktop)
- [Visual Studio Code](https://code.visualstudio.com) with the [Dev Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) extension
- Copy the file `.env.example` to `.env` and populate it with your data (`cp .env.example .env`)
**Info:** Use `.env.example`, not `.env.dev`, as the base for `.env`. Inside the Dev Container, the application and the databases run as separate containers on the same Docker network, so `DATABASE_URL` and `REDIS_HOST` must point to the service names `postgres` and `redis` (as `.env.example` already does), not `localhost`.
#### Setup
1. Open the repository folder in Visual Studio Code
1. Run the command _Dev Containers: Reopen in Container_ (this builds the container and runs `npm install` automatically)
1. In the container's integrated terminal, run `npm run database:setup` to initialize the database schema
1. Start the [server](#start-server)
1. Start the client with `npm run start:client -- --host 0.0.0.0` instead of the usual command (see note below)
1. Open https://localhost:4200/en in your browser
1. Create a new user via _Get Started_ (this first user will get the role `ADMIN`)
**Info:** The client dev server binds to `localhost` by default, which is only reachable from within the container itself. Passing `--host 0.0.0.0` makes it listen on all interfaces so Visual Studio Code's forwarded port reaches it from your browser on the host. This is not required for the server, which already binds to `0.0.0.0` by default.
### Start Server ### Start Server
#### Debug #### Debug

Loading…
Cancel
Save