Skip to content

Commit 64a67d6

Browse files
Merge pull request #140 from mrsumanbiswas/3-devops-create-unified-docker-composeyml-for-local-multi-container-development
docker-mutlistage setup and few fixes
2 parents 7ef8d28 + d475904 commit 64a67d6

35 files changed

Lines changed: 641 additions & 311 deletions

‎.env.example‎

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,37 @@
1-
HOST=0.0.0.0
2-
PORT=8000
1+
# -----------------------------------------------------------------------------
2+
# Host User & System Settings (for Rootless Docker)
3+
# Run `id -u` and `id -g` on Linux/macOS to get these values
4+
# -----------------------------------------------------------------------------
5+
UID=1000
6+
GID=1000
37

4-
# PostgreSQL Configuration (PostgreSQL 16)
5-
POSTGRES_USER=fashio_admin
6-
POSTGRES_PASSWORD=SuperSecureAndComplexPassword2026!
8+
# -----------------------------------------------------------------------------
9+
# Port Configurations
10+
# -----------------------------------------------------------------------------
11+
POSTGRES_PORT=5432
12+
BACKEND_PORT=8000
13+
FRONTEND_PORT=5173
14+
15+
# -----------------------------------------------------------------------------
16+
# Database Configuration
17+
# -----------------------------------------------------------------------------
718
POSTGRES_DB=fashio_db
8-
POSTGRES_PORT=42359
9-
POSTGRES_HOST=127.0.0.1
19+
POSTGRES_USER=fashio_user
20+
POSTGRES_PASSWORD=fashio_secure_password
21+
POSTGRES_HOST=db
1022

11-
# JWT
12-
JWT_SECRET=my_super_long_and_secure_secret_key
23+
# -----------------------------------------------------------------------------
24+
# Django / Security Settings
25+
# -----------------------------------------------------------------------------
26+
JWT_SECRET=super-secret-jwt-key-change-in-production
1327

14-
# OAuth2 Authentication Providers
15-
# Google Developer Console Credentials
16-
GOOGLE_CLIENT_ID=your_google_client_id.apps.googleusercontent.com
17-
GOOGLE_CLIENT_SECRET=GOCSPX-your_google_client_secret
18-
GOOGLE_REDIRECT_URL=http://localhost:8000/api/auth/google/callback
28+
# -----------------------------------------------------------------------------
29+
# OAuth Credentials (Google & GitHub)
30+
# -----------------------------------------------------------------------------
31+
GOOGLE_CLIENT_ID=your-google-client-id.apps.googleusercontent.com
32+
GOOGLE_CLIENT_SECRET=your-google-client-secret
33+
GOOGLE_REDIRECT_URL=http://localhost:8000/api/auth/google/callback/
1934

20-
# GitHub Developer Settings Credentials
21-
GITHUB_CLIENT_ID=ov-your_github_client_id
22-
GITHUB_CLIENT_SECRET=your_github_client_secret
23-
GITHUB_REDIRECT_URL=http://localhost:8000/api/auth/github/callback
35+
GITHUB_CLIENT_ID=your-github-client-id
36+
GITHUB_CLIENT_SECRET=your-github-client-secret
37+
GITHUB_REDIRECT_URL=http://localhost:8000/api/auth/github/callback/

