new file mode 100644
@@ -0,0 +1,5 @@
+# MySQL settings
+MYSQL_ROOT_PASSWORD=root
+MYSQL_DATABASE=errorreport_db
+MYSQL_USER=errorreport
+MYSQL_PASSWORD=errorreport
new file mode 100644
@@ -0,0 +1,17 @@
+# Use an official Python runtime as a parent image
+FROM python:3.10
+
+# Set environment variables
+ENV PYTHONDONTWRITEBYTECODE 1
+ENV PYTHONUNBUFFERED 1
+
+# Set the working directory
+WORKDIR /app
+
+# Install dependencies
+COPY requirements.txt /app/
+RUN pip install -r requirements.txt
+
+# Copy the project code into the container
+COPY . /app/
+RUN cp -rf /app/project/settings.py.docker /app/project/settings.py
@@ -22,9 +22,10 @@ Setup instructions:
1. Initialise and activate a python virtual environment. `virtualenv venv && source ./venv/bin/activate`
2. Install the dependencies via `pip install -r requirements.txt`
-3. Set DATABASES.default.ENGINE in settings.py to use the database engine of your choice.
-4. Set a SECRET_KEY in settings.py
-5. Setup the database schema with the Django model. Run `python manage.py migrate`.
+3. cp settings.py.host settings.py
+4. Set DATABASES.default.ENGINE in settings.py to use the database engine of your choice.
+5. Set a SECRET_KEY in settings.py
+6. Setup the database schema with the Django model. Run `python manage.py migrate`.
Usage
new file mode 100644
@@ -0,0 +1,38 @@
+version: '3'
+services:
+ db:
+ image: mysql:8.0.36
+ container_name: error_report_web_db
+ restart: always
+ volumes:
+ - data:/var/lib/mysql
+ environment:
+ MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
+ MYSQL_DATABASE: ${MYSQL_DATABASE}
+ MYSQL_USER: ${MYSQL_USER}
+ MYSQL_PASSWORD: ${MYSQL_PASSWORD}
+ ports:
+ - "3306:3306"
+ healthcheck:
+ test: ["CMD", "mysql", "-h", "localhost", "-u", "root", "-p${MYSQL_ROOT_PASSWORD}", "-e", "SELECT 1"]
+ timeout: 20s
+ retries: 10
+
+ backend:
+ build:
+ context: .
+ dockerfile: Dockerfile
+ container_name: error_report_web_backend
+ command: sh -c "python3 manage.py migrate --noinput && python3 manage.py runserver 0.0.0.0:8000"
+ volumes:
+ - .:/app
+ restart: always
+ ports:
+ - "8000:8000"
+ env_file:
+ - .env
+ depends_on:
+ db:
+ condition: service_healthy
+volumes:
+ data:
@@ -17,18 +17,12 @@ MANAGERS = ADMINS
DATABASES = {
'default': {
- # exmplae backends: 'postgresql_psycopg2', 'mysql', 'sqlite3'
- # or 'oracle'.
- 'ENGINE': 'django.db.backends.sqlite3',
- # Or path to database file if using sqlite3.
- 'NAME': 'error-report-db.sqlite3',
- # Not used with sqlite3.
- 'USER': '',
- 'PASSWORD': '',
- # Set to empty string for localhost.
- 'HOST': '',
- # Set to empty string for default.
- 'PORT': '',
+ 'ENGINE': 'django.db.backends.mysql',
+ 'NAME': os.environ.get('MYSQL_DATABASE'),
+ 'USER': os.environ.get('MYSQL_USER'),
+ 'PASSWORD': os.environ.get('MYSQL_PASSWORD'),
+ 'HOST': os.environ.get('DB_HOST', 'db'),
+ 'PORT': os.environ.get('DB_PORT', '3306'),
}
}
@@ -214,3 +208,5 @@ LOGIN_REDIRECT_URL = '/Errors'
TEST_RUNNER = 'django.test.runner.DiscoverRunner'
DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'
+
+ALLOWED_HOSTS = ['*']
similarity index 93%
copy from project/settings.py
copy to project/settings.py.docker
@@ -17,18 +17,12 @@ MANAGERS = ADMINS
DATABASES = {
'default': {
- # exmplae backends: 'postgresql_psycopg2', 'mysql', 'sqlite3'
- # or 'oracle'.
- 'ENGINE': 'django.db.backends.sqlite3',
- # Or path to database file if using sqlite3.
- 'NAME': 'error-report-db.sqlite3',
- # Not used with sqlite3.
- 'USER': '',
- 'PASSWORD': '',
- # Set to empty string for localhost.
- 'HOST': '',
- # Set to empty string for default.
- 'PORT': '',
+ 'ENGINE': 'django.db.backends.mysql',
+ 'NAME': os.environ.get('MYSQL_DATABASE'),
+ 'USER': os.environ.get('MYSQL_USER'),
+ 'PASSWORD': os.environ.get('MYSQL_PASSWORD'),
+ 'HOST': os.environ.get('DB_HOST', 'db'),
+ 'PORT': os.environ.get('DB_PORT', '3306'),
}
}
similarity index 100%
copy from project/settings.py
copy to project/settings.py.host