Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
bc9eae5
Profiles migration done
Apr 14, 2025
8e2a0f5
lettings migrations done.
Apr 14, 2025
31ededa
Refactoring urls/views/templates.
Apr 14, 2025
df8cc09
Merge pull request #1 from mumz0/Improve-modular-architecture
mumz0 Apr 14, 2025
f2fe88b
Solved project issues and initialise Sentry.
Apr 20, 2025
aa2f836
Merge pull request #2 from mumz0/solve-project-issues
mumz0 Apr 20, 2025
cd179a2
Create ci.yml
mumz0 Apr 25, 2025
0dceaec
Merge pull request #3 from mumz0/mumz0-patch-1
mumz0 Apr 25, 2025
f9245d3
Indentation fixed.
Apr 25, 2025
fcdf67e
Merge pull request #4 from mumz0/fix/ci_yml
mumz0 Apr 25, 2025
557dd1d
Trigger CI
Apr 25, 2025
932b8db
Create django.yml
mumz0 Apr 25, 2025
e48ed0c
fix django.yml file.
Apr 25, 2025
501458d
fix django.yml file.
Apr 25, 2025
01f2975
Fix secret in django.yml file.
Apr 25, 2025
b9b71eb
Trigger CI
Apr 25, 2025
2194bac
Add secret for tests.
Apr 25, 2025
04817e1
fix yml.
Apr 25, 2025
e47a789
fix yml.
Apr 25, 2025
2a38a41
fix yml.
Apr 25, 2025
78495a0
Add dockerfile
Apr 25, 2025
313f8b2
Merge pull request #5 from mumz0/feature/add-dockerfile
mumz0 Apr 25, 2025
50c3a6f
Rename Dokerfile to Dockerfile
mumz0 Apr 25, 2025
6ce8412
Merge pull request #6 from mumz0/mumz0-patch-2
mumz0 Apr 25, 2025
8cad1f3
Update django.yml
mumz0 Apr 25, 2025
077afb7
Merge pull request #7 from mumz0/mumz0-patch-3
mumz0 Apr 25, 2025
f6cdfb3
Update Dockerfile
mumz0 Apr 25, 2025
e54887b
Merge pull request #8 from mumz0/mumz0-patch-4
mumz0 Apr 25, 2025
ceb0cee
Update django.yml
mumz0 Apr 25, 2025
f481db8
Merge pull request #9 from mumz0/mumz0-patch-5
mumz0 Apr 25, 2025
2f86221
Add connection and push to dockerhub.
Apr 26, 2025
a5be09d
Merge pull request #10 from mumz0/feature/push-dockerhub
mumz0 Apr 26, 2025
dfd3f36
setup for prod.
Apr 26, 2025
268e948
setup for prod.
Apr 26, 2025
43ec435
Merge pull request #11 from mumz0/feature/enable-render
mumz0 Apr 26, 2025
b8bfc52
test with new allowed host.
Apr 26, 2025
05973ad
Merge pull request #12 from mumz0/fix/allowed-hosts-issue
mumz0 Apr 26, 2025
7ac7954
Welcome message has been changed to verify if the render deployment s…
Apr 26, 2025
223301d
Welcome message back to origin.
Apr 26, 2025
9de5d4b
Add success condition and coverage execution when run tests.
Apr 26, 2025
9dfcfeb
Merge pull request #13 from mumz0/feature/improve-ci-workflows
mumz0 Apr 26, 2025
384c1f2
Coverage test updated in ci workflow.
Apr 26, 2025
204de9c
Merge pull request #14 from mumz0/fix/ci-workflow-test-coverage
mumz0 Apr 26, 2025
2547583
Update django.yml
mumz0 Apr 26, 2025
7c8138c
init readthedocs(in progress)
Apr 27, 2025
47cac54
trigger CI
Apr 27, 2025
17a54fe
fix django.yml.
Apr 27, 2025
66b8799
modif html
Apr 27, 2025
d569d1f
Update README.
May 1, 2025
a02c7c6
Implementation of readthedocs.
May 2, 2025
d98a258
Merge pull request #16 from mumz0/feature/init-readthedocs
mumz0 May 2, 2025
0fc1e10
Merge branch 'master' into mumz0-patch-6
mumz0 May 2, 2025
4ae9448
Merge pull request #15 from mumz0/mumz0-patch-6
mumz0 May 2, 2025
897100d
fix readthedocs file
May 2, 2025
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
Binary file added .coverage
Binary file not shown.
15 changes: 15 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[run]
source =
lettings
profiles
oc_lettings_site

