💅💅💅💅💅💅💅💅💅💅💅💅💅💅💅💅💅💅💅💅💅💅💅
💅💅💅💅💅💅💅💅💅💅💅💅💅💅💅💅💅💅💅💅💅💅💅
✨✨✨✨✨✨✨✨✨✨✨✨✨
✨✨✨✨✨✨✨✨✨✨✨✨✨
Django meetup #50
30.08.2023
😶
🙂
🙂💻🏢
🙂📱😠
✌️😏🥂😎👍🏖️
🤔💻
😩💻
😩📱😡
😣💻
😖💻
😭💻
😤 ⌨️ ✨
👮🥴👮🌄
😶
Je m’appelle Sylvain
# C’EST QUOI?
✨✨✨✨✨✨✨✨✨✨✨
Quelques qualités d’un bon environnement
Qualité
Pre-commit, CI/CD, reproduction de bugs en local.
Coût
Gain de temps lors de l’onboarding d’une nouvelle personne sur le projet ou après changement de machine.
Efficacité
L’équipe qui travaille sur le projet peut se concentrer sur ce qui est important, réduction de la frustration.
# POURQUOI ?
Pourquoi ?
Manuels d’installation
🧘
🔥🔥
🔥🔥
🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥
Ne faites pas ça à la maison
/ 10
Manuels d’installation
🔥 / 10
Vagrant
🧘
$ vagrant up
✨
✨
✨
✨
✨
✨
✨
C’est pire lent j’ai envie de mourir
La mise à jour Ruby a tout pété
Le plugin LXC est plus compatible
Personne sait comment rebuilder une box
Bonjour j’utilise Windows
Ça crashe à mort
Les miroirs pour cette version de Debian existent plus
🔥
🔥
🔥
🔥
🔥
🔥
🔥
🔥🔥🔥🔥🔥
🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥
11 / 20
Manuels d’installation
🔥 / 10
Vagrant
11 / 20
Docker
🧘
$ docker-compose up
✨
✨
✨
✨
✨
✨
✨
Permission denied: migrations/0001_initial.py
C’est pire lent j’ai envie de mourir
docker-compose rebuild à chaque changement de branche
Comment j’utilise PDB ?
Charger un dump de db ça devrait pas être si compliqué, non ?
Mon IDE trouve pas Black
Pourquoi c’est si compliqué ?
🔥
🔥
🔥
🔥
🔥
🔥
No space left on device
🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥
Docker m’a tuer
/ 10
Manuels d’installation
🔥 / 10
Vagrant
11 / 20
Docker
6 / 10
Nix
🧘
Puis installation directement sur l’hôte
Un faux paquet Nix, Python style
def my_package(
buildPythonPackage,
fetchFromGitHub,
django_4, dateutil,
django_tables2,
**kwargs
):
version = "1.0.0"
return buildPythonPackage(
pname="my_package",
version=version,
src=fetchFromGitHub(
owner="sephii",
repo="my_package",
rev=f"v{version}",
hash="sha256-s89gs3H//Dc3k6BLZUC4APyDgiWY9LetWAkI+kXQTf8=",
),
buildInputs=[django_4, dateutil, django_tables2],
)
# NIXNIXNIXNIXNIXN
Un vrai paquet Nix
{ buildPythonPackage
, fetchFromGitHub
, django_4
, dateutil
, django_tables2
, ...
}: buildPythonPackage rec {
pname = "my_package";
version = "1.0.0";
src = fetchFromGitHub {
owner = "sephii";
repo = "my_package";
rev = "v${version}";
hash = "sha256-s89gs3H//Dc3k6BLZUC4APyDgiWY9LetWAkI+kXQTf8=";
};
buildInputs = [ django_4 dateutil django_tables2 ];
}
# NIXNIXNIXNIXNIXN
Déclaration d’un environnement Nix (venv)
{ pkgs, ... }: pkgs.mkShell {
venvDir = "./.venv";
packages = [
pkgs.python311
pkgs.python311.pkgs.venvShellHook
pkgs.nodejs
];
postVenvCreation = ''
unset SOURCE_DATE_EPOCH
pip install -r requirements.txt
'';
postShellHook = ''
unset SOURCE_DATE_EPOCH
'';
}
🔥💖🔥💖🔥💖🔥💖🔥💖🔥
Déclaration d’un environnement Nix (nix style)
{ pkgs, ... }: pkgs.mkShell {
packages = [
(pkgs.python311.withPackages (ps: [ ps.django ]))
pkgs.nodejs
];
shellHook = ''${pkgs.fortune}/bin/fortune | ${pkgs.ponysay}/bin/ponysay'';
}
🔥💖🔥💖🔥💖🔥💖🔥💖🔥
$ nix run nixpkgs#strawberry
$ nix run github:sephii/taxi
$ nix-shell -p "python39.withPackages (ps: [ ps.django ps.requests ])"
pkgs.dockerTools.buildLayeredImage {
name = "myproject";
config.Cmd = [
"${pythonEnv.interpreter} -m gunicorn"
];
}
Intégration avec ✨ direnv ✨
Pas de gestion des services
🔥💖🔥💖🔥💖🔥💖🔥💖🔥
Poney / 10
Manuels d’installation
🔥 / 10
Vagrant
11 / 20
Docker
6 / 10
devenv
Nix
8 / 10
🧘
Et génération de procfile pour les services
Déclaration d’un environnement devenv avec poetry
{ pkgs, ... }: {
enterShell = ''
echo "Run just -l to see the list of available commands"
'';
languages.python.enable = true;
languages.python.package = pkgs.python311;
languages.python.poetry.enable = true;
languages.python.poetry.activate.enable = true;
processes = {
runserver.exec = "poetry run -- python -m django runserver";
};
services.postgres.enable = true;
services.mailhog.enable = true;
pre-commit.hooks.ruff.enable = true;
pre-commit.hooks.black.enable = true;
scripts.dj.exec = "python -m django $@";
packages = [ pkgs.nodejs-18_x ];
}
💖💖💖💖💖💖💖💖💖💖💖
$ devenv ci
$ devenv container
💖💖💖💖💖💖💖💖💖💖💖
Tip top / 10
Manuels d’installation
🔥 / 10
Vagrant
11 / 20
Docker
6 / 10
devenv
9.999 / 10
Nix
8 / 10
devenv++
🧘
💖💖💖💖💖💖💖💖💖💖💖
Ce qu’il manque à devenv pour être number one
Environnement de développement GeoDjango
Mon django-template
# RESSOURCES
Nix
https://nixos.org/
https://nix.dev/ (doc)
Direnv
https://github.com/direnv/direnv
Devenv
django-template
😶
🙂
@sephi@tooting.ch
sylvain@django-meetups.ch
🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂
😶😶😶😶😶😶😶😶😶😶😶😶😶😶😶😶😶😶😶😶😶😶😶
🏖️🏖️🏖️🏖️🏖️🏖️🏖️🏖️🏖️🏖️🏖️🏖️🏖️
🏖️🏖️🏖️🏖️🏖️🏖️🏖️🏖️🏖️🏖️🏖️🏖️🏖️