diff --git a/.gitignore b/.gitignore index e0ad09e..111219a 100644 --- a/.gitignore +++ b/.gitignore @@ -2,10 +2,13 @@ */__pycache__/ *.py[cod] *$py.class - # C extensions *.so +#added +staticfiles/ +*/migrations/ + # Distribution / packaging .Python build/ diff --git a/BH/settings.py b/BH/settings.py index f03e22a..a876ea9 100644 --- a/BH/settings.py +++ b/BH/settings.py @@ -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/ @@ -29,7 +31,7 @@ SECRET_KEY = os.getenv('SECRET_KEY') # SECURITY WARNING: don't run with debug turned on in production! DEBUG = False -ALLOWED_HOSTS = ['localhost', '127.0.0.1'] +ALLOWED_HOSTS = ['localhost', '127.0.0.1', 'beyond-heroes.com', 'www.beyond-heroes.com'] # Application definition @@ -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/' diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b0f8294 --- /dev/null +++ b/Dockerfile @@ -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"] diff --git a/README.md b/README.md index 201c06a..bd59457 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,23 @@ +## Requirements +The website requires the following: +- Docker +- Docker Compose +- A running MariaDB Instance + ## Deployment -To deploy the website: +To deploy the website: - first clone the repository to any local folder -- then open the folder with the `manage.py` file -- then `Shift`+`Right Click` and click on `Open PowerShell window here` -- then create the virtual environment by typing `py -m venv .venv` -- then activate the virtual environment by typing `.venv\Scripts\Activate` -- then install the requirements by typing `pip install -r requirements.txt` -- then type in `py manage.py runserver 3000` -- open browser at address `localhost:3000` or `127.0.0.1:3000` +- then open the folder +- create a new file called `.env` and add the following: +``` +SECRET_KEY=your_secret_key +DB_NAME=your_db_name +DB_USER=your_db_user +DB_PASSWORD=your_db_password +DB_HOST=your_db_host +DB_PORT=your_db_port +``` +- run `docker-compose up --build` to start the website ## Structure The website has a Home page and a News page currently. The News page shows all developer blogs. diff --git a/blog/models.py b/blog/models.py index 961fe1e..a209119 100644 --- a/blog/models.py +++ b/blog/models.py @@ -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): diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..0784b53 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,15 @@ +services: + django: + build: . + env_file: + - .env + volumes: + - .:/app + ports: + - "3030:3030" + network_mode: "host" + 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}" diff --git a/requirements.txt b/requirements.txt index 00e0c28..93ba28d 100644 Binary files a/requirements.txt and b/requirements.txt differ