omit =
*/tests/*
*/tests.py
*/migrations/*
*/apps.py
manage.py
oc_lettings_site/wsgi.py
oc_lettings_site/asgi.py
*/__init__.py
70 changes: 70 additions & 0 deletions .github/workflows/django.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: Django CI

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:
build:
runs-on: ubuntu-latest
strategy:
max-parallel: 4
matrix:
python-version: [3.12.3]
env:
SECRET_KEY: ${{ secrets.SECRET_KEY }}
SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
DJANGO_SETTINGS_MODULE: oc_lettings_site.settings

steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}

- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt

- name: Lint with flake8
if: success()
run: flake8

- name: Run tests with coverage
if: success()
run: |
coverage run -m pytest
coverage html
coverage report --fail-under=80

- name: Collect static files
if: success()
run: python manage.py collectstatic --noinput

- name: Build Docker image
if: success()
run: >-
docker build
--build-arg SECRET_KEY=${{ secrets.SECRET_KEY }}
--build-arg SENTRY_DSN=${{ secrets.SENTRY_DSN }}
-t oc-lettings-site .

- name: Login to Docker Hub
if: success()
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Tag Docker image
if: success()
run: docker tag oc-lettings-site ${{ secrets.DOCKERHUB_USERNAME }}/oc-lettings-site:latest

- name: Push Docker image
if: success()
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/oc-lettings-site:latest
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
**/__pycache__
*.pyc
venv
.env
htmlcov
pytest_cache
.coverage
17 changes: 17 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Read the Docs configuration file for Sphinx projects
version: 2

build:
os: ubuntu-24.04
tools:
python: "3.12"

sphinx:
configuration: docs/conf.py

formats:
- pdf

python:
install:
- requirements: docs/requirements.txt
21 changes: 21 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM python:3.12.3-slim

WORKDIR /app

COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

COPY . .

ENV DJANGO_SETTINGS_MODULE=oc_lettings_site.settings
ENV PYTHONUNBUFFERED=1

ARG SECRET_KEY
ARG SENTRY_DSN

ENV SECRET_KEY=${SECRET_KEY}
ENV SENTRY_DSN=${SENTRY_DSN}

RUN python manage.py collectstatic --noinput

CMD ["gunicorn", "oc_lettings_site.wsgi:application", "--bind", "0.0.0.0:8000"]
128 changes: 96 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,77 +1,141 @@
## Résumé
## Summary

Site web d'Orange County Lettings
Orange County Lettings website

## Développement local
## Local Development

### Prérequis
### Prerequisites

- Compte GitHub avec accès en lecture à ce repository
- GitHub account with read access to this repository
- Git CLI
- SQLite3 CLI
- Interpréteur Python, version 3.6 ou supérieure
- Python interpreter, version 3.6 or higher

Dans le reste de la documentation sur le développement local, il est supposé que la commande `python` de votre OS shell exécute l'interpréteur Python ci-dessus (à moins qu'un environnement virtuel ne soit activé).
In the rest of the local development documentation, it is assumed that the `python` command in your OS shell runs the above Python interpreter (unless a virtual environment is activated).

### macOS / Linux

#### Cloner le repository
#### Clone the repository

- `cd /path/to/put/project/in`
- `git clone https://github.com/OpenClassrooms-Student-Center/Python-OC-Lettings-FR.git`

#### Créer l'environnement virtuel
#### Create the virtual environment

