diff --git a/.gitignore b/.gitignore index b17657e..a101333 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ -.env -backend/qlockify-backend/ -frontend/qlockify-frontend/ +.env +backend/logs/ +backend/.pytest_cache/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..1fb0d85 --- /dev/null +++ b/README.md @@ -0,0 +1,33 @@ +# Qlockify Deployment + +This repository is the deployment layer only. + +It does not contain application source copies. Docker builds read directly from the sibling repositories: + +- `../qlockify-backend` +- `../qlockify-frontend` + +## Local structure + +The expected directory layout is: + +```text +Qlockify/ + qlockify-backend/ + qlockify-frontend/ + qlockify-deployment/ +``` + +## Deployment flow + +1. Configure deployment env files: + - `./.env` + - `./backend/.env` + - `./frontend/.env` +2. From `qlockify-deployment`, build and start the stack: + +```powershell +docker compose up --build +``` + +The backend container runs database migrations and `collectstatic` on startup, then serves Django with Gunicorn using `config.wsgi:application`. diff --git a/backend/.env.sample b/backend/.env.sample index 45fa934..eb55a22 100644 --- a/backend/.env.sample +++ b/backend/.env.sample @@ -11,7 +11,7 @@ DJANGO_ALLOWED_HOSTS= POSTGRES_DB=app_db POSTGRES_USER=app_user POSTGRES_PASSWORD=app_password -POSTGRES_HOST=localhost +POSTGRES_HOST=db POSTGRES_PORT=5432 # CORS / CSRF @@ -30,11 +30,11 @@ JWT_ALGORITHM=HS256 # Redis / Celery REDIS_URL=redis://redis:6379/0 -REDIS_HOST=127.0.0.1 +REDIS_HOST=redis REDIS_PORT=6379 REDIS_PASSWORD= -CELERY_BROKER_URL= -CELERY_RESULT_BACKEND= +CELERY_BROKER_URL=redis://redis:6379/0 +CELERY_RESULT_BACKEND=redis://redis:6379/0 # Timzone / Language LANGUAGE_CODE=en-us diff --git a/backend/Dockerfile b/backend/Dockerfile index 93c95c4..9948a8c 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -16,10 +16,10 @@ RUN apt-get update \ && apt-get install -y gcc libpq-dev \ && rm -rf /var/lib/apt/lists/* -COPY qlockify-backend/requirements/ /app/requirements/ -RUN pip install --no-cache-dir -r requirements/base.txt \ - && pip install --no-cache-dir -r requirements/prod.txt - -COPY qlockify-backend/ . - -CMD ["gunicorn", "core.wsgi:application", "--bind", "0.0.0.0:8000"] +COPY qlockify-backend/requirements/ /app/requirements/ +RUN pip install --no-cache-dir -r requirements/base.txt \ + && pip install --no-cache-dir -r requirements/prod.txt + +COPY qlockify-backend/ . + +CMD ["gunicorn", "config.wsgi:application", "--bind", "0.0.0.0:8000"] diff --git a/docker-compose.yml b/docker-compose.yml index 4e63ff1..c817788 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,5 @@ -version: '3.8' - -services: - db: +services: + db: image: postgres:18-alpine restart: always env_file: @@ -26,34 +24,38 @@ services: ports: - "127.0.0.1:6379:6379" - backend: - build: - context: ./backend - dockerfile: Dockerfile + backend: + build: + context: .. + dockerfile: qlockify-deployment/backend/Dockerfile restart: always env_file: - ./backend/.env - volumes: - - static_data:/app/staticfiles - - media_data:/app/mediafiles - expose: - - "8000" + volumes: + - static_data:/app/staticfiles + - media_data:/app/mediafiles + command: > + sh -c "python manage.py migrate && + python manage.py collectstatic --noinput && + gunicorn config.wsgi:application --bind 0.0.0.0:8000" + expose: + - "8000" depends_on: db: condition: service_healthy redis: condition: service_started - celery: - build: - context: ./backend - dockerfile: Dockerfile + celery: + build: + context: .. + dockerfile: qlockify-deployment/backend/Dockerfile restart: always env_file: - ./backend/.env volumes: - media_data:/app/mediafiles - command: celery -A core worker -l INFO + command: celery -A config worker -l INFO depends_on: db: condition: service_healthy @@ -62,10 +64,10 @@ services: backend: condition: service_started - frontend: - build: - context: ./frontend - dockerfile: Dockerfile + frontend: + build: + context: .. + dockerfile: qlockify-deployment/frontend/Dockerfile restart: always env_file: - ./frontend/.env @@ -87,7 +89,7 @@ services: - backend - frontend -volumes: - postgres_data: - static_data: - media_data: +volumes: + postgres_data: + static_data: + media_data: diff --git a/frontend/.env.sample b/frontend/.env.sample index de4c9d5..77ce981 100644 --- a/frontend/.env.sample +++ b/frontend/.env.sample @@ -1 +1 @@ -VITE_API_BASE_URL=http://localhost/api +VITE_API_BASE_URL=http://localhost/api diff --git a/frontend/Dockerfile b/frontend/Dockerfile index a29e6b4..7d9aa5e 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -4,11 +4,11 @@ WORKDIR /app RUN npm config set registry https://package-mirror.liara.ir/repository/npm/ --global -COPY qlockify-frontend/package*.json ./ -RUN npm install - -COPY qlockify-frontend/ . -RUN npm run build +COPY qlockify-frontend/package*.json ./ +RUN npm install + +COPY qlockify-frontend/ . +RUN npm run build FROM nginx:alpine