add docker

This commit is contained in:
TUTOR03 2020-11-29 06:39:02 +05:00
parent a297597dc4
commit c11ab4d04a
10 changed files with 117 additions and 26 deletions

15
backend/Dockerfile Normal file
View File

@ -0,0 +1,15 @@
# pull official base image
FROM python:3
# set work directory
WORKDIR /usr/src/app
# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# install dependencies
RUN pip install --upgrade pip
COPY ./requirements.txt .
RUN pip install -r requirements.txt
RUN apt update && apt install netcat -y
# copy project
COPY . .
ENTRYPOINT ["/usr/src/app/entrypoint.sh"]

View File

@ -11,6 +11,7 @@ https://docs.djangoproject.com/en/3.1/ref/settings/
"""
from pathlib import Path
import os
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
@ -20,13 +21,11 @@ BASE_DIR = Path(__file__).resolve().parent.parent
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'cn0m$w9+&hn7eus%m2z3m-=9!fz+!*#y_c7lb(4nax^51gfajz'
SECRET_KEY = os.environ.get("SECRET_KEY")
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
DEBUG = int(os.environ.get("DEBUG", default=0))
ALLOWED_HOSTS = os.environ.get("DJANGO_ALLOWED_HOSTS").split(" ")
# Application definition
@ -80,23 +79,12 @@ TEMPLATES = [
WSGI_APPLICATION = 'Ugra_hackaton.wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases
# DATABASES = {
# 'default': {
# 'ENGINE': 'django.db.backends.sqlite3',
# 'NAME': BASE_DIR / 'db.sqlite3',
# }
# }
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'ugra_hackaton',
'USER': 'postgres',
'PASSWORD': 'zo.h0906023',
'NAME': os.environ.get("POSTGRES_DB"),
'USER': os.environ.get("POSTGRES_USER"),
'PASSWORD': os.environ.get("POSTGRES_PASSWORD"),
'HOST': '127.0.0.1',
'PORT': '5432',
}
@ -145,12 +133,12 @@ STATIC_ROOT = BASE_DIR / 'static'
MEDIA_ROOT = BASE_DIR / 'media'
MEDIA_URL = '/media/'
MAX_CHECK_RADIUS = 1
MAX_CHECK_RADIUS = 0.001
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'artemss20030906@gmail.com'
EMAIL_HOST_PASSWORD = 'hbqgvdsqhvkuijuc'
EMAIL_HOST_USER = os.environ.get("EMAIL_HOST_USER")
EMAIL_HOST_PASSWORD = os.environ.get("EMAIL_HOST_PASSWORD")
EMAIL_PORT = 587
EMAIL_USE_TLS = True

View File

@ -0,0 +1,26 @@
# Generated by Django 3.1.3 on 2020-11-29 05:53
import back.models
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('back', '0011_game_points'),
]
operations = [
migrations.AddField(
model_name='checkpoint',
name='image',
field=models.ImageField(default='mt.img', upload_to=back.models.get_check_path),
preserve_default=False,
),
migrations.AddField(
model_name='game',
name='image',
field=models.ImageField(default='media/img.png', upload_to=back.models.get_game_path),
preserve_default=False,
),
]

View File

@ -8,6 +8,12 @@ CheckPointTypes = [
('GPS','GPS Coordinates')
]
def get_check_path(instance, filename):
return(f'{instance.game.title}/{instance.name}_{filename}')
def get_game_path(instance, filename):
return(f'{instance.title}/{instance.title}_{filename}')
class Profile(models.Model):
user = models.OneToOneField(User, on_delete = models.CASCADE)
points = models.DecimalField(max_digits=7, decimal_places=0, default = 0)
@ -25,6 +31,7 @@ class Game(models.Model):
active = models.BooleanField(default = True)
points = models.DecimalField(max_digits = 3, decimal_places = 0, blank = False, null = False)
slug = models.SlugField(unique = True, blank = True, null = False)
image = models.ImageField(upload_to = get_game_path, blank = False, null = False)
class CheckPoint(models.Model):
check_type = models.CharField(choices = CheckPointTypes, max_length = 20, blank = False, null = False)
@ -34,6 +41,7 @@ class CheckPoint(models.Model):
description = models.TextField(blank = False, null = False)
next_checkpoint = models.ForeignKey('self', on_delete = models.CASCADE, blank = True, null = True)
qr_data = models.TextField(blank = True, null = True)
image = models.ImageField(upload_to = get_check_path, blank = False, null = False)
last = models.BooleanField(default = False)
start = models.BooleanField(default = False)
address = models.CharField(max_length = 200, blank = True, null = True)

View File

@ -46,6 +46,7 @@ class CurrentCheckPointSerializer(serializers.ModelSerializer):
'name',
'description',
'address',
'image'
]
class TeamSerializer(serializers.ModelSerializer):

View File

@ -47,10 +47,27 @@ class ListGamesAPIView(generics.ListAPIView):
def get_queryset(self):
profile = Profile.objects.get(user = self.request.user)
if(self.kwargs['visited'] == '0'):
data = list(map(lambda team_i: team_i.game,filter(lambda ob:not Gamer.objects.filter(profile = profile, team = ob).exists(), Team.objects.all())))
else:
data = list(map(lambda team_i: team_i.game,filter(lambda ob:Gamer.objects.filter(profile = profile, team = ob).exists(), Team.objects.all())))
data = []
for game_i in Game.objects.filter(active = True):
teams = game_i.teams.all()
if(self.kwargs['visited'] == '0'):
test = True
for team_i in teams:
gamer_i = Gamer.objects.filter(team = team_i, profile = profile)
if(gamer_i.exists()):
test = False
break
if(test):
data.append(game_i)
else:
test = False
for team_i in teams:
gamer_i = Gamer.objects.filter(team = team_i, profile = profile)
if(gamer_i.exists()):
test = True
break
if(test):
data.append(game_i)
if(len(data)!=0):
return list_to_queryset(data)
else:

View File

@ -0,0 +1,21 @@
version: '3.7'
services:
web:
build: .
command: gunicorn URL_shortener.wsgi:application --bind 0.0.0.0:8005
volumes:
- .:/usr/src/app/
ports:
- 8005:8005
env_file:
- ./.env
depends_on:
- db
db:
image: postgres:alpine
volumes:
- postgres_data:/var/lib/postgresql/data/
env_file:
- ./.env
volumes:
postgres_data:

15
backend/entrypoint.sh Normal file
View File

@ -0,0 +1,15 @@
#!/bin/sh
echo "Waiting for postgres..."
while ! nc -z db 5432; do
sleep 0.1
done
echo "PostgreSQL started"
python manage.py makemigrations --noinput
python manage.py migrate --no-input
python manage.py collectstatic --no-input
exec "$@"

Binary file not shown.

After

Width:  |  Height:  |  Size: 90 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 96 KiB