diff --git a/safeshare/Dockerfile b/safeshare/Dockerfile new file mode 100644 index 0000000..4c05e08 --- /dev/null +++ b/safeshare/Dockerfile @@ -0,0 +1,18 @@ +FROM python:3.10 + +# Install Netcat +RUN apt-get update && \ + apt-get -y install netcat-traditional && \ + apt-get clean + +ENV PYTHONUNBUFFERED 1 + +WORKDIR /code + +COPY requirements.txt ./ +RUN pip install --no-cache-dir -r requirements.txt + +COPY . /code/ + +RUN chmod a+x start.sh +CMD ["./start.sh"] \ No newline at end of file diff --git a/safeshare/docker-compose.yml b/safeshare/docker-compose.yml new file mode 100644 index 0000000..9ee7bc2 --- /dev/null +++ b/safeshare/docker-compose.yml @@ -0,0 +1,73 @@ +version: '3' + +services: + db: + image: mariadb:10.5 + command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW + restart: always + volumes: + - db_data:/var/lib/mysql + networks: + - dbnet + environment: + - MYSQL_DATABASE=safeShare + - MYSQL_USER=user + - MYSQL_ROOT_PASSWORD=password + - MYSQL_PASSWORD=password + expose: + - 3306 + + redis: + image: redis:latest + command: redis-server --requirepass password + restart: always + networks: + - dbnet + expose: + - 6379 + volumes: + - redis_data:/data + + study_together: + build: + context: . + dockerfile: Dockerfile + restart: + always + ports: + - "8000:8000" # Map container port 8000 to host port 8000 + environment: + - DEBUG=True + - SECRET_KEY=A_RANDOM_SECRET_KEY + - DB_NAME=testSite + - DB_USER=user + - DB_PASSWORD=password + - DB_HOST=db + - DB_PORT=3306 + - ALLOWED_HOSTS=* + - CACHE=True + - REDIS_URL=redis://:password@redis:6379/0 + depends_on: + - db + - redis + networks: + - dbnet + + frontend: + build: + context: ./study-frontend + dockerfile: Dockerfile + restart: + always + ports: + - "3000:3000" # Map container port 3000 to host port 3000 + environment: + - REACT_APP_API_URL=http://localhost:8000/api + networks: + - dbnet +volumes: + db_data: + redis_data: + +networks: + dbnet: diff --git a/safeshare/safeshare-frontend/Dockerfile b/safeshare/safeshare-frontend/Dockerfile new file mode 100644 index 0000000..47b6719 --- /dev/null +++ b/safeshare/safeshare-frontend/Dockerfile @@ -0,0 +1,11 @@ +FROM node + +WORKDIR /frontend + +COPY . . + +RUN npm install + +EXPOSE 3000 + +CMD ["npm", "start"] diff --git a/safeshare/safeshare/settings.py b/safeshare/safeshare/settings.py index 33a6fb9..9f3bc6f 100644 --- a/safeshare/safeshare/settings.py +++ b/safeshare/safeshare/settings.py @@ -116,31 +116,31 @@ WSGI_APPLICATION = 'safeshare.wsgi.application' # Database # https://docs.djangoproject.com/en/4.2/ref/settings/#databases -# if os.getenv('GITHUB_WORKFLOW'): -# DATABASES = { -# 'default': { -# 'ENGINE': 'django.db.backends.postgresql', -# 'NAME': 'github-actions', -# 'USER': 'postgres', -# 'PASSWORD': 'postgres', -# 'HOST': 'localhost', -# 'PORT': '5432' -# } -# } -# else: -# DATABASES = { -# 'default': { -# 'ENGINE': 'django.db.backends.mysql', -# 'NAME': env.str('DB_NAME', 'safeshare'), -# 'USER': env.str('DB_USER', 'mariadb'), -# 'PASSWORD': env.str('DB_PASSWORD', 'mariadb'), -# 'HOST': env.str('DB_HOST', 'localhost'), -# 'PORT': env.str('DB_PORT', '3306'), -# 'OPTIONS': { -# 'init_command': "SET sql_mode='STRICT_TRANS_TABLES', innodb_strict_mode=1", -# }, -# } -# } +if os.getenv('GITHUB_WORKFLOW'): + DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.postgresql', + 'NAME': 'github-actions', + 'USER': 'postgres', + 'PASSWORD': 'postgres', + 'HOST': 'localhost', + 'PORT': '5432' + } + } +else: + DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.mysql', + 'NAME': env.str('DB_NAME', 'safeshare'), + 'USER': env.str('DB_USER', 'mariadb'), + 'PASSWORD': env.str('DB_PASSWORD', 'mariadb'), + 'HOST': env.str('DB_HOST', 'localhost'), + 'PORT': env.str('DB_PORT', '3306'), + 'OPTIONS': { + 'init_command': "SET sql_mode='STRICT_TRANS_TABLES', innodb_strict_mode=1", + }, + } + } if env.bool('CACHE', default=False): CACHES = { diff --git a/safeshare/safeshare_app/views/file.py b/safeshare/safeshare_app/views/file.py index 9cb7b2f..369fa09 100644 --- a/safeshare/safeshare_app/views/file.py +++ b/safeshare/safeshare_app/views/file.py @@ -4,7 +4,6 @@ import uuid from django.core.cache import cache from rest_framework.decorators import api_view from rest_framework.response import Response -from django.conf import settings @api_view(['GET', 'POST']) diff --git a/safeshare/start.sh b/safeshare/start.sh new file mode 100644 index 0000000..d3c616b --- /dev/null +++ b/safeshare/start.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +# Wait until Database is ready +while ! nc -z db 3306; do sleep 1; done + +python manage.py migrate --noinput + +# Seed the database with initial data +#python manage.py loaddata study_together_app/fixtures/* + +python manage.py runserver 0.0.0.0:8000 \ No newline at end of file