mirror of
https://github.com/rjNemo/villafleurie
synced 2026-06-06 02:16:47 +00:00
Docker compose config. Nginx serving static & media files
This commit is contained in:
parent
66c989ea97
commit
6162d87fe0
10 changed files with 33 additions and 70 deletions
5
.gitignore
vendored
5
.gitignore
vendored
|
|
@ -1,11 +1,12 @@
|
||||||
|
.DS_Store
|
||||||
|
.vscode/
|
||||||
env/
|
env/
|
||||||
__pycache__/
|
__pycache__/
|
||||||
rental/__pycache__/
|
rental/__pycache__/
|
||||||
rental/migrations/
|
rental/migrations/
|
||||||
villafleurie/__pycache__/
|
villafleurie/__pycache__/
|
||||||
villafleurie/staticfiles/
|
villafleurie/staticfiles/
|
||||||
.DS_Store
|
villafleurie/static_files/
|
||||||
.vscode/
|
|
||||||
rental/client_secrets.json
|
rental/client_secrets.json
|
||||||
token.pickle
|
token.pickle
|
||||||
*.env
|
*.env
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ version: "3"
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
static_files:
|
static_files:
|
||||||
|
media:
|
||||||
|
|
||||||
services:
|
services:
|
||||||
db:
|
db:
|
||||||
|
|
@ -10,10 +11,10 @@ services:
|
||||||
web:
|
web:
|
||||||
build: .
|
build: .
|
||||||
command: bash -c "python manage.py migrate && python manage.py loaddata villafleurie.json && gunicorn -w 4 villafleurie.wsgi -b 0.0.0.0:8000"
|
command: bash -c "python manage.py migrate && python manage.py loaddata villafleurie.json && gunicorn -w 4 villafleurie.wsgi -b 0.0.0.0:8000"
|
||||||
# container_name: villafleurie
|
|
||||||
volumes:
|
volumes:
|
||||||
- .:/villafleurie
|
- .:/villafleurie
|
||||||
- static_files:/static_files
|
- static_files:/static_files
|
||||||
|
- media:/villafleurie/media
|
||||||
ports:
|
ports:
|
||||||
- "8000:8000"
|
- "8000:8000"
|
||||||
depends_on:
|
depends_on:
|
||||||
|
|
@ -21,7 +22,6 @@ services:
|
||||||
env_file: prod.env
|
env_file: prod.env
|
||||||
|
|
||||||
nginx:
|
nginx:
|
||||||
# image: nginx
|
|
||||||
build:
|
build:
|
||||||
context: .
|
context: .
|
||||||
dockerfile: nginx/Dockerfile
|
dockerfile: nginx/Dockerfile
|
||||||
|
|
@ -29,5 +29,6 @@ services:
|
||||||
- 80:80
|
- 80:80
|
||||||
volumes:
|
volumes:
|
||||||
- static_files:/static_files
|
- static_files:/static_files
|
||||||
|
- media:/media
|
||||||
depends_on:
|
depends_on:
|
||||||
- web
|
- web
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
"""Django's command-line utility for administrative tasks."""
|
""" Django's command-line utility for administrative tasks """
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,11 +3,16 @@ server {
|
||||||
server_name localhost;
|
server_name localhost;
|
||||||
access_log /var/log/nginx/example.log;
|
access_log /var/log/nginx/example.log;
|
||||||
|
|
||||||
location static/ {
|
location /static/ {
|
||||||
autoindex off;
|
autoindex off;
|
||||||
alias /static_files/;
|
alias /static_files/;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
location /media/ {
|
||||||
|
autoindex off;
|
||||||
|
alias /media/;
|
||||||
|
}
|
||||||
|
|
||||||
location / {
|
location / {
|
||||||
proxy_pass http://web:8000;
|
proxy_pass http://web:8000;
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
|
|
||||||
|
|
@ -12,9 +12,8 @@ from villafleurie.settings import BASE_DIR
|
||||||
|
|
||||||
|
|
||||||
def build_calendar_api_service():
|
def build_calendar_api_service():
|
||||||
"""
|
""" Build Google Calendar API service and returns calendar list and service """
|
||||||
Build Google Calendar API service and returns calendar list and service
|
|
||||||
"""
|
|
||||||
creds = None
|
creds = None
|
||||||
# If modifying these scopes, delete the file token.pickle.
|
# If modifying these scopes, delete the file token.pickle.
|
||||||
SCOPES = ['https://www.googleapis.com/auth/calendar']
|
SCOPES = ['https://www.googleapis.com/auth/calendar']
|
||||||
|
|
@ -72,13 +71,11 @@ def get_calendar_reservations(place):
|
||||||
|
|
||||||
|
|
||||||
def synchronize_calendars(place):
|
def synchronize_calendars(place):
|
||||||
"""
|
""" Get a complete list of existing bookings in calendar
|
||||||
Get a complete list of existing bookings in calendar
|
|
||||||
Creates reservation if not in db, update if already in db
|
Creates reservation if not in db, update if already in db
|
||||||
Delete from db reservation deleted from cal
|
Delete from db reservation deleted from cal """
|
||||||
"""
|
|
||||||
reservation = get_calendar_reservations(place)
|
|
||||||
|
|
||||||
|
reservation = get_calendar_reservations(place)
|
||||||
place = get_object_or_404(Place, name=place.name)
|
place = get_object_or_404(Place, name=place.name)
|
||||||
price = get_reservation_price(
|
price = get_reservation_price(
|
||||||
place,
|
place,
|
||||||
|
|
@ -115,10 +112,9 @@ def synchronize_calendars(place):
|
||||||
|
|
||||||
|
|
||||||
def get_bookings(place):
|
def get_bookings(place):
|
||||||
"""
|
""" Synchronize with Master calendar via a call to synchronize_calendar
|
||||||
Synchronize with Master calendar via a call to synchronize_calendar
|
Returns a list of all related place reservations """
|
||||||
Returns a list of all related place reservations
|
|
||||||
"""
|
|
||||||
synchronize_calendars(place)
|
synchronize_calendars(place)
|
||||||
booked_dates = Reservation.objects.filter(place=place)
|
booked_dates = Reservation.objects.filter(place=place)
|
||||||
# if booking.place.name == f"{place.name}"]
|
# if booking.place.name == f"{place.name}"]
|
||||||
|
|
@ -126,9 +122,8 @@ def get_bookings(place):
|
||||||
|
|
||||||
|
|
||||||
def check_availability(place, start_date, end_date):
|
def check_availability(place, start_date, end_date):
|
||||||
"""
|
""" check if the related place is available during a given period """
|
||||||
check if the related place is available during a given period
|
|
||||||
"""
|
|
||||||
bookings = get_bookings(place)
|
bookings = get_bookings(place)
|
||||||
for booking in bookings:
|
for booking in bookings:
|
||||||
if (booking.start <= start_date <= booking.end) or (booking.start <= end_date <= booking.end):
|
if (booking.start <= start_date <= booking.end) or (booking.start <= end_date <= booking.end):
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,7 @@ import os
|
||||||
|
|
||||||
# @app.task
|
# @app.task
|
||||||
def send_confirmation_mail(name, email, template="ticket"):
|
def send_confirmation_mail(name, email, template="ticket"):
|
||||||
"""
|
""" Send confirmation message to customer """
|
||||||
Send confirmation message to customer
|
|
||||||
"""
|
|
||||||
subject = "Nous avons reçu votre message"
|
subject = "Nous avons reçu votre message"
|
||||||
message = f" Merci {name}, Bien reçu nous revenons vers vous rapidement ! - HtmlMessage"
|
message = f" Merci {name}, Bien reçu nous revenons vers vous rapidement ! - HtmlMessage"
|
||||||
|
|
||||||
|
|
@ -28,9 +26,7 @@ def send_confirmation_mail(name, email, template="ticket"):
|
||||||
|
|
||||||
|
|
||||||
def send_notification(subject, name, message, template="activation"):
|
def send_notification(subject, name, message, template="activation"):
|
||||||
"""
|
""" Send notification to admins """
|
||||||
Send notification to admins
|
|
||||||
"""
|
|
||||||
html_path = os.path.join(BASE_DIR, 'rental/templates/rental/html/')
|
html_path = os.path.join(BASE_DIR, 'rental/templates/rental/html/')
|
||||||
with open(os.path.join(html_path, f"{template}.html"), 'r') as html:
|
with open(os.path.join(html_path, f"{template}.html"), 'r') as html:
|
||||||
html_message = html.read()
|
html_message = html.read()
|
||||||
|
|
@ -43,9 +39,7 @@ def send_notification(subject, name, message, template="activation"):
|
||||||
|
|
||||||
|
|
||||||
def send_quotation(reservation):
|
def send_quotation(reservation):
|
||||||
"""
|
""" Send quotation to customer """
|
||||||
Send quotation to customer
|
|
||||||
"""
|
|
||||||
name = reservation.guest.name
|
name = reservation.guest.name
|
||||||
email = list(reservation.guest.email)
|
email = list(reservation.guest.email)
|
||||||
send_confirmation_mail(name, email, template="welcome")
|
send_confirmation_mail(name, email, template="welcome")
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,7 @@ from datetime import datetime
|
||||||
|
|
||||||
|
|
||||||
def get_reservation_price(place, start, end):
|
def get_reservation_price(place, start, end):
|
||||||
"""
|
""" Compute booking price as a function of place and dates """
|
||||||
Compute booking price as a function of place and dates
|
|
||||||
"""
|
|
||||||
if type(start) == str:
|
if type(start) == str:
|
||||||
start = datetime.strptime(start, '%Y-%m-%d')
|
start = datetime.strptime(start, '%Y-%m-%d')
|
||||||
if type(end) == str:
|
if type(end) == str:
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
asgiref==3.2.3
|
asgiref==3.2.3
|
||||||
astroid==2.3.3
|
astroid==2.3.3
|
||||||
autopep8==1.4.4
|
|
||||||
beautifulsoup4==4.8.1
|
beautifulsoup4==4.8.1
|
||||||
cachetools==3.1.1
|
cachetools==3.1.1
|
||||||
certifi==2019.11.28
|
certifi==2019.11.28
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@ SECRET_KEY = os.environ.get('SECRET_KEY')
|
||||||
|
|
||||||
if os.environ.get('ENV') == 'PRODUCTION':
|
if os.environ.get('ENV') == 'PRODUCTION':
|
||||||
DEBUG = False
|
DEBUG = False
|
||||||
# STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
|
|
||||||
DATABASES = {
|
DATABASES = {
|
||||||
'default': {
|
'default': {
|
||||||
'ENGINE': 'django.db.backends.postgresql',
|
'ENGINE': 'django.db.backends.postgresql',
|
||||||
|
|
@ -22,19 +21,13 @@ if os.environ.get('ENV') == 'PRODUCTION':
|
||||||
'ATOMIC_REQUESTS': True
|
'ATOMIC_REQUESTS': True
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
# PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
|
|
||||||
# STATIC_ROOT = os.path.join(PROJECT_ROOT, 'staticfiles')
|
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
|
||||||
# STATIC_TMP = os.path.join(PROJECT_ROOT, 'static')
|
# STATIC_ROOT = os.path.join(PROJECT_ROOT, 'static')
|
||||||
# # Extra places for collectstatic to find static files.
|
|
||||||
# STATICFILES_DIRS = (os.path.join(PROJECT_ROOT, 'static'),)
|
|
||||||
# os.makedirs(STATIC_TMP, exist_ok=True)
|
|
||||||
# os.makedirs(STATIC_ROOT, exist_ok=True)
|
|
||||||
STATIC_ROOT = "/static/"
|
|
||||||
CSRF_COOKIE_SECURE = True
|
CSRF_COOKIE_SECURE = True
|
||||||
SESSION_COOKIE_SECURE = True
|
SESSION_COOKIE_SECURE = True
|
||||||
CONN_MAX_AGE = 500
|
CONN_MAX_AGE = 500
|
||||||
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
DEBUG = True
|
DEBUG = True
|
||||||
DATABASES = {
|
DATABASES = {
|
||||||
|
|
@ -52,8 +45,6 @@ else:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
STATICFILES_DIRS = [os.path.join(BASE_DIR, "rental", "static", "rental"), ]
|
STATICFILES_DIRS = [os.path.join(BASE_DIR, "rental", "static", "rental"), ]
|
||||||
# PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
|
|
||||||
# STATIC_ROOT = os.path.join(PROJECT_ROOT, 'staticfiles')
|
|
||||||
|
|
||||||
ALLOWED_HOSTS = [
|
ALLOWED_HOSTS = [
|
||||||
'0.0.0.0',
|
'0.0.0.0',
|
||||||
|
|
@ -61,15 +52,6 @@ ALLOWED_HOSTS = [
|
||||||
'localhost'
|
'localhost'
|
||||||
]
|
]
|
||||||
|
|
||||||
# PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
|
|
||||||
# STATIC_ROOT = os.path.join(PROJECT_ROOT, 'staticfiles')
|
|
||||||
# STATIC_TMP = os.path.join(PROJECT_ROOT, 'static')
|
|
||||||
# # Extra places for collectstatic to find static files.
|
|
||||||
# STATICFILES_DIRS = (os.path.join(PROJECT_ROOT, 'static'),)
|
|
||||||
# os.makedirs(STATIC_TMP, exist_ok=True)
|
|
||||||
# os.makedirs(STATIC_ROOT, exist_ok=True)
|
|
||||||
|
|
||||||
|
|
||||||
INSTALLED_APPS = [
|
INSTALLED_APPS = [
|
||||||
'django.contrib.admin',
|
'django.contrib.admin',
|
||||||
'django.contrib.auth',
|
'django.contrib.auth',
|
||||||
|
|
@ -84,7 +66,6 @@ SITE_ID = 1
|
||||||
|
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
'django.middleware.security.SecurityMiddleware',
|
'django.middleware.security.SecurityMiddleware',
|
||||||
# 'whitenoise.middleware.WhiteNoiseMiddleware',
|
|
||||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||||
'django.middleware.common.CommonMiddleware',
|
'django.middleware.common.CommonMiddleware',
|
||||||
'django.middleware.csrf.CsrfViewMiddleware',
|
'django.middleware.csrf.CsrfViewMiddleware',
|
||||||
|
|
@ -120,7 +101,6 @@ TEMPLATES = [
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
WSGI_APPLICATION = 'villafleurie.wsgi.application'
|
WSGI_APPLICATION = 'villafleurie.wsgi.application'
|
||||||
|
|
||||||
AUTH_PASSWORD_VALIDATORS = [
|
AUTH_PASSWORD_VALIDATORS = [
|
||||||
|
|
@ -137,10 +117,11 @@ USE_L10N = True
|
||||||
USE_TZ = True
|
USE_TZ = True
|
||||||
|
|
||||||
STATIC_URL = '/static/'
|
STATIC_URL = '/static/'
|
||||||
|
STATIC_ROOT = "/static_files/"
|
||||||
|
|
||||||
|
# MEDIA_ROOT = os.path.join(BASE_DIR, "media")
|
||||||
MEDIA_ROOT = os.path.join(BASE_DIR, "media")
|
|
||||||
MEDIA_URL = '/media/'
|
MEDIA_URL = '/media/'
|
||||||
|
MEDIA_ROOT = '/media/'
|
||||||
|
|
||||||
EMAIL_HOST = "smtp.gmail.com"
|
EMAIL_HOST = "smtp.gmail.com"
|
||||||
EMAIL_USE_TLS = True
|
EMAIL_USE_TLS = True
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,5 @@
|
||||||
"""
|
|
||||||
WSGI config for villafleurie project.
|
|
||||||
|
|
||||||
It exposes the WSGI callable as a module-level variable named ``application``.
|
|
||||||
|
|
||||||
For more information on this file, see
|
|
||||||
https://docs.djangoproject.com/en/2.2/howto/deployment/wsgi/
|
|
||||||
"""
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from django.core.wsgi import get_wsgi_application
|
from django.core.wsgi import get_wsgi_application
|
||||||
|
|
||||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'villafleurie.settings')
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'villafleurie.settings')
|
||||||
|
|
||||||
application = get_wsgi_application()
|
application = get_wsgi_application()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue