Skip to content

Commit

Permalink
modified settings and environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
goutomroy committed Oct 17, 2023
1 parent 9f91244 commit 5dcaf17
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 32 deletions.
10 changes: 0 additions & 10 deletions .envs/.env.dev
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
# web
DJANGO_SETTINGS_MODULE=hex_images.settings.development
SECRET_KEY=django-insecure-@0*hp*@)v1qpq2j&!s3+2gw7!f=kh0h$9tf_e0w4prq&=q860h

# postgres
POSTGRES_DB=hex_images
POSTGRES_USER=hex_images
POSTGRES_PASSWORD=UiZz91YIW5GETnX2ifoCl8BtI8wuToLS
POSTGRES_HOST=postgres
POSTGRES_PORT=5432

# redis
ALLOW_EMPTY_PASSWORD=no
REDIS_PASSWORD=UiZz91YIW5GETdsfnX2ifoCl8BtI8wuToLS
16 changes: 16 additions & 0 deletions .envs/.env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# web
DJANGO_SETTINGS_MODULE=hex_images.settings.development
SECRET_KEY=django-insecure-@0*hp*@)v1qpq2j&!s3+2gw7!f=kh0h$9tf_e0w4prq&=q860h

# postgres
POSTGRES_DB=hex_images
POSTGRES_USER=hex_images
POSTGRES_PASSWORD=UiZz91YIW5GETnX2ifoCl8BtI8wuToLS
POSTGRES_HOST=postgres
POSTGRES_PORT=5432

# redis
ALLOW_EMPTY_PASSWORD=no
REDIS_PASSWORD=UiZz91YIW5GETdsfnX2ifoCl8BtI8wuToLS
REDIS_HOST=redis
REDIS_PORT=6379
2 changes: 0 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,3 @@ RUN pip install -r requirements/development.txt
COPY . .

LABEL maintainer="Goutom Roy" version="1.0.0"


22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
### Setup
### Setup
**Run following commands**
* docker-compose up -d
* docker container exec -it hex_images__web python manage.py create_test_users
Expand All @@ -11,15 +11,15 @@
* username: **hex_premium** password: **hex_premium_2023**
* username: **hex_enterprise** password: **hex_enterprise_2023**

### Available endpoints to use
**Please login to admin site before using these endpoints**
* http://localhost:8000/api/photos
* http://localhost:8000/api/photos/<pk>
* http://localhost:8000/api/expiring_link_view/<str:signed_link>/
* http://localhost:8000/api/expiring_links
* http://localhost:8000/api/expiring_links/<pk>
* http://localhost:8000/api/thumbnail_photos
* http://localhost:8000/media/<path>
### Available endpoints to use
**Please login to admin site before using these endpoints**
* http://localhost:8000/api/photos
* http://localhost:8000/api/photos/<pk>
* http://localhost:8000/api/expiring_link_view/<str:signed_link>/
* http://localhost:8000/api/expiring_links
* http://localhost:8000/api/expiring_links/<pk>
* http://localhost:8000/api/thumbnail_photos
* http://localhost:8000/media/<path>


### Testing command
Expand All @@ -29,4 +29,4 @@
**93%**

### Time to finish
It took about 28 hours to finish the project
It took about 28 hours to finish the project
29 changes: 29 additions & 0 deletions docker-compose-develope.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
services:

postgres:
image: postgres:15.3-alpine
container_name: hex_images__postgres
ports:
- '5432:5432'
volumes:
- /var/hex_images_service/postgres-data:/var/lib/postgresql/data
env_file:
- .envs/.env.dev

restart: always
networks:
- back-tier

redis:
image: redis:7.0.4-alpine
container_name: hex_images__redis
ports:
- '6379:6379'
volumes:
- /var/hex_images_service/redis-data:/data
networks:
- back-tier

networks:
back-tier:
driver: bridge
3 changes: 2 additions & 1 deletion hex_images/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
import os

from celery import Celery
from django.conf import settings

# set the default Django settings module for the 'celery' program.
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "hex_images.settings.development")


class Config:
broker_url = "redis://redis:6379/0"
broker_url = (settings.REDIS_CONNECTION_STRING,)
result_backend = "django-db"
beat_max_loop_interval = 600
result_cache_max = 1000
Expand Down
25 changes: 18 additions & 7 deletions hex_images/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@
# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ.get("SECRET_KEY")
SECRET_KEY = (
os.environ.get(
"SECRET_KEY",
"django-insecure-@0*hp*@)v1qpq2j&!s3+2gw7!f=kh0h$9tf_e0w4prq&=q860h",
),
)

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
Expand Down Expand Up @@ -87,21 +92,27 @@
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql",
"NAME": os.environ.get("POSTGRES_DB"),
"USER": os.environ.get("POSTGRES_USER"),
"PASSWORD": os.environ.get("POSTGRES_PASSWORD"),
"HOST": os.environ.get("POSTGRES_HOST"),
"PORT": os.environ.get("POSTGRES_PORT"),
"NAME": os.environ.get("POSTGRES_DB", "hex_images"),
"USER": os.environ.get("POSTGRES_USER", "hex_images"),
"PASSWORD": os.environ.get(
"POSTGRES_PASSWORD", "UiZz91YIW5GETnX2ifoCl8BtI8wuToLS"
),
"HOST": os.environ.get("POSTGRES_HOST", "localhost"),
"PORT": os.environ.get("POSTGRES_PORT", "5432"),
"ATOMIC_REQUESTS": True,
"CONN_MAX_AGE": 60 * 10,
}
}

# Cache
REDIS_CONNECTION_STRING = os.environ.get(
"REDIS_CONNECTION_STRING", "redis://localhost:6379"
)

CACHES = {
"default": {
"BACKEND": "django.core.cache.backends.redis.RedisCache",
"LOCATION": "redis://redis:6379/0",
"LOCATION": REDIS_CONNECTION_STRING,
}
}

Expand Down
4 changes: 3 additions & 1 deletion hex_images/settings/development.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from django.conf import settings

from .base import * # noqa

# project constant
Expand All @@ -9,7 +11,7 @@
CACHES = {
"default": {
"BACKEND": "django.core.cache.backends.redis.RedisCache",
"LOCATION": "redis://localhost:6379/0",
"LOCATION": settings.REDIS_CONNECTION_STRING,
}
}

Expand Down
1 change: 1 addition & 0 deletions hex_images/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@

if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urlpatterns += [path("api-auth/", include("rest_framework.urls"))]

0 comments on commit 5dcaf17

Please sign in to comment.