Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
1d52620
rename branch to main
Faaab84 Jan 4, 2026
e68d8c8
envoi
Faaab84 Jan 10, 2026
d7e31da
envoi
Faaab84 Jan 10, 2026
52dc143
envoi
Faaab84 Jan 10, 2026
7b61387
envoi
Faaab84 Jan 11, 2026
130080c
envoi
Faaab84 Jan 16, 2026
0e1c336
envoi
Faaab84 Jan 16, 2026
3cd733d
envoi
Faaab84 Jan 16, 2026
1290247
envoi
Faaab84 Jan 16, 2026
cec6032
envoi
Faaab84 Jan 16, 2026
d501584
envoi sql
Faaab84 Jan 17, 2026
634f98c
modify yml
Faaab84 Jan 17, 2026
2684219
modify yml
Faaab84 Jan 17, 2026
27e18cf
modify yml
Faaab84 Jan 17, 2026
590e730
modify yml
Faaab84 Jan 17, 2026
09cc0ac
setting
Faaab84 Jan 17, 2026
defa7e7
setting
Faaab84 Jan 17, 2026
531cf4b
setting
Faaab84 Jan 17, 2026
4fb4008
setting
Faaab84 Jan 17, 2026
17c5b60
setting
Faaab84 Jan 17, 2026
e6f5743
setting
Faaab84 Jan 17, 2026
d97f8a8
setting reath the doc
Faaab84 Jan 17, 2026
d6eba71
setting reath the doc_2
Faaab84 Jan 17, 2026
7b5375c
setting reath the doc_2
Faaab84 Jan 17, 2026
20c3997
setting reath the doc_4
Faaab84 Jan 17, 2026
4a123dd
setting reath the doc_5
Faaab84 Jan 17, 2026
620ca77
setting reath the doc_5
Faaab84 Jan 17, 2026
99493ec
setting reath the doc_5
Faaab84 Jan 17, 2026
e34c2b0
clean_folder
Faaab84 Jan 17, 2026
3f9da7a
clean_folder
Faaab84 Jan 17, 2026
e3d6532
setting reath the doc_5
Faaab84 Jan 17, 2026
77d88c7
modification test oral
Faaab84 Jan 17, 2026
bc1ebf4
oral blanc
Faaab84 Jan 18, 2026
7e27599
envoi
Faaab84 Jan 18, 2026
cdbd642
envoi
Faaab84 Jan 18, 2026
97bd154
envoi
Faaab84 Jan 18, 2026
9d06a5d
envoi
Faaab84 Jan 18, 2026
4323e4d
envoi
Faaab84 Jan 18, 2026
ec88c1d
envoi
Faaab84 Jan 19, 2026
72c7016
envoi
Faaab84 Jan 19, 2026
13d67ac
envoi
Faaab84 Jan 21, 2026
2d66965
envoi
Faaab84 Jan 21, 2026
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
17 changes: 17 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[flake8]
ignore = E501,E241,E111,E117,E402,F401,E303,E305,E722,E402

exclude =
.git,
__pycache__,
venv\,
.github\
.pytest_cache\
*.pyc,
.env\,
env\,
venv\,
.coverage,
templates\,
static\,

82 changes: 82 additions & 0 deletions .github/workflows/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: GitHub Actions Demo
run-name: ${{ github.actor }} CI for oc-lettings-site 🚀
on:
push:
pull_request:
branches:
- master
jobs:
test:
runs-on: ubuntu-latest
env:
SECRET_KEY: ${{ secrets.SECRET_KEY }}
SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
DEBUG: "False"
ALLOWED_HOSTS: "127.0.0.1,localhost,0.0.0.0,oc-lettings-site-latest-05t2.onrender.com"
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run Tests
run: |
pytest --cov --cov-fail-under=80

flake8:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run Flake8
run: |
flake8 --count

build:
needs: [test, flake8]
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master' && github.event_name == 'push'

steps:
- uses: actions/checkout@v4

- name: Log in to DockerHub
run: echo "${{ secrets.DOCKERHUB_TOKEN }}" | docker login -u "${{ secrets.DOCKERHUB_USERNAME }}" --password-stdin

- name: Build the Docker image
env:
SECRET_KEY: ${{ secrets.SECRET_KEY }}
run: |
docker build . --file Dockerfile \
--build-arg SECRET_KEY="${SECRET_KEY}" \
--tag ${{ secrets.DOCKERHUB_USERNAME }}/oc-lettings-site:${{ github.sha }} \
--tag ${{ secrets.DOCKERHUB_USERNAME }}/oc-lettings-site:latest

- name: Push image to DockerHub
run: |
docker push ${{ secrets.DOCKERHUB_USERNAME }}/oc-lettings-site:${{ github.sha }}
docker push ${{ secrets.DOCKERHUB_USERNAME }}/oc-lettings-site:latest

