diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 000000000..590a23198 --- /dev/null +++ b/.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/* diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 000000000..57ca346a5 --- /dev/null +++ b/.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" + ] + } + } +} diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml new file mode 100644 index 000000000..da89f4775 --- /dev/null +++ b/.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 diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 5b1b36afb..965ea5694 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -18,6 +18,30 @@ 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`) +### 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 #### Debug