diff --git a/.env.example b/.env.example new file mode 100644 index 00000000..a0253933 --- /dev/null +++ b/.env.example @@ -0,0 +1,11 @@ +SECRET_KEY=secret-key + +DATABASE_URL=psql://postgres:postgres@db:5432/postgres +CACHE_DEFAULT=redis://redis:6379/0 +STATIC_URL=/static/ +STATIC_ROOT=/var/static/ + +POSTGRES_DB=postgres +POSTGRES_USER=postgres +POSTGRES_PASSWORD=postgres +POSTGRES_HOST=db \ No newline at end of file diff --git a/.flake8 b/.flake8 index 628307c6..950514d9 100644 --- a/.flake8 +++ b/.flake8 @@ -1,7 +1,17 @@ [flake8] max-complexity = 20 max-line-length = 120 -exclude = ~* +exclude = + .venv, + venv, + .git, + __pycache__, + build, + dist, + migrations, + snapshots, + __pypackages__, + ignore = E401,W391,E128,E261,E731,Q000,W504,W606,W503,E203 ;putty-ignore = ; tests/test_choice_as_instance.py : E501 diff --git a/.gitignore b/.gitignore index 124ce5e9..578bd6ae 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -.* ~* *.min.min.js *.py[ico] @@ -25,3 +24,4 @@ docker/conf/redis.conf src/aurora/staticfiles .pdm-python +.vscode \ No newline at end of file diff --git a/README.md b/README.md index 5c6a1ed0..a8972ca8 100644 --- a/README.md +++ b/README.md @@ -14,18 +14,18 @@ First configure your `.envrc` and run python manage.py runserver ```` -- Option 2: using docker-composer +- Option 2: using docker compose For the first time you need to run in root project directory ```shell ./manage env --comment --defaults > .env -docker-compose build -docker-compose up +docker compose build +docker compose up ``` each next time ```shell -docker-compose up +docker compose up ``` diff --git a/docker-compose.yml b/compose.yml similarity index 64% rename from docker-compose.yml rename to compose.yml index 671bca04..c80894cb 100644 --- a/docker-compose.yml +++ b/compose.yml @@ -1,5 +1,3 @@ -version: '3.7' - volumes: db: @@ -12,21 +10,26 @@ services: build: context: ./ dockerfile: ./docker/Dockerfile + target: dev + command: dev + # FIXME: if the below lines are uncommented, then __pypackages__ get lost + # volumes: + # - ./:/code/ ports: - "8000:8000" - volumes: - - ./:/code/ - command: "dev" depends_on: - db + - redis + db: - image: mdillon/postgis:11-alpine + image: postgres:16 volumes: - db:/var/lib/postgresql/data env_file: - .env + redis: - image: redis:4.0.11-alpine3.8 + image: redis:7 restart: unless-stopped expose: - "6379" diff --git a/docker/Dockerfile b/docker/Dockerfile index d2675e5c..5c9cdb76 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.11-slim-bullseye +FROM python:3.11-slim-bullseye as base ARG BUILD_DATE ARG VERSION @@ -64,3 +64,8 @@ ADD ./docker/bin/* /usr/local/bin/ ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] EXPOSE 8000 + +FROM base as dev +RUN pdm sync --dev + +FROM base as dist diff --git a/ops/compose.test.yml b/ops/compose.test.yml new file mode 100644 index 00000000..240c9a89 --- /dev/null +++ b/ops/compose.test.yml @@ -0,0 +1,23 @@ +services: + backend: + stdin_open: true + tty: true + env_file: + - test.env + image: ${backend_image} + ports: + - "8000:8000" + depends_on: + - db + - redis + + db: + image: postgres:16 + env_file: + - test.env + + redis: + image: redis:7 + restart: unless-stopped + expose: + - "6379" diff --git a/ops/test.env b/ops/test.env new file mode 100644 index 00000000..a0253933 --- /dev/null +++ b/ops/test.env @@ -0,0 +1,11 @@ +SECRET_KEY=secret-key + +DATABASE_URL=psql://postgres:postgres@db:5432/postgres +CACHE_DEFAULT=redis://redis:6379/0 +STATIC_URL=/static/ +STATIC_ROOT=/var/static/ + +POSTGRES_DB=postgres +POSTGRES_USER=postgres +POSTGRES_PASSWORD=postgres +POSTGRES_HOST=db \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 7cc2c681..eb39f5e9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -124,6 +124,7 @@ exclude = ''' | dist | migrations | snapshots + | __pypackages__ )/ '''