diff --git a/Dockerfile b/Dockerfile index 135c778..38f54de 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,11 +11,16 @@ WORKDIR /usr/src/app # Install dependencies COPY requirements.txt /usr/src/app/ RUN pip install --upgrade pip -RUN pip install --no-cache-dir -r requirements.txt +RUN pip install -r requirements.txt # Copy project COPY . /usr/src/app/ +# Make script executable +RUN chmod +x /usr/src/app/wait_for_postgres.sh -# Command to run the application -CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"] +# Collect static files +RUN python manage.py collectstatic --noinput + +# Run migrations +CMD /usr/src/app/wait_for_postgres.sh db python manage.py migrate diff --git a/README.md b/README.md index dc728a0..a17d835 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,32 @@ Additionally, a new service account needs to be created on Google Drive for syst Follow the instructions in [this tutorial](https://medium.com/@matheodaly.md/create-a-google-cloud-platform-service-account-in-3-steps-7e92d8298800) to guide you through service account creation and obtaining the credentials file. Remember to place this file under `/config/service_account.json`. -### Installing + +### Installing with Docker Compose + + +After cloning the repository and navigating into the directory, run the following command to build the Docker image: + +```bash +docker-compose build +``` + +Then, run the following command to start the Docker container: + +```bash +docker-compose up -d +``` + +Open the http://localhost:8000 and it should be up, running and ready to use. + +For adding seed data to the database, run the following command: + +```bash +docker-compose exec web python manage.py seeder +docker-compose exec web python manage.py check_api +``` + +### Installing for Contributors After cloning the repository and navigating into the directory, install the dependencies using pip: A step by step series of examples that tell you how to get a development environment running diff --git a/core/settings.py b/core/settings.py index 71d2d0d..8566d6b 100644 --- a/core/settings.py +++ b/core/settings.py @@ -145,7 +145,8 @@ GDRIVE_TEST_FOLDER_ID = os.environ.get("GMAIL_TEST_FOLDER_ID", "1NIGvjHBuUQHWnMqzboyg-zLI1q_bOuCH") # celery configs -CELERY_BROKER_URL = "redis://localhost:6379/0" +CELERY_REDIS_HOST = os.environ.get("CELERY_REDIS_HOST", "localhost") +CELERY_BROKER_URL = f"redis://{CELERY_REDIS_HOST}:6379/0" CELERY_RESULT_BACKEND = "django-db" CELERY_CACHE_BACKEND = "django-cache" diff --git a/docker-compose.yaml b/docker-compose.yaml index a593228..adbf393 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,15 +1,6 @@ version: '3.8' services: - web: - build: . - volumes: - - .:/usr/src/app - ports: - - "8000:8000" - environment: - - PYTHONUNBUFFERED=1 - - POSTGRES_HOST=db db: image: pgvector/pgvector:pg15 volumes: @@ -28,3 +19,35 @@ services: - REDIS_HOST=redis - REDIS_PORT=6379 - REDIS_DB=0 + web: + build: . + command: python manage.py runserver + volumes: + - .:/usr/src/app + ports: + - "8000:8000" + environment: + - PYTHONUNBUFFERED=1 + - POSTGRES_HOST=db + - CELERY_REDIS_HOST=redis + depends_on: + - db + - redis + celery_worker: + build: . + command: celery -A core worker -P gevent -c 1000 --loglevel=info + environment: + - PYTHONUNBUFFERED=1 + - POSTGRES_HOST=db + - CELERY_REDIS_HOST=redis + volumes: + - .:/usr/src/app + celery_beat: + build: . + command: celery -A core beat --loglevel=info + environment: + - PYTHONUNBUFFERED=1 + - POSTGRES_HOST=db + - CELERY_REDIS_HOST=redis + volumes: + - .:/usr/src/app diff --git a/wait_for_postgres.sh b/wait_for_postgres.sh new file mode 100644 index 0000000..92616ae --- /dev/null +++ b/wait_for_postgres.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +set -e + +host="$1" +shift +cmd="$@" + +until PGPASSWORD=$POSTGRES_PASSWORD psql -h "$host" -U "$POSTGRES_USER" -c '\q'; do + >&2 echo "Postgres is unavailable - sleeping" + sleep 1 +done + +>&2 echo "Postgres is up - executing command" +exec $cmd