deploy:
needs: build
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master' && github.event_name == 'push'

steps:
- name: Deploy to Render
env:
deploy_url: ${{ secrets.RENDER_DEPLOY_HOOK_URL }}
run: |
curl "$deploy_url"
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
**/__pycache__
*.pyc
venv
.coverage
venv/
.env
staticfiles/
reports/
.pytest_cache/
Dockerfile1
Dockerfile1
docker-compose.yml.old
22 changes: 22 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Read the Docs configuration file
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

# Required
version: 2

# Set the OS, Python version, and other tools you might need
build:
os: ubuntu-24.04
tools:
python: "3.12"

# Build documentation in the "docs/" directory with Sphinx
sphinx:
configuration: docs/conf.py

# Optionally, but recommended,
# declare the Python requirements required to build your documentation
# See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
python:
install:
- requirements: requirements.txt
22 changes: 22 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM python:3.11-slim

ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1

WORKDIR /app

COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
ARG SECRET_KEY="temporary-insecure-key-for-local-build-only-do-not-use-in-production"
ENV SECRET_KEY=${SECRET_KEY}

COPY . .

RUN python manage.py makemigrations --noinput && \
python manage.py migrate --noinput

RUN python manage.py collectstatic --noinput

EXPOSE 8000

CMD ["gunicorn", "oc_lettings_site.wsgi:application", "--bind", "0.0.0.0:8000"]
160 changes: 156 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
## Résumé
# Site web d'Orange County Lettings

Site web d'Orange County Lettings
Ce repository contient le code source du site web d'Orange County Lettings, un site de location immobilière fictif développé dans le cadre du parcours "Développeur d'application - Python" d'OpenClassrooms.

## Développement local
Ce site web permet aux utilisateurs de consulter des profils de propriétaires et des annonces de locations immobilières. Il est construit avec le framework web Django et utilise une base de données SQLite pour stocker les informations.

## Architecture du projet

Le projet est structuré de la manière suivante :

- `oc_lettings_site/` : Dossier principal du projet Django. Contient les fichiers de configuration principaux du projet Django.
- `lettings/` : Application Django gérant les annonces de locations.
- `profiles/` : Application Django gérant les profils des propriétaires.
- `static/` : Contient les fichiers statiques (CSS, JavaScript, images).
- `templates/` : Contient les templates HTML utilisés pour rendre les pages web (accueil sur le site et pages 404 et 500, les autres templates sont intégrés dans les apps correspondantes).
- `oc-lettings-site.sqlite3` : Fichier de base de données SQLite.

## Documentation complète

La documentation détaillée du projet (architecture modulaire, schémas, description des apps, guides techniques, CI/CD, Sentry, etc.) est disponible sur ReadTheDocs :

https://python-oc-lettings-fr100.readthedocs.io/en/latest/installation.html#quick-start-local-development

### Prérequis

Expand Down Expand Up @@ -51,7 +68,7 @@ Dans le reste de la documentation sur le développement local, il est supposé q

- `cd /path/to/Python-OC-Lettings-FR`
- `source venv/bin/activate`
- `pytest`
- `pytest --cov --cov-fail-under=80`

#### Base de données

Expand All @@ -69,9 +86,144 @@ Dans le reste de la documentation sur le développement local, il est supposé q
- Aller sur `http://localhost:8000/admin`
- Connectez-vous avec l'utilisateur `admin`, mot de passe `Abc1234!`



### Configuration

Les variables d'environnement suivantes peuvent être configurées pour modifier le comportement du projet en local :
Créer un fichier .env avec les informations :

- `DEBUG=False` : active le mode debug de Django.
- `SECRET_KEY=<votre_clé_secrète>` : Clé secrète utilisée par Django. Par défaut, une clé de développement est utilisée.
- `SENTRY_DSN=<votre_dsn_sentry>` : DSN pour Sentry. Par défaut, aucune valeur n'est définie.
- `ALLOWED_HOSTS=<"">` :ALLOWED_HOSTS (127.0.0.1,localhost,0.0.0.0,oc-lettings-site-latest-05t2.onrender.com)

### Windows

Utilisation de PowerShell, comme ci-dessus sauf :

- Pour activer l'environnement virtuel, `.\venv\Scripts\Activate.ps1`
- Remplacer `which <my-command>` par `(Get-Command <my-command>).Path`


## Déploiement

### Vue d'ensemble

Le projet utilise un pipeline CI/CD automatisé via **GitHub Actions** pour déployer l'application en production sur **Render** :

1. **Validation du code** : Exécution automatique des tests (pytest avec couverture ≥ 80%) et vérification de la qualité du code (flake8)
2. **Containerisation** : Construction de l'image Docker et publication sur DockerHub
3. **Déploiement automatique** : Render détecte la nouvelle image et redémarre l'application
4. **Monitoring** : Sentry surveille les erreurs et performances en production

