diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 000000000..c7135fac8 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,15 @@ +ARG BASE_IMAGE=drive:backend-development +FROM ${BASE_IMAGE} + +USER root + +# Install tools needed by Zed (basedpyright LSP requires node) +RUN apk add --no-cache nodejs npm bash + +# Create a writable home and register the dev user with a valid shell +ARG DEV_UID=1000 +RUN mkdir -p /tmp/dev-home && chown ${DEV_UID}:0 /tmp/dev-home \ + && echo "default:x:${DEV_UID}:0:default user:/tmp/dev-home:/bin/sh" >> /etc/passwd + +USER default +ENV HOME=/tmp/dev-home diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 000000000..d7292d9c2 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,19 @@ +{ + "name": "Drive - La Suite Numerique", + "dockerComposeFile": [ + "../compose.yaml", + "docker-compose.override.yml" + ], + "service": "devcontainer", + "workspaceFolder": "/workspace", + "overrideCommand": true, + "shutdownAction": "none", + "containerUser": "default", + "updateRemoteUserUID": false, + "initializeCommand": { + "network": "docker network create lasuite-network || true", + "envfiles": "touch env.d/development/crowdin.local env.d/development/common.local env.d/development/postgresql.local env.d/development/kc_postgresql.local", + "dirs": "mkdir -p data/media data/static" + }, + "forwardPorts": [3000, 8071, 8080, 8083, 9000, 9001, 9980, 9981] +} diff --git a/.devcontainer/docker-compose.override.yml b/.devcontainer/docker-compose.override.yml new file mode 100644 index 000000000..d4c56a736 --- /dev/null +++ b/.devcontainer/docker-compose.override.yml @@ -0,0 +1,11 @@ +services: + devcontainer: + build: + context: . + dockerfile: .devcontainer/Dockerfile + args: + BASE_IMAGE: drive:backend-development + DEV_UID: ${DOCKER_USER:-1000} + user: "default" + volumes: + - ..:/workspace:cached diff --git a/.gitignore b/.gitignore index 2f9a22de8..4713d3591 100644 --- a/.gitignore +++ b/.gitignore @@ -79,7 +79,6 @@ db.sqlite3 .idea/ .vscode/ *.iml -.devcontainer # Various .turbo diff --git a/Makefile b/Makefile index 86f7f1454..756d67855 100644 --- a/Makefile +++ b/Makefile @@ -113,7 +113,7 @@ build-frontend: ## build the frontend container @$(COMPOSE) build frontend-dev $(cache) .PHONY: build-frontend-development -down: ## stop and remove containers, networks, images, and volumes +down: stop-devcontainer ## stop and remove containers, networks, images, and volumes @$(COMPOSE) down rm -rf data/postgresql.* .PHONY: down @@ -171,10 +171,18 @@ status: ## an alias for "docker compose ps" @$(COMPOSE) ps .PHONY: status -stop: ## stop the development server using Docker +stop: stop-devcontainer ## stop the development server using Docker @$(COMPOSE) stop .PHONY: stop +COMPOSE_DEVCONTAINER = docker compose -f compose.yaml -f .devcontainer/docker-compose.override.yml + +stop-devcontainer: ## stop the devcontainer service if running + @if $(COMPOSE_DEVCONTAINER) ps devcontainer --status running -q 2>/dev/null | grep -q .; then \ + $(COMPOSE_DEVCONTAINER) stop devcontainer; \ + fi +.PHONY: stop-devcontainer + # -- Backend demo: ## flush db then create a demo for load testing purpose diff --git a/README.md b/README.md index 91d03d21f..405d8b912 100644 --- a/README.md +++ b/README.md @@ -121,6 +121,18 @@ To start all the services, except the frontend container, you can use the follow $ make run-backend ``` +### Dev Container (Zed / VS Code) + +You can develop inside a container using the [Dev Containers](https://containers.dev/) specification. +This is supported by **Zed** and **VS Code** out of the box. + +1. Start the project with `make run` (or `make bootstrap` on first use). +2. Open the project in your IDE — it will detect `.devcontainer/devcontainer.json` and offer to reopen in a container. + +The dev container runs alongside `app-dev` as a dedicated IDE workspace with +Python dependencies and LSP support. It shares the same source files via volume +mounts, so your changes are immediately reflected in the running application. + ### Django admin You can access the Django admin site at