From 0d76868e6e92d73b28b9c4e4ebbb6ccdef466e2b Mon Sep 17 00:00:00 2001 From: Chris Wells Date: Sun, 14 Apr 2024 04:10:45 +0000 Subject: [PATCH] Switch to dev containers --- .devcontainer.json | 30 ++- .envrc | 3 - .vscode/launch.template.json | 9 +- README.md | 2 +- babybuddy/settings/base.py | 13 +- devenv.lock | 209 ------------------- devenv.nix | 54 ----- devenv.yaml | 10 - docs/contributing/development-environment.md | 45 +--- 9 files changed, 48 insertions(+), 327 deletions(-) delete mode 100644 .envrc delete mode 100644 devenv.lock delete mode 100644 devenv.nix delete mode 100644 devenv.yaml diff --git a/.devcontainer.json b/.devcontainer.json index 82b6eac9..a1d4fbd5 100644 --- a/.devcontainer.json +++ b/.devcontainer.json @@ -1,23 +1,39 @@ { + "name": "babybuddy", + "image": "mcr.microsoft.com/devcontainers/python:3", + "features": { + "ghcr.io/devcontainers/features/github-cli:1": {}, + "ghcr.io/devcontainers/features/node:1": { + "version": "18" + }, + "ghcr.io/devcontainers-contrib/features/gulp-cli:2": {}, + "ghcr.io/devcontainers-contrib/features/pipenv:2": {} + }, "customizations": { "vscode": { "extensions": [ - "bbenoist.Nix", - "ms-python.python", "batisteo.vscode-django", - "ms-python.black-formatter" + "donjayamanne.python-environment-manager", + "ms-python.black-formatter", + "ms-python.python", + "samuelcolvin.jinjahtml" ], "settings": { "[python]": { + "defaultInterpreterPath": "${workspaceFolder}/.venv/bin/python", "editor": { "defaultFormatter": "ms-python.black-formatter" }, "pipenvPath": "pipenv" - } + }, + "terminal.integrated.defaultProfile.linux": "zsh" } } }, - "image": "ghcr.io/cachix/devenv:latest", - "overrideCommand": false, - "updateContentCommand": "devenv ci" + "containerEnv": { + "DJANGO_SETTINGS_MODULE": "babybuddy.settings.development", + "PIPENV_VENV_IN_PROJECT": "1" + }, + "postCreateCommand": "pipenv install --dev && npm install --include=dev && gulp migrate", + "forwardPorts": [8000] } diff --git a/.envrc b/.envrc deleted file mode 100644 index 6de8a8ac..00000000 --- a/.envrc +++ /dev/null @@ -1,3 +0,0 @@ -source_url "https://raw.githubusercontent.com/cachix/devenv/d1f7b48e35e6dee421cfd0f51481d17f77586997/direnvrc" "sha256-YBzqskFZxmNb3kYVoKD9ZixoPXJh1C9ZvTLGFRkauZ0=" - -use devenv \ No newline at end of file diff --git a/.vscode/launch.template.json b/.vscode/launch.template.json index ddc23bdc..b87e1337 100644 --- a/.vscode/launch.template.json +++ b/.vscode/launch.template.json @@ -1,20 +1,19 @@ { - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { - "name": "Python: Django", - "type": "python", + "name": "Debug Baby Buddy", + "type": "debugpy", "request": "launch", "program": "${workspaceFolder}/manage.py", + "python": "${workspaceFolder}/.venv/bin/python", "env": { "DEBUG": "False" }, "args": [ "runserver" ], + "console": "integratedTerminal", "django": true, "justMyCode": true } diff --git a/README.md b/README.md index 96e006d0..160f24fc 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ for information about how to create/update translations. ### Available languages -:brazil: Brazilian Portuguese, :es: Catalan, :cn: Chinese (simplified), :czech_republic: Czech, :denmark: Danish, :netherlands: Dutch, :uk: English (U.K.), :us: English (U.S.) _(base)_, :finland: Finnish, :fr: French, :de: German, :israel: Hebrew, :hungary: Hungarian, :it: Italian, :norway: Norwegian Bokmål, :poland: Polish, :portugal: Portuguese, :ru: Russian, :mexico: :es: Spanish, :sweden: Swedish, :tr: Turkish, :ukraine: Ukrainian +:brazil: Brazilian Portuguese, :es: Catalan, :cn: Chinese (simplified), :czech*republic: Czech, :denmark: Danish, :netherlands: Dutch, :uk: English (U.K.), :us: English (U.S.) *(base)\_, :finland: Finnish, :fr: French, :de: German, :israel: Hebrew, :hungary: Hungarian, :it: Italian, :norway: Norwegian Bokmål, :poland: Polish, :portugal: Portuguese, :ru: Russian, :mexico: :es: Spanish, :sweden: Swedish, :tr: Turkish, :ukraine: Ukrainian ## 🌐 Baby Buddy on the Web diff --git a/babybuddy/settings/base.py b/babybuddy/settings/base.py index db49429d..9466b576 100644 --- a/babybuddy/settings/base.py +++ b/babybuddy/settings/base.py @@ -1,9 +1,20 @@ import os -from distutils.util import strtobool from django.utils.translation import gettext_lazy as _ from dotenv import load_dotenv, find_dotenv + +# Convert common string values to boolean. +def strtobool(val): + val = val.lower() + if val in ("y", "yes", "t", "true", "on", "1"): + return 1 + elif val in ("n", "no", "f", "false", "off", "0"): + return 0 + else: + raise ValueError("invalid truth value {!r}".format(val)) + + # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) diff --git a/devenv.lock b/devenv.lock deleted file mode 100644 index 4b848a91..00000000 --- a/devenv.lock +++ /dev/null @@ -1,209 +0,0 @@ -{ - "nodes": { - "devenv": { - "locked": { - "dir": "src/modules", - "lastModified": 1694422554, - "narHash": "sha256-s5NTPzT66yIMmau+ZGP7q9z4NjgceDETL4xZ6HJ/TBg=", - "owner": "cachix", - "repo": "devenv", - "rev": "63d20fe09aa09060ea9ec9bb6d582c025402ba15", - "type": "github" - }, - "original": { - "dir": "src/modules", - "owner": "cachix", - "repo": "devenv", - "type": "github" - } - }, - "flake-compat": { - "flake": false, - "locked": { - "lastModified": 1673956053, - "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=", - "owner": "edolstra", - "repo": "flake-compat", - "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9", - "type": "github" - }, - "original": { - "owner": "edolstra", - "repo": "flake-compat", - "type": "github" - } - }, - "flake-utils": { - "locked": { - "lastModified": 1653893745, - "narHash": "sha256-0jntwV3Z8//YwuOjzhV2sgJJPt+HY6KhU7VZUL0fKZQ=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "1ed9fb1935d260de5fe1c2f7ee0ebaae17ed2fa1", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "flake-utils_2": { - "inputs": { - "systems": "systems" - }, - "locked": { - "lastModified": 1685518550, - "narHash": "sha256-o2d0KcvaXzTrPRIo0kOLV0/QXHhDQ5DTi+OxcjO8xqY=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "a1720a10a6cfe8234c0e93907ffe81be440f4cef", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "gitignore": { - "inputs": { - "nixpkgs": [ - "pre-commit-hooks", - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1660459072, - "narHash": "sha256-8DFJjXG8zqoONA1vXtgeKXy68KdJL5UaXR8NtVMUbx8=", - "owner": "hercules-ci", - "repo": "gitignore.nix", - "rev": "a20de23b925fd8264fd7fad6454652e142fd7f73", - "type": "github" - }, - "original": { - "owner": "hercules-ci", - "repo": "gitignore.nix", - "type": "github" - } - }, - "mk-shell-bin": { - "locked": { - "lastModified": 1677004959, - "narHash": "sha256-/uEkr1UkJrh11vD02aqufCxtbF5YnhRTIKlx5kyvf+I=", - "owner": "rrbutani", - "repo": "nix-mk-shell-bin", - "rev": "ff5d8bd4d68a347be5042e2f16caee391cd75887", - "type": "github" - }, - "original": { - "owner": "rrbutani", - "repo": "nix-mk-shell-bin", - "type": "github" - } - }, - "nix2container": { - "inputs": { - "flake-utils": "flake-utils", - "nixpkgs": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1688922987, - "narHash": "sha256-RnQwrCD5anqWfyDAVbfFIeU+Ha6cwt5QcIwIkaGRzQw=", - "owner": "nlewo", - "repo": "nix2container", - "rev": "ab381a7d714ebf96a83882264245dbd34f0a7ec8", - "type": "github" - }, - "original": { - "owner": "nlewo", - "repo": "nix2container", - "type": "github" - } - }, - "nixpkgs": { - "locked": { - "lastModified": 1694760568, - "narHash": "sha256-3G07BiXrp2YQKxdcdms22MUx6spc6A++MSePtatCYuI=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "46688f8eb5cd6f1298d873d4d2b9cf245e09e88e", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixpkgs-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, - "nixpkgs-stable": { - "locked": { - "lastModified": 1685801374, - "narHash": "sha256-otaSUoFEMM+LjBI1XL/xGB5ao6IwnZOXc47qhIgJe8U=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "c37ca420157f4abc31e26f436c1145f8951ff373", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixos-23.05", - "repo": "nixpkgs", - "type": "github" - } - }, - "pre-commit-hooks": { - "inputs": { - "flake-compat": "flake-compat", - "flake-utils": "flake-utils_2", - "gitignore": "gitignore", - "nixpkgs": [ - "nixpkgs" - ], - "nixpkgs-stable": "nixpkgs-stable" - }, - "locked": { - "lastModified": 1694364351, - "narHash": "sha256-oadhSCqopYXxURwIA6/Anpe5IAG11q2LhvTJNP5zE6o=", - "owner": "cachix", - "repo": "pre-commit-hooks.nix", - "rev": "4f883a76282bc28eb952570afc3d8a1bf6f481d7", - "type": "github" - }, - "original": { - "owner": "cachix", - "repo": "pre-commit-hooks.nix", - "type": "github" - } - }, - "root": { - "inputs": { - "devenv": "devenv", - "mk-shell-bin": "mk-shell-bin", - "nix2container": "nix2container", - "nixpkgs": "nixpkgs", - "pre-commit-hooks": "pre-commit-hooks" - } - }, - "systems": { - "locked": { - "lastModified": 1681028828, - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", - "owner": "nix-systems", - "repo": "default", - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", - "type": "github" - }, - "original": { - "owner": "nix-systems", - "repo": "default", - "type": "github" - } - } - }, - "root": "root", - "version": 7 -} diff --git a/devenv.nix b/devenv.nix deleted file mode 100644 index 884a28b9..00000000 --- a/devenv.nix +++ /dev/null @@ -1,54 +0,0 @@ -{ pkgs, ... }: - -{ - # https://devenv.sh/basics/ - env.DJANGO_SETTINGS_MODULE = "babybuddy.settings.development"; - - # https://devenv.sh/packages/ - packages = [ - pkgs.pipenv - pkgs.nodejs_18 - pkgs.nodePackages.gulp - pkgs.sqlite - ]; - - # https://devenv.sh/scripts/ - - enterShell = '' - pipenv install --dev - npm i - gulp migrate - ''; - - processes = { - gulp.exec = "gulp"; - }; - - # https://devenv.sh/languages/ - languages.python.enable = true; - languages.javascript = { - enable = true; - npm.install.enable = true; - }; - - devcontainer = { - enable = true; - settings.customizations.vscode.settings."[python]".editor.defaultFormatter = "ms-python.black-formatter"; - settings.customizations.vscode.settings."[python]".pipenvPath = "pipenv"; - settings.customizations.vscode.extensions = [ - "bbenoist.Nix" - "ms-python.python" - "batisteo.vscode-django" - "ms-python.black-formatter" - ]; - }; - - # services.nginx.enable = true; - - pre-commit.hooks = { - # format Python code - black.enable = true; - }; - - # See full reference at https://devenv.sh/reference/options/ -} diff --git a/devenv.yaml b/devenv.yaml deleted file mode 100644 index 2638a19b..00000000 --- a/devenv.yaml +++ /dev/null @@ -1,10 +0,0 @@ -inputs: - nixpkgs: - url: github:NixOS/nixpkgs/nixpkgs-unstable - nix2container: - url: github:nlewo/nix2container - inputs: - nixpkgs: - follows: nixpkgs - mk-shell-bin: - url: github:rrbutani/nix-mk-shell-bin diff --git a/docs/contributing/development-environment.md b/docs/contributing/development-environment.md index 5efac81b..b0f43676 100644 --- a/docs/contributing/development-environment.md +++ b/docs/contributing/development-environment.md @@ -77,46 +77,17 @@ information and steps below to set up a local development environment for Baby B Open [http://127.0.0.1:8000](http://127.0.0.1:8000) and log in with the default username and password (`admin`/`admin`). -## Alternative: https://devenv.sh/ +## Alternative: [Dev Container](https://containers.dev/) -1. Install devenv (linux/mac/windows subsystem for linux/docker) via https://devenv.sh/getting-started/ -1. git clone the repo -1. here you have two options - 1. run `devenv shell` and then run `gulp` - 1. _OR_ run `devenv up` which automatically runs gulp/nodejs/python as well -1. Open [http://127.0.0.1:8000](http://127.0.0.1:8000) and log in with the default - username and password (`admin`/`admin`). +1. Add Dev Container support to your preferred IDE: https://containers.dev/supporting +2. Clone the Baby Buddy repo +3. Open the cloned repo in the dev container -Devenv also generates the **.devcontainer for vscode**, and sets up **github codespaces support**. To run babybuddy in the devcontainer or codespaces, open a terminal after opening this repo in the devcontainer, which causes the dependencies to be installed via `devenv shell`. Then, run `gulp` to start the baby buddy server. +Run `gulp` to start the Baby Buddy development server. -### Debugging in devenv + vscode +### Debugging in VSCode To debug in devenv + vscode/codespaces: -1. add a `.vscode/launch.json` file like this: - -```json -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "name": "Python: Django", - "type": "python", - "request": "launch", - "program": "${workspaceFolder}/manage.py", - "env": { - "DEBUG": "False" - }, - "args": ["runserver"], - "django": true, - "justMyCode": true - } - ] -} -``` - -2. Consider running `gulp fake --children 5 --days 7` as explained in the [gulp command reference](./gulp-command-reference.md) to add some fake data to the database -3. Click Run -> Start Debugging (F5) and set your breakpoints in the python as desired +1. Copy `.vscode/launch.template.json` as `.vscode/launch.json` file like this: +2. Click Run -> Start Debugging (F5) and set your breakpoints in the python as desired