**Schéma du pipeline CI/CD** :

Le déploiement automatique se déclenche uniquement sur les pushs ou des merge vers la branche `master` après validation réussie des tests et du linting.

Pour chaque push sur des branches autres que `master`, une vérification des tests et du linting ainsi qu'un build Docker sont effectués et l'image est poussée sur DockerHub avec le tag du `sha du commit` + le tag `latest`, mais sans déploiement automatique.

---

### Prérequis

Pour effectuer un déploiement, les comptes et outils suivants sont nécessaires :

#### Comptes requis

- **GitHub** : Repository du projet avec GitHub Actions activé
- **DockerHub** : Registry pour stocker les images Docker
- **Render** : Plateforme d'hébergement pour l'application en production
- **Sentry** (optionnel) : Service de monitoring des erreurs

#### Conteneur local (pour tests manuels)

- Docker installé et configuré
- Accès SSH au repository GitHub
- CLI Docker connectée à DockerHub (pour pushs manuels d'images)

---

### Marche à suivre pour le déploiement initial

#### 1. Configuration DockerHub

1. Créer un compte sur [hub.docker.com](https://hub.docker.com)
2. Créer un repository public : `votre-username/oc-lettings-site`
3. Générer un Access Token :
- Aller dans **Account Settings** → **Security** → **New Access Token**
- Nom : `github-actions-token`
- Permissions : **Read, Write, Delete**
- Copier le token généré (il ne sera affiché qu'une seule fois)

#### 2. Configuration Render

1. Créer un compte sur [render.com](https://render.com)
2. Créer un nouveau **Web Service** :
- **Type** : Docker
- **Docker Image URL** : `votre-username/oc-lettings-site:latest`
- **Region** : Choisir la région la plus proche
- **Instance Type** : Free
3. Configurer les variables d'environnement dans Render :

`SECRET_KEY`=<générer une clé secrète Django ou modifier celle du projet pour la production>
`SENTRY_DSN`=<votre DSN Sentry>

4. Récupérer le **Deploy Hook URL** :
- Aller dans **Settings** → **Deploy Hook**
- Copier l'URL (format : `https://api.render.com/deploy/srv-xxxxx?key=yyyyy`)

#### 3. Configuration des GitHub Secrets

Ajouter les secrets suivants dans le repository GitHub (**Settings** → **Secrets and variables** → **Actions** → **New repository secret**) :

- `DOCKERHUB_TOKEN` : Token d'accès DockerHub
- `DOCKERHUB_USERNAME` : Nom d'utilisateur DockerHub
- `RENDER_DEPLOY_HOOK_URL` : URL du webhook Render

### Processus de déploiement

#### Déploiement automatique (recommandé)

Le déploiement est entièrement automatisé via GitHub Actions :

1. **Développer et tester localement** :
Au préalable, tirer une branche depuis `master`, effectuer les modifications, puis exécuter les tests et le linting localement :

```bash
pytest --cov --cov-fail-under=80
flake8
```

2. **Pousser sur la branche actuelle** :

```bash
git add .
git commit -m "Description des modifications"
git push
```

3. **Le pipeline s'exécute automatiquement** :

- ✅ Tests unitaires (pytest avec couverture 80%)
- ✅ Linting (flake8)

4. **Merge request sur la branche master** :

Une fois fait, il faut merger la branche dans `master` via une pull request sur GitHub.

5. **Le pipeline s'exécute automatiquement** :
Après le merge, le pipeline s'exécute automatiquement :

- ✅ Tests unitaires (pytest avec couverture 80%)
- ✅ Linting (flake8)
- ✅ Build de l'image Docker
- ✅ Push vers DockerHub (`latest` + tag avec SHA du commit)
- ✅ Déclenchement du déploiement Render via webhook

6. **Vérifier le déploiement** :
- Consulter les logs dans l'onglet **Actions** de GitHub
- Vérifier le statut sur le dashboard Render
- Accéder à l'application déployée : `https://votre-app.onrender.com`

---
25 changes: 25 additions & 0 deletions compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
version: "3.13"

services:
quality-check:
build: .
volumes:
- .:/app
working_dir: /app
entrypoint: ["/bin/sh", "-c"]
command: >
flake8 . --count --max-complexity=10 --max-line-length=88 --exclude=venv,migrations,__pycache__ &&
pytest --cov=. --cov-report=term-missing --cov-fail-under=80

web:
build: .
command: gunicorn oc_lettings_site.wsgi:application --bind 0.0.0.0:8000 --reload
ports:
- "8000:8000"
env_file:
- .env
volumes:
- .:/app
depends_on:
quality-check:
condition: service_completed_successfully
20 changes: 20 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = .
BUILDDIR = _build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/images/Pipeline_CICD.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading