Compare commits

...

4 Commits

Author SHA1 Message Date
Surya e7a1572905 Merge pull request 'made everything to a docker file' (#6) from dockerisation into master
Reviewed-on: #6
This makes the Site Ready for Deployment.
2024-08-05 13:17:28 +02:00
Jukoga c916a2f583 updated the README.md 2024-08-05 13:13:59 +02:00
root 2e1fd94c8f production ready 2024-08-05 13:01:21 +02:00
Jukoga 2c286dacf4 made everything to a docker file 2024-08-01 13:33:38 +02:00
7 changed files with 76 additions and 11 deletions

5
.gitignore vendored
View File

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

View File

@ -17,6 +17,8 @@ from dotenv import load_dotenv
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEMPLATES_DIR = os.path.join(BASE_DIR + '/templates') TEMPLATES_DIR = os.path.join(BASE_DIR + '/templates')
DEFAULT_AUTO_FIELD='django.db.models.AutoField'
# Quick-start development settings - unsuitable for production # Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/ # 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! # SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False 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 # Application definition
@ -128,6 +130,7 @@ USE_TZ = True
# Static files (CSS, JavaScript, Images) # Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/ # https://docs.djangoproject.com/en/3.0/howto/static-files/
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/static/' STATIC_URL = '/static/'
MEDIA_ROOT = os.path.join(BASE_DIR + '/media') MEDIA_ROOT = os.path.join(BASE_DIR + '/media')
MEDIA_URL = '/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

@ -1,13 +1,23 @@
## Requirements
The website requires the following:
- Docker
- Docker Compose
- A running MariaDB Instance
## Deployment ## Deployment
To deploy the website: To deploy the website:
- first clone the repository to any local folder - first clone the repository to any local folder
- then open the folder with the `manage.py` file - then open the folder
- then `Shift`+`Right Click` and click on `Open PowerShell window here` - create a new file called `.env` and add the following:
- then create the virtual environment by typing `py -m venv .venv` ```
- then activate the virtual environment by typing `.venv\Scripts\Activate` SECRET_KEY=your_secret_key
- then install the requirements by typing `pip install -r requirements.txt` DB_NAME=your_db_name
- then type in `py manage.py runserver 3000` DB_USER=your_db_user
- open browser at address `localhost:3000` or `127.0.0.1:3000` 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 ## Structure
The website has a Home page and a News page currently. The News page shows all developer blogs. The website has a Home page and a News page currently. The News page shows all developer blogs.

View File

@ -7,7 +7,7 @@ from django.utils import timezone
class Blog(models.Model): class Blog(models.Model):
content = models.TextField() content = models.TextField()
title = models.CharField(max_length=150) 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) date_posted = models.DateTimeField(default=timezone.now)
def get_absolute_url(self): def get_absolute_url(self):

15
docker-compose.yml Normal file
View File

@ -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}"

Binary file not shown.