made everything to a docker file

pull/6/head
Jukoga 2024-08-01 13:33:38 +02:00
parent 812099ee7f
commit 2c286dacf4
6 changed files with 56 additions and 2 deletions

5
.gitignore vendored
View File

@ -2,10 +2,13 @@
*/__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
#added
staticfiles/
*/migrations/
# Distribution / packaging
.Python
build/

View File

@ -17,6 +17,8 @@ from dotenv import load_dotenv
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEMPLATES_DIR = os.path.join(BASE_DIR + '/templates')
DEFAULT_AUTO_FIELD='django.db.models.AutoField'
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
@ -128,6 +130,7 @@ USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/static/'
MEDIA_ROOT = os.path.join(BASE_DIR + '/media')
MEDIA_URL = '/media/'

34
Dockerfile Normal file
View File

@ -0,0 +1,34 @@
# Use an official Python runtime as a parent image
FROM python:3.11-slim
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
# Set working directory
WORKDIR /app
# Install system dependencies
RUN apt-get update && apt-get install -y \
build-essential \
libpq-dev \
default-libmysqlclient-dev \
pkg-config \
&& rm -rf /var/lib/apt/lists/*
# Install Python dependencies
COPY requirements.txt /app/
RUN pip install --no-cache-dir -r requirements.txt
RUN pip install gunicorn
# Copy project files
COPY . /app/
# Expose the port on which the application will run
EXPOSE 3030
# Define environment variable for Gunicorn
ENV GUNICORN_CMD_ARGS="--bind 0.0.0.0:3030"
# Run Gunicorn server with your Django application
CMD ["gunicorn", "BH.wsgi:application"]

View File

@ -7,7 +7,7 @@ from django.utils import timezone
class Blog(models.Model):
content = models.TextField()
title = models.CharField(max_length=150)
author = models.ForeignKey(User, on_delete=models.CASCADE)
author = models.TextField() #models.ForeignKey(User, on_delete=models.CASCADE)
date_posted = models.DateTimeField(default=timezone.now)
def get_absolute_url(self):

14
docker-compose.yml Normal file
View File

@ -0,0 +1,14 @@
services:
django:
build: .
env_file:
- .env
volumes:
- .:/app
ports:
- "3030:3030"
command: >
sh -c "python manage.py makemigrations blog --noinput &&
python manage.py migrate --noinput &&
python manage.py collectstatic --noinput &&
gunicorn BH.wsgi:application --bind 0.0.0.0:3030 --workers ${GUNICORN_WORKERS:-3}"

Binary file not shown.