[deployment] select .env according to env var
This commit is contained in:
parent
3fdc60d9e5
commit
ecd80c291a
5 changed files with 17 additions and 15 deletions
|
|
@ -15,7 +15,7 @@ well with fish shell.
|
||||||
Have Python >= 3.12 installed. I use [pyenv] (which in turn is installed by [homebrew]).
|
Have Python >= 3.12 installed. I use [pyenv] (which in turn is installed by [homebrew]).
|
||||||
|
|
||||||
Set up Postgresql, a role and a schema. I have it on localhost, using the
|
Set up Postgresql, a role and a schema. I have it on localhost, using the
|
||||||
project name for role and schema name, and password. See `.env.sample` for
|
project name for role and schema name, and password. See `.env.test` for
|
||||||
providing connection information.
|
providing connection information.
|
||||||
|
|
||||||
Clone the repo. `cd` into the project directory. ([direnv] should activate the
|
Clone the repo. `cd` into the project directory. ([direnv] should activate the
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,6 @@ https://docs.djangoproject.com/en/5.1/ref/settings/
|
||||||
|
|
||||||
import environ
|
import environ
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import sys
|
|
||||||
|
|
||||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||||
|
|
||||||
|
|
@ -18,10 +17,7 @@ env = environ.Env(
|
||||||
DEBUG=(bool, False),
|
DEBUG=(bool, False),
|
||||||
DEPLOYMENT=(str, "Dev"),
|
DEPLOYMENT=(str, "Dev"),
|
||||||
)
|
)
|
||||||
if "pytest/__main__.py" in sys.argv[0]:
|
env.read_env(env.str("ENV_PATH", BASE_DIR / ".env")) # pyright: ignore[reportArgumentType]
|
||||||
env.read_env(BASE_DIR / ".env.test")
|
|
||||||
else:
|
|
||||||
env.read_env(BASE_DIR / ".env")
|
|
||||||
|
|
||||||
# See https://docs.djangoproject.com/en/5.1/howto/deployment/checklist/
|
# See https://docs.djangoproject.com/en/5.1/howto/deployment/checklist/
|
||||||
|
|
||||||
|
|
@ -44,12 +40,10 @@ INSTALLED_APPS = [
|
||||||
"collector.apps.CollectorConfig",
|
"collector.apps.CollectorConfig",
|
||||||
]
|
]
|
||||||
if env("DEPLOYMENT") == "Dev":
|
if env("DEPLOYMENT") == "Dev":
|
||||||
INSTALLED_APPS.extend(
|
INSTALLED_APPS += [
|
||||||
[
|
|
||||||
"django_extensions",
|
"django_extensions",
|
||||||
"debug_toolbar",
|
"debug_toolbar",
|
||||||
]
|
]
|
||||||
)
|
|
||||||
SHELL_PLUS = "ipython"
|
SHELL_PLUS = "ipython"
|
||||||
|
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
|
|
@ -62,7 +56,9 @@ MIDDLEWARE = [
|
||||||
"django.middleware.clickjacking.XFrameOptionsMiddleware",
|
"django.middleware.clickjacking.XFrameOptionsMiddleware",
|
||||||
]
|
]
|
||||||
if env("DEPLOYMENT") == "Dev":
|
if env("DEPLOYMENT") == "Dev":
|
||||||
MIDDLEWARE.append("debug_toolbar.middleware.DebugToolbarMiddleware")
|
MIDDLEWARE += [
|
||||||
|
"debug_toolbar.middleware.DebugToolbarMiddleware",
|
||||||
|
]
|
||||||
INTERNAL_IPS = [
|
INTERNAL_IPS = [
|
||||||
"127.0.0.1",
|
"127.0.0.1",
|
||||||
]
|
]
|
||||||
|
|
|
||||||
5
config/test.py
Normal file
5
config/test.py
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
def test_we_are_using_the_correct_envpath():
|
||||||
|
assert os.environ.get("ENV_PATH", "") == ".env.test"
|
||||||
2
justfile
2
justfile
|
|
@ -16,4 +16,4 @@ serve:
|
||||||
python -m django runserver
|
python -m django runserver
|
||||||
|
|
||||||
test *ARGS:
|
test *ARGS:
|
||||||
python -m pytest {{ARGS}}
|
ENV_PATH=.env.test python -m pytest {{ARGS}}
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,8 @@ authors = [
|
||||||
pythonpath = "."
|
pythonpath = "."
|
||||||
python_files = [
|
python_files = [
|
||||||
"test_*.py",
|
"test_*.py",
|
||||||
"tests.py"
|
"tests.py",
|
||||||
|
"config/test.py",
|
||||||
]
|
]
|
||||||
addopts = [
|
addopts = [
|
||||||
"--create-db",
|
"--create-db",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue