Skip to content

feat: Dockerize application for development #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 25 additions & 13 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
.dockerignore
Dockerfile
README.md
# Virtual Environments
venv/
env/
.venv/
.env/

# Python cache
__pycache__/
*.pyc
*.pyo
*.pyd
__pycache__

env/
.venv/
.env
.env.example
.venv/
# Tooling cache & reports
.ruff_cache/
.coverage
.coverage.*

# Version Control
.git/
.gitignore

# IDE and editor directories
.vscode/
.idea/

# Requirements files not needed in production
requirements/dev.txt

.git
.gitignore
# Log files
*.log
*.log.*
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ ENV PYTHONBUFFERED=1 \

WORKDIR /usr/src/app

COPY . .
COPY requirements/prod.txt ./requirements.txt

RUN pip install --upgrade pip && \
pip install -r requirements/prod.txt
pip install --no-cache-dir -r requirements.txt

COPY . .

CMD ["sh", "-c", "cd /usr/src/app/promo_code && python manage.py migrate --noinput && gunicorn promo_code.wsgi:application --bind ${SERVER_ADDRESS}"]

Expand Down
58 changes: 58 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
services:
web:
build: .
container_name: promo_code
ports:
- 8000:8080
volumes:
- .:/usr/src/app
depends_on:
db:
condition: service_healthy
restart: true
redis:
condition: service_started
antifraud:
condition: service_started

env_file:
- .env
db:
image: postgres:17
container_name: postgres_db
volumes:
- postgres_db:/var/lib/postgresql/data/
environment:
POSTGRES_DB: ${POSTGRES_DATABASE}
POSTGRES_USER: ${POSTGRES_USERNAME}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USERNAME} -d ${POSTGRES_DATABASE}"]
interval: 10s
timeout: 10s
retries: 5
start_period: 30s
env_file:
- .env

redis:
image: redis:7-alpine
ports:
- "6379:6379"
volumes:
- redis_data:/data


antifraud:
image: lodthe/prod-backend-antifraud:latest
environment:
SERVER_PORT: ${ANTIFRAUD_INTERNAL_PORT}
CACHE_DURATION_MS: ${ANTIFRAUD_CACHE_MS}
SLOWDOWN_AFTER: ${ANTIFRAUD_SLOWDOWN_AFTER}
BLOCKED_EMAILS: ${ANTIFRAUD_BLOCKED_EMAILS}
ports:
- "${ANTIFRAUD_EXTERNAL_PORT}:${ANTIFRAUD_INTERNAL_PORT}"

volumes:
postgres_db:
redis_data:
15 changes: 15 additions & 0 deletions promo_code/promo_code/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,21 @@ def load_bool(name, default):
},
}

CACHES = {
'default': {
'BACKEND': 'django_redis.cache.RedisCache',
'LOCATION': os.getenv('REDIS_URL', 'redis://127.0.0.1:6379/0'),
'OPTIONS': {
'CLIENT_CLASS': 'django_redis.client.DefaultClient',
},
},
}

ANTIFRAUD_ADDRESS = f'{os.getenv("ANTIFRAUD_ADDRESS")}'
ANTIFRAUD_VALIDATE_URL = f'{ANTIFRAUD_ADDRESS}/api/validate'
ANTIFRAUD_UPDATE_USER_VERDICT_URL = (
f'{ANTIFRAUD_ADDRESS}/internal/update_user_verdict'
)

AUTH_PASSWORD_VALIDATORS = [
{
Expand Down
3 changes: 3 additions & 0 deletions requirements/prod.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
django==5.2
django-redis==6.0.0
djangorestframework==3.15.2
djangorestframework-simplejwt==5.4.0
gunicorn==23.0.0
psycopg2-binary==2.9.10
pycountry==24.6.1
python-dotenv==1.0.1
requests==2.32.4
parameterized==0.9.0