Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialization docker #11

Merged
merged 4 commits into from
Mar 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,27 @@
# apply
System for applying for positions within UTN





## Docker
Notera att du måste ha .env filen i root mappen för att allt ska fungera!

# För att starta Docker
docker-compose up --build # Bygger och startar alla tjänster

# För att starta om Docker
docker-compose restart # Startar om alla tjänster

# För att stoppa och ta bort Docker-containrar
docker-compose down # Stoppar och tar bort containrar och nätverk

# För att också ta bort volymer (t.ex. om du vill återställa databasen)
docker-compose down --volumes # Stoppar och tar bort containrar, nätverk och volymer


# Efter du startat docker
Efter du har startat docker så har du nu en databas (postgres) och en server som kör på port localhost:8000

Nu behöver du bara gå in i frontend/apply och köra npm run dev
Empty file removed apply/__init__.py
Empty file.
17 changes: 17 additions & 0 deletions backend.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# official Python image
FROM python:3.12

# set working directory in container
WORKDIR /app

# copy dependencies file and install dependencies, requirements.txt is taken from old project
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# copy the whole project (including manage.py in the root dir)
COPY . .

# expose port 8000 for Django
EXPOSE 8000

CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
2 changes: 1 addition & 1 deletion apply/asgi.py → backend/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'apply.settings')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings')

application = get_asgi_application()
16 changes: 11 additions & 5 deletions apply/settings.py → backend/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"""

from pathlib import Path
import os

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
Expand All @@ -37,6 +38,7 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'backend'
]

MIDDLEWARE = [
Expand All @@ -49,7 +51,7 @@
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'apply.urls'
ROOT_URLCONF = 'backend.urls'

TEMPLATES = [
{
Expand All @@ -67,20 +69,24 @@
},
]

WSGI_APPLICATION = 'apply.wsgi.application'
WSGI_APPLICATION = 'backend.wsgi.application'


# Database
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases

# Detta har ändrats sedan standard installationen
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
'ENGINE': 'django.db.backends.postgresql',
'NAME': os.getenv("POSTGRES_DB"),
'USER': os.getenv("POSTGRES_USER"),
'PASSWORD': os.getenv("POSTGRES_PASSWORD"),
'HOST': 'db',
'PORT': 5432,
}
}


# Password validation
# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators

Expand Down
2 changes: 1 addition & 1 deletion apply/urls.py → backend/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from django.urls import path, include
from rest_framework.routers import DefaultRouter
from .views import PositionViewSet

Expand Down
2 changes: 1 addition & 1 deletion apply/wsgi.py → backend/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'apply.settings')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings')

application = get_wsgi_application()
31 changes: 31 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
version: "3.8"

services:
db:
image: postgres:15
container_name: postgres_db
restart: always
env_file:
- .env # load environment variables from .env
ports:
- "5432:5432"
volumes:
- pg_data:/var/lib/postgresql/data

backend:
build:
context: .
dockerfile: backend.Dockerfile
container_name: django_backend
depends_on:
- db
ports:
- "8000:8000"
env_file:
- .env # load environment variables from .env
volumes:
- .:/app
command: ["python", "manage.py", "runserver", "0.0.0.0:8000"]

volumes:
pg_data:
2 changes: 1 addition & 1 deletion manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'apply.settings')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
Expand Down
18 changes: 18 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# async functionality
asgiref==3.6.0

# Websockets
channels[daphne]==4.0.0
channels_redis==4.1.0

# Django
Django[argon2]==4.1.7
django-cors-headers==3.14.0
django-filter==23.2
djangorestframework==3.14.0

# Handy config
python-decouple==3.8

psycopg2
Pillow>=8.0.0