Merge pull request 'made everything to a docker file' (#6) from dockerisation into master
Reviewed-on: #6 This makes the Site Ready for Deployment.test
commit
e7a1572905
|
|
@ -2,10 +2,13 @@
|
|||
*/__pycache__/
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
|
||||
# C extensions
|
||||
*.so
|
||||
|
||||
#added
|
||||
staticfiles/
|
||||
*/migrations/
|
||||
|
||||
# Distribution / packaging
|
||||
.Python
|
||||
build/
|
||||
|
|
|
|||
|
|
@ -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/'
|
||||
|
|
|
|||
|
|
@ -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"]
|
||||
26
README.md
26
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.
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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}"
|
||||
BIN
requirements.txt
BIN
requirements.txt
Binary file not shown.
Loading…
Reference in New Issue