‎.flake8‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[flake8]
2+
max-line-length = 88
3+
extend-ignore = E203
4+
5+
# Allow star imports specifically in settings modules
6+
per-file-ignores =
7+
config/settings/*.py: F401, F403, F405
8+
9+
exclude =
10+
.git,
11+
__pycache__,
12+
.venv,
13+
*/migrations/*

‎.github/workflows/backend-ci.yml‎

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,74 @@
1-
name: Backend Tests
1+
name: Backend CI
22

33
on:
44
push:
5+
branches: [ main, dev ]
6+
paths:
7+
- "backend/**"
8+
- ".github/workflows/backend-ci.yml"
59
pull_request:
10+
branches: [ main, dev ]
11+
paths:
12+
- "backend/**"
13+
- ".github/workflows/backend-ci.yml"
614

715
permissions:
816
contents: read
917

1018
jobs:
1119
test:
1220
runs-on: ubuntu-latest
21+
22+
env:
23+
DJANGO_SETTINGS_MODULE: config.settings.local
24+
POSTGRES_DB: fashio_test_db
25+
POSTGRES_USER: fashio_test_user
26+
POSTGRES_PASSWORD: fashio_test_password
27+
POSTGRES_HOST: localhost
28+
POSTGRES_PORT: 5432
29+
JWT_SECRET: test-jwt-secret-key-for-ci-pipeline
30+
31+
defaults:
32+
run:
33+
working-directory: backend
1334

1435
services:
1536
postgres:
1637
image: postgres:16-alpine
1738
env:
18-
POSTGRES_USER: ${{ vars.POSTGRES_USER || 'fashio_admin' }}
19-
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD || 'local_test_password' }}
20-
POSTGRES_DB: ${{ vars.POSTGRES_DB || 'fashio_db' }}
39+
POSTGRES_DB: fashio_test_db
40+
POSTGRES_USER: fashio_test_user
41+
POSTGRES_PASSWORD: fashio_test_password
2142
ports:
2243
- 5432:5432
2344
options: >-
2445
--health-cmd pg_isready
25-
--health-interval 10s
46+
--health-interval 5s
2647
--health-timeout 5s
2748
--health-retries 5
2849
2950
steps:
3051
- name: Checkout source code
3152
uses: actions/checkout@v4
3253

33-
- name: Install uv and set up python
54+
- name: Install uv and enable caching
3455
uses: astral-sh/setup-uv@v5
3556
with:
3657
version: "latest"
3758
enable-cache: true
3859
cache-dependency-lock-file: "backend/uv.lock"
3960

40-
- name: Install dependencies
41-
working-directory: backend
61+
- name: Ensure Python 3.12 is installed
62+
run: uv python install 3.12
63+
64+
- name: Install project dependencies
4265
run: uv sync --frozen
4366

44-
- name: Run flake8
45-
working-directory: backend
46-
run: |
47-
uv run flake8 . --exclude=.venv --count --select=E9,F63,F7,F82 --show-source --statistics
48-
uv run flake8 . --exclude=.venv --count --exit-zero --max-complexity=10 --max-line-length=119 --statistics
67+
- name: Lint code with Ruff
68+
run: uv run ruff check .
4969

50-
- name: Run black check
51-
working-directory: backend
52-
run: uvx black --check --verbose .
70+
- name: Check code formatting with Ruff
71+
run: uv run ruff format --check .
5372

54-
- name: Run pytest
55-
working-directory: backend
73+
- name: Run Pytest suite
5674
run: uv run pytest

‎backend/.dockerignore‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
.venv
22
__pycache__
33
*.pyc
4+
*.pyo
5+
*.pyd
46
.git
5-
.env
7+
.gitignore
8+
.env
9+
.pytest_cache
10+
.coverage
11+
htmlcov
12+
media
13+
staticfiles

‎backend/Dockerfile‎

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,62 @@
1-
FROM python:3.12-slim
1+
FROM python:3.12-slim AS base
22

3-
ENV PYTHONDONTWRITEBYTECODE=1
4-
ENV PYTHONUNBUFFERED=1
3+
ENV PYTHONUNBUFFERED=1 \
4+
PYTHONDONTWRITEBYTECODE=1 \
5+
UV_COMPILE_BYTECODE=1 \
6+
UV_LINK_MODE=copy
57

68
WORKDIR /app
79

8-
RUN pip install --no-cache-dir uv
10+
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
11+
12+
FROM base AS development
13+
14+
ENV UV_CACHE_DIR=/tmp/.uv-cache
915

1016
COPY pyproject.toml uv.lock ./
1117

12-
RUN uv sync --frozen
18+
RUN uv sync --frozen && rm -rf /tmp/.uv-cache
19+
20+
COPY . .
21+
22+
EXPOSE 8000
23+
24+
CMD ["uv", "run", "python", "manage.py", "runserver", "0.0.0.0:8000"]
25+
26+
FROM base AS builder
27+
28+
RUN apt-get update && apt-get install -y --no-install-recommends \
29+
build-essential \
30+
libpq-dev \
31+
&& rm -rf /var/lib/apt/lists/*
32+
33+
COPY pyproject.toml uv.lock ./
34+
RUN uv sync --frozen --no-dev --no-install-project
1335

1436
COPY . .
37+
RUN uv sync --frozen --no-dev
38+
FROM python:3.12-slim AS production
39+
40+
ENV PYTHONUNBUFFERED=1 \
41+
PYTHONDONTWRITEBYTECODE=1 \
42+
PATH="/app/.venv/bin:$PATH"
43+
44+
WORKDIR /app
45+
46+
RUN apt-get update && apt-get install -y --no-install-recommends \
47+
libpq5 \
48+
curl \
49+
&& rm -rf /var/lib/apt/lists/*
50+
51+
COPY --from=builder /app/.venv /app/.venv
52+
COPY --from=builder /app /app
53+
54+
RUN addgroup --gid 1000 appgroup && \
55+
adduser --uid 1000 --gid 1000 --disabled-password --gecos "" appuser && \
56+
chown -R appuser:appgroup /app
57+
58+
USER appuser
1559

1660
EXPOSE 8000
1761

18-
CMD ["uv", "run", "python", "manage.py", "runserver", "${HOST}:${PORT}"]
62+
CMD ["gunicorn", "config.wsgi:application", "--bind", "0.0.0.0:8000", "--workers", "4"]
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
from django.contrib import admin
2-
31
# Register your models here.
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
from django.db import models
2-
31
# Create your models here.

‎backend/apps/authentication/serializers.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from rest_framework import serializers
21
from django.contrib.auth.models import User
2+
from rest_framework import serializers
33

44

55
class RegisterSerializer(serializers.ModelSerializer):
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
from django.test import TestCase
2-
31
# Create your tests here.

‎backend/apps/authentication/urls.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from django.urls import path
2+
23
from . import views
34

45
urlpatterns = [

0 commit comments

Comments
 (0)