Skip to content

Commit

Permalink
fix: make compose working.
Browse files Browse the repository at this point in the history
  • Loading branch information
Amir Mehr committed Mar 21, 2024
1 parent afb7bc9 commit c492baa
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 14 deletions.
11 changes: 8 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
41 changes: 32 additions & 9 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
15 changes: 15 additions & 0 deletions wait_for_postgres.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit c492baa

Please sign in to comment.