From c2cf5899086ec7d032558dd0a7425a5b4d1cd93e Mon Sep 17 00:00:00 2001 From: Mariano Ramirez Date: Mon, 8 Jan 2024 17:12:43 -0400 Subject: [PATCH] Improvements for development --- .dockerignore | 22 ++++++++++++++++++++++ Dockerfile | 20 ++++++++++++++++++++ README.rst | 14 ++++++++++++++ docker-compose.yml | 13 +++++++++++++ 4 files changed, 69 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..aad30826 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,22 @@ +# Ignore common Python files and directories +*.pyc +__pycache__/ +*.pyo +*.pyd + +# Ignore development and testing files +*.env +*.log +*.sqlite3 + +# Ignore virtual environment files +venv/ +.env + +# vscode & codespaces +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +*.code-workspace \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..3c351003 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +# Use the official Python image as the base image +FROM python:3.12-alpine + +# Install MySQL and PostgreSQL client libraries +RUN apk update && apk add --no-cache \ + mariadb-connector-c-dev \ + postgresql-dev python3-dev musl-dev + +# Install Tox +RUN pip install tox +RUN tox -e dev + +# Set the working directory +WORKDIR /app + +# Copy the project files to the working directory +COPY . /app + +# Set the entrypoint command +CMD ["tox"] diff --git a/README.rst b/README.rst index ae480ce3..bddbb441 100644 --- a/README.rst +++ b/README.rst @@ -122,6 +122,12 @@ Create development virtualenv (you need to have tox installed in your base syste tox -e dev source .tox/dev/bin/activate +To run the test project, with the folder of the project as the current directory, run:: + + export PYTHONPATH="${PYTHONPATH}:/app/src" + docker run -d postgres -p 5432:5432 + + Then run the full import:: test_project/manage.py migrate @@ -129,6 +135,14 @@ Then run the full import:: There are several environment variables which affect project settings (like DB_ENGINE and CI), you can find them all in test_project/settings.py. +For example to change the database engine, you can run:: + + export DB_ENGINE=postgresql + export DB_HOST=192.168.0.118 + export DB_NAME=app + export DB_USER=postgres + export DB_PORT=5432 + To run the test suite you need to have postgresql or mysql installed with passwordless login, or just use sqlite. Otherwise the tests which try to create/drop database will fail. Running the full test suite:: diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..9bec07aa --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,13 @@ +version: '3.9' +services: + db: + image: postgres + environment: + POSTGRES_PASSWORD: example + app: + build: . + volumes: + - .:/app + working_dir: /app + links: + - db