diff --git a/backend/.dockerignore b/backend/.dockerignore new file mode 100644 index 00000000..e1165672 --- /dev/null +++ b/backend/.dockerignore @@ -0,0 +1,4 @@ +__pycache__/ +*.pyc +.env +.git diff --git a/backend/Dockerfile b/backend/Dockerfile new file mode 100644 index 00000000..6fbbc3d6 --- /dev/null +++ b/backend/Dockerfile @@ -0,0 +1,19 @@ +FROM python:3.11-slim AS builder +WORKDIR /app +RUN apt-get update && apt-get install -y build-essential +COPY requirements.txt . +RUN pip install --prefix=/install -r requirements.txt + +FROM python:3.11-slim +WORKDIR /app +RUN useradd -m appuser +RUN mkdir -p /app/db \ + && chown -R appuser:appuser /app + +USER appuser + +COPY --from=builder /install /usr/local +COPY . . +USER appuser +EXPOSE 8000 +CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"] diff --git a/backend/config/urls.py b/backend/config/urls.py index 193911f5..0cc639be 100644 --- a/backend/config/urls.py +++ b/backend/config/urls.py @@ -1,23 +1,9 @@ -""" -URL configuration for config project. - -The `urlpatterns` list routes URLs to views. For more information please see: - https://docs.djangoproject.com/en/6.0/topics/http/urls/ -Examples: -Function views - 1. Add an import: from my_app import views - 2. Add a URL to urlpatterns: path('', views.home, name='home') -Class-based views - 1. Add an import: from other_app.views import Home - 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') -Including another URLconf - 1. Import the include() function: from django.urls import include, path - 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) -""" from django.contrib import admin from django.urls import path, include +from django.http import HttpResponse urlpatterns = [ + path('', lambda request: HttpResponse("Backend is running 🚀")), path('admin/', admin.site.urls), path('api/', include('core.urls')), ] diff --git a/backend/core/urls.py b/backend/core/urls.py index eb42a8dc..2e7cfcc3 100644 --- a/backend/core/urls.py +++ b/backend/core/urls.py @@ -1,6 +1,8 @@ from django.urls import path +from django.http import HttpResponse from .views import hello_world urlpatterns = [ + path('', lambda request: HttpResponse("API is running 🚀")), path('hello/', hello_world, name='hello_world'), ] diff --git a/backend/requirements.txt b/backend/requirements.txt new file mode 100644 index 00000000..8e1f5387 --- /dev/null +++ b/backend/requirements.txt @@ -0,0 +1,3 @@ +django-cors-headers +Django>=4.2 +gunicorn diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..108e971b --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,16 @@ +version: "3.9" + +services: + backend: + build: ./backend + ports: + - "8000:8000" + environment: + - DEBUG=True + + frontend: + build: ./frontend + ports: + - "3000:80" + depends_on: + - backend diff --git a/frontend/Dockerfile b/frontend/Dockerfile new file mode 100644 index 00000000..5341d558 --- /dev/null +++ b/frontend/Dockerfile @@ -0,0 +1,21 @@ +FROM node:20-alpine AS builder +WORKDIR /app +COPY package*.json ./ +RUN npm install +COPY . . +RUN npm run build + + +FROM nginx:alpine + +RUN adduser -D appuser \ + && mkdir -p /var/cache/nginx /var/run/nginx /run \ + && chown -R appuser:appuser /var/cache/nginx /var/run/nginx /run + +USER appuser + + + +COPY --from=builder /app/dist /usr/share/nginx/html +USER appuser +EXPOSE 80