Skip to content

Commit

Permalink
Adding redis settings
Browse files Browse the repository at this point in the history
  • Loading branch information
= committed Nov 14, 2024
1 parent fa2bc51 commit f7d20ed
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .env-prod
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ DB_HOST=10.2.2.10
DB_NAME=crank
DB_USER=crank
DB_PORT=3306
PYTHON_UNBUFFERED=1
PYTHON_UNBUFFERED=1
REDIS_URL=redis://redis:6379/0
6 changes: 6 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ jobs:
with:
python-version: 3.13

- name: Start Redis
uses: supercharge/redis-github-action@1.7.0
with:
redis-version: 7.0.5

- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand All @@ -61,6 +66,7 @@ jobs:
ENV: dev
SECRET_KEY: ${{ secrets.SECRET_KEY }}
DJANGO_SETTINGS_MODULE: 'crank.settings'
REDIS_URL: 'redis://localhost:6379/0'
PYTHON_UNBUFFERED: 1
run: |
coverage run -m pytest
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,16 @@ jobs:
pip install -r requirements.txt
pip install -r requirements-dev.txt
- name: Start Redis
uses: supercharge/redis-github-action@1.7.0
with:
redis-version: 7.0.5

- name: Run tests
env:
ENV: dev
SECRET_KEY: '${{ secrets.SECRET_KEY }}'
REDIS_URL: 'redis://localhost:6379/0'
run: |
pytest
Expand Down
8 changes: 5 additions & 3 deletions crank/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@
)

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
Expand Down Expand Up @@ -150,7 +150,9 @@

EXTENSIONS_MAX_UNIQUE_QUERY_ATTEMPTS = 1000

SESSION_ENGINE = "django.contrib.sessions.backends.cached_db"
SESSION_ENGINE = "django.contrib.sessions.backends.cache"
SESSION_CACHE_ALIAS = 'default'
SESSION_SAVE_EVERY_REQUEST = False
SESSION_COOKIE_DOMAIN = ".crank.fyi"
SESSION_COOKIE_SECURE = False

Expand Down
17 changes: 17 additions & 0 deletions crank/settings/dev.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Copyright (c) 2024 Isaac Adams
# Licensed under the MIT License. See LICENSE file in the project root for full license information.
from pathlib import Path
from django.core.cache.backends.redis import RedisCache
import os


BASE_DIR = Path(__file__).resolve().parent.parent.parent
DEBUG = True
SECRET_KEY = os.environ["SECRET_KEY"]
Expand All @@ -15,6 +17,21 @@
},
}
}

REDIS_URL = os.environ["REDIS_URL"]
CACHES = {
'default': {
'BACKEND': 'django_redis.cache.RedisCache',
'LOCATION': REDIS_URL,
'OPTIONS': {
'CLIENT_CLASS': 'django_redis.client.DefaultClient',
}
}
}

# Optional: To use Redis for session storage
SESSION_CACHE_ALIAS = 'default'

CORS_ORIGIN_ALLOW_ALL = True
ALLOWED_HOSTS = ['*']
LOGGING = {
Expand Down
19 changes: 19 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright (c) 2024 Isaac Adams
# Licensed under the MIT License. See LICENSE file in the project root for full license information.
---
services:
redis:
deploy:
resources:
limits:
cpus: "0"
memory: "0"
image: "redis:7.0.5-alpine"
restart: "unless-stopped"
stop_grace_period: "3s"
volumes:
- "redis:/data"
profiles: [ "redis" ]

volumes:
redis: { }
2 changes: 2 additions & 0 deletions k8s/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ spec:
value: "3306"
- name: ENV
value: "prod"
- name: REDIS_URL
value: "redis://redis:6379/0"
- name: PYTHONUNBUFFERED
value: "1"
envFrom:
Expand Down
2 changes: 1 addition & 1 deletion k8s/redis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ spec:
spec:
containers:
- name: redis
image: redis:6.2
image: redis:7.0.5-alpine
ports:
- containerPort: 6379
resources:
Expand Down
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ django-filter==24.2
django-manifest-loader==1.0.0
django-nose==1.4.7
django-oauth-toolkit==2.4.0
django-redis==5.4.0
django-seed==0.3.1
django-session-csrf==0.7.1
django-sslserver==0.22
Expand Down Expand Up @@ -74,6 +75,7 @@ python3-openid==3.2.0
pytz==2024.1
PyYAML==6.0.1
pyzmq==26.2.0
redis==5.2.0
requests==2.32.2
requests-oauthlib==1.3.1
setuptools==70.0.0
Expand All @@ -88,9 +90,9 @@ tzdata==2024.2
urllib3==2.2.2
virtualenv==20.25.1
waybackpy==3.0.6
Werkzeug==3.1.3
whitenoise==6.6.0
wrapt==1.15.0
zipp==3.19.1
zope.event==5.0
zope.interface==7.1.1
werkzeug>=3.0.6 # not directly required, pinned by Snyk to avoid a vulnerability

0 comments on commit f7d20ed

Please sign in to comment.