diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 000000000..141cb39ae --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,8 @@ +FROM mcr.microsoft.com/vscode/devcontainers/rust:0-1 + +RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ + && apt-get -y install --no-install-recommends postgresql-client + +# TODO: pre-build custom images, those take too much time +#RUN cargo install sqlx-cli --no-default-features --features postgres +#RUN cargo install cargo-edit \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 000000000..b063e5bd5 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,40 @@ +{ + "name": "Rust", + "dockerComposeFile": "docker-compose.yml", + "service": "app", + "workspaceFolder": "/workspace", + + "postCreateCommand": "SQLX_OFFLINE=1 cargo run -- database migrate", + "settings": { + "lldb.executable": "/usr/bin/lldb", + "sqltools.connections": [{ + "name": "Container database", + "driver": "PostgreSQL", + "previewLimit": 50, + "server": "localhost", + "port": 5432, + "database": "postgres", + "username": "postgres", + "password": "postgres" + }], + "files.watcherExclude": { + "**/target/**": true + } + }, + + "forwardPorts": [8080], + "portsAttributes": { + "8080": { + "label": "Application" + } + }, + + "extensions": [ + "bungcip.better-toml", + "vadimcn.vscode-lldb", + "mutantdino.resourcemonitor", + "matklad.rust-analyzer", + "mtxr.sqltools", + "mtxr.sqltools-driver-pg" + ] +} diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml new file mode 100644 index 000000000..30c6f9e7f --- /dev/null +++ b/.devcontainer/docker-compose.yml @@ -0,0 +1,34 @@ +version: '3' + +services: + app: + build: + context: . + dockerfile: Dockerfile + volumes: + - ..:/workspace:cached + + environment: + # FIXME: sqlx-cli and the app use different URIs + DATABASE_URL: postgresql://postgres:postgres@localhost/postgres + MAS_DATABASE_URI: postgresql://postgres:postgres@localhost/postgres + MAS_COOKIES_SECRET: a093e76c2ddc87d9de7afc1f9059d60a12176b2cdf8966029c00bc2146518a61 + + # Overrides default command so things don't shut down after the process ends. + command: sleep infinity + + # Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function. + network_mode: service:db + + db: + image: postgres:latest + restart: unless-stopped + volumes: + - postgres-data:/var/lib/postgresql/data + environment: + POSTGRES_PASSWORD: postgres + POSTGRES_USER: postgres + POSTGRES_DB: postgres + +volumes: + postgres-data: \ No newline at end of file