- `cd /path/to/Python-OC-Lettings-FR`
- `python -m venv venv`
- `apt-get install python3-venv` (Si l'étape précédente comporte des erreurs avec un paquet non trouvé sur Ubuntu)
- Activer l'environnement `source venv/bin/activate`
- Confirmer que la commande `python` exécute l'interpréteur Python dans l'environnement virtuel
- `apt-get install python3-venv` (If the previous step gives errors with a package not found on Ubuntu)
- Activate the environment `source venv/bin/activate`
- Confirm that the `python` command runs the Python interpreter in the virtual environment
`which python`
- Confirmer que la version de l'interpréteur Python est la version 3.6 ou supérieure `python --version`
- Confirmer que la commande `pip` exécute l'exécutable pip dans l'environnement virtuel, `which pip`
- Pour désactiver l'environnement, `deactivate`
- Confirm that the Python interpreter version is 3.6 or higher `python --version`
- Confirm that the `pip` command runs the pip executable in the virtual environment, `which pip`
- To deactivate the environment, `deactivate`

#### Exécuter le site
#### Run the site

- `cd /path/to/Python-OC-Lettings-FR`
- `source venv/bin/activate`
- `pip install --requirement requirements.txt`
- `python manage.py runserver`
- Aller sur `http://localhost:8000` dans un navigateur.
- Confirmer que le site fonctionne et qu'il est possible de naviguer (vous devriez voir plusieurs profils et locations).
- Go to `http://localhost:8000` in a browser.
- Confirm that the site works and it is possible to navigate (you should see several profiles and lettings).

#### Linting

- `cd /path/to/Python-OC-Lettings-FR`
- `source venv/bin/activate`
- `flake8`

#### Tests unitaires
#### Unit tests

- `cd /path/to/Python-OC-Lettings-FR`
- `source venv/bin/activate`
- `pytest`

#### Base de données
#### Database

- `cd /path/to/Python-OC-Lettings-FR`
- Ouvrir une session shell `sqlite3`
- Se connecter à la base de données `.open oc-lettings-site.sqlite3`
- Afficher les tables dans la base de données `.tables`
- Afficher les colonnes dans le tableau des profils, `pragma table_info(Python-OC-Lettings-FR_profile);`
- Lancer une requête sur la table des profils, `select user_id, favorite_city from
- Open a shell session `sqlite3`
- Connect to the database `.open oc-lettings-site.sqlite3`
- Display the tables in the database `.tables`
- Display the columns in the profiles table, `pragma table_info(Python-OC-Lettings-FR_profile);`
- Run a query on the profiles table, `select user_id, favorite_city from
Python-OC-Lettings-FR_profile where favorite_city like 'B%';`
- `.quit` pour quitter
- `.quit` to exit

#### Panel d'administration
#### Admin panel

- Aller sur `http://localhost:8000/admin`
- Connectez-vous avec l'utilisateur `admin`, mot de passe `Abc1234!`
- Go to `http://localhost:8000/admin`
- Log in with user `admin`, password `Abc1234!`

### Windows

Utilisation de PowerShell, comme ci-dessus sauf :
Using PowerShell, as above except:

- Pour activer l'environnement virtuel, `.\venv\Scripts\Activate.ps1`
- Remplacer `which <my-command>` par `(Get-Command <my-command>).Path`
- To activate the virtual environment, `.\venv\Scripts\Activate.ps1`
- Replace `which <my-command>` with `(Get-Command <my-command>).Path`

## Deployment

### Overview of the deployment process

The application deployment is done via a GitHub Actions CI/CD pipeline that:
1. Runs tests and coverage
2. Builds a Docker image
3. Publishes the image to Docker Hub when tests succeed
4. Automatically triggers a deployment on Render using a webhook

This architecture allows:
- Verifying code quality before deployment
- Maintaining versioned Docker images
- Deploying automatically without manual intervention

### Prerequisites

- A Docker Hub account
- A Render account
- A GitHub account with configured secrets:
- `DOCKERHUB_USERNAME`: Docker Hub username
- `DOCKERHUB_TOKEN`: Docker Hub token
- `SECRET_KEY`: Django secret key
- `SENTRY_DSN`: Sentry DSN key

### Deployment Steps

#### Initial setup (to be done once)

1. Configure Docker Hub:
- Create an account on [Docker Hub](https://hub.docker.com/) if you don't have one
- Create a new repository for the application
- Generate an access token for GitHub Actions

2. Create an account on [Render](https://render.com/) if you don't already have one

3. From the Render dashboard, create a new Web Service:
- Click on "New" then "Web Service"
- Select "Existing image"
- Connect your Docker Hub account
- Specify the image: `docker.io/your-username/oc-lettings-site:latest`

4. Configure environment variables on Render:
- In your service settings, go to "Environment"
- Add the following variables:
- `SECRET_KEY`: your Django secret key
- `SENTRY_DSN`: Sentry DSN key

5. Configure the Render webhook for automatic deployment:
- In your Render service settings, go to "Deploys" then "Deploy Hooks"
- Create a new hook and copy the generated URL
- Go to Docker Hub, in your repository settings
- Add a new webhook pointing to the Render URL

6. Configure secrets in GitHub:
- Go to your GitHub repository → Settings → Secrets → Actions
- Add the secrets mentioned in the prerequisites

#### Automatic deployment flow

1. When you push code to the main branch:
```bash
git push origin master
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 = source
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)
Binary file added docs/build/doctrees/database.doctree
Binary file not shown.
Binary file added docs/build/doctrees/deployment.doctree
Binary file not shown.
Binary file added docs/build/doctrees/description.doctree
Binary file not shown.
Binary file added docs/build/doctrees/environment.pickle
Binary file not shown.
Binary file added docs/build/doctrees/index.doctree
Binary file not shown.
Binary file added docs/build/doctrees/installation.doctree
Binary file not shown.
Binary file added docs/build/doctrees/interfaces.doctree
Binary file not shown.
Binary file added docs/build/doctrees/quickstart.doctree
Binary file not shown.
Binary file added docs/build/doctrees/technologies.doctree
Binary file not shown.
4 changes: 4 additions & 0 deletions docs/build/html/.buildinfo
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Sphinx build info version 1
# This file records the configuration used when building these files. When it is not found, a full rebuild will be done.
config: e26cb8a6f800060a2b2234eb94a837cf
tags: 645f666f9bcd5a90fca523b33c5a78b7
Loading