Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
47a642d
(feat) initialized project by following and updating the Readme file,…
AurelienAllenic May 30, 2024
d3f585e
(feat) added two new apps : lettings and profiles, added models to th…
AurelienAllenic May 31, 2024
72a1ae4
(feat) added urls, views, templates and removed everything useless
AurelienAllenic May 31, 2024
1d57c25
Merge pull request #1 from AurelienAllenic/first_step
AurelienAllenic May 31, 2024
e8f9567
(fix) corrected indentation with flake8, added comments and docString…
AurelienAllenic May 31, 2024
a4cc2ba
(feat) added 404 and 500 pages with one url to test the 500 and the t…
AurelienAllenic May 31, 2024
8b08c5d
(feat) added unitary test for 404 and 500 and for each page, still fu…
AurelienAllenic Jun 3, 2024
f371325
(feat) added unitary tests in each test file of app folders, added fu…
AurelienAllenic Jun 3, 2024
665a08d
Merge pull request #2 from AurelienAllenic/second_step
AurelienAllenic Jun 3, 2024
048e2cd
(feat) added sentry and its config into settings, its debug route int…
AurelienAllenic Jun 3, 2024
ce79aab
Merge pull request #3 from AurelienAllenic/third_step
AurelienAllenic Jun 3, 2024
399758d
Create main.yml
AurelienAllenic Jun 4, 2024
ebb5ea4
testing ci cd deployment
AurelienAllenic Jun 6, 2024
1edbae2
(fix) changed yml file to match nodejs versions
AurelienAllenic Jun 6, 2024
299a0f3
(indent) corrected files for flake8 linting
AurelienAllenic Jun 6, 2024
73de166
(fix) corrected , issue in settings
AurelienAllenic Jun 6, 2024
72f49ec
(feat) excluded packages in env folder from linting
AurelienAllenic Jun 6, 2024
6b870ab
(feat) excluded packages in env folder from linting
AurelienAllenic Jun 6, 2024
d5724b9
(feat) updated requirtements to match my modules
AurelienAllenic Jun 6, 2024
edd2f11
(fix) removed useless constrait in config
AurelienAllenic Jun 6, 2024
6499471
(fix) added pytest-cov so that we can test it inside the ci/cd pipeline
AurelienAllenic Jun 6, 2024
70029c4
(feat) added Dockerfile and added gunicorn to requirements
AurelienAllenic Jun 6, 2024
63cb3ac
(fix) added username before calling image for docker
AurelienAllenic Jun 6, 2024
8b6a463
(fix) added username before calling image for docker
AurelienAllenic Jun 6, 2024
2a2eca7
(feat) added deployment part
AurelienAllenic Jun 6, 2024
a5d531b
(feat) added line for collecting static inside yml file and reception…
AurelienAllenic Jun 7, 2024
fec8ea6
(feat) added doc with read the sphynx
AurelienAllenic Jun 7, 2024
8ea47a9
(feat) added readthedocs
AurelienAllenic Jun 7, 2024
be3f360
(fix) corected error on doc
AurelienAllenic Jun 13, 2024
edefc34
(fix) changed main to master inside yml file
AurelienAllenic Jun 13, 2024
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.
58 changes: 58 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Django CI/CD

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

jobs:
build-and-test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.8'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Collect static files
run: python manage.py collectstatic --noinput
env:
DJANGO_SETTINGS_MODULE: oc_lettings_site.settings
- name: Run linting
run: flake8 .

- name: Run tests with coverage
run: |
pytest --cov=./ --cov-report=term-missing:skip-covered --cov-fail-under=80

build-and-push-docker:
needs: build-and-test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Build Docker image
run: docker build . -t ${{ secrets.DOCKER_USERNAME }}/myapp:${{ github.sha }}

- name: Log in to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Push Docker image to Docker Hub
run: docker push ${{ secrets.DOCKER_USERNAME }}/myapp:${{ github.sha }}

- name: Output Docker run command
run: "echo 'Run the following command to pull and run the Docker image locally: docker run -p 8000:8000 myapp:${{ github.sha }}'"
- name: Deploy to Render
run: |
curl -X POST -d '' "${{ secrets.RENDER_DEPLOY_HOOK }}"
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
**/__pycache__
*.pyc
venv
env
.env
15 changes: 15 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# .readthedocs.yaml
version: 2

build:
os: ubuntu-22.04
tools:
python: "3.9"

sphinx:
configuration: doc/conf.py


python:
install:
- requirements: requirements.txt
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,13 @@ Dans le reste de la documentation sur le développement local, il est supposé q
- 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);`
Faux
Afficher les colonnes dans le tableau des profils, `pragma table_info(oc_lettings_site_profile);`
- Lancer une requête sur la table des profils, `select user_id, favorite_city from
Python-OC-Lettings-FR_profile where favorite_city like 'B%';`
Faux
Lancer une requête sur la table des profils, `SELECT user_id, favorite_city FROM oc_lettings_site_profile WHERE favorite_city LIKE 'B%';`

- `.quit` pour quitter

#### Panel d'administration
Expand Down
20 changes: 20 additions & 0 deletions doc/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)
Binary file added doc/_build/doctrees/environment.pickle
Binary file not shown.
Binary file added doc/_build/doctrees/github_actions.doctree
Binary file not shown.
Binary file added doc/_build/doctrees/index.doctree
Binary file not shown.
Binary file added doc/_build/doctrees/local_use.doctree
Binary file not shown.
Binary file added doc/_build/doctrees/presentation.doctree
Binary file not shown.
Binary file added doc/_build/doctrees/requirements.doctree
Binary file not shown.
Binary file added doc/_build/doctrees/sentry.doctree
Binary file not shown.
Binary file added doc/_build/doctrees/structure.doctree
Binary file not shown.
4 changes: 4 additions & 0 deletions doc/_build/html/.buildinfo
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: e5310faf057c669c38714cf216a1ddfb
tags: 645f666f9bcd5a90fca523b33c5a78b7
80 changes: 80 additions & 0 deletions doc/_build/html/_sources/github_actions.rst.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
Github Actions
===========

YML file steps
--------------------

**Step 1: Install Python, packages from requirements.txt and
link static assets to our project**

.. code-block:: bash

name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Collect static files
run: python manage.py collectstatic --noinput
env:
DJANGO_SETTINGS_MODULE: oc_lettings_site.settings

**Step 2: Linting**

.. code-block:: bash

- name: Run linting
run: flake8 .

**Step 3: Tests with coverage **

.. code-block:: bash

- name: Run tests with coverage
run: |
pytest --cov=./ --cov-report=term-missing:skip-covered --cov-fail-under=80

**Step 4: Create Secrets for your github actions and use them**
1. Inside yout project, on Github, go to settings, secrets and variables, click on action and on new repository secret,
add your docker username and your docker password like this:

.. code-block:: bash

DOCKER_USERNAME="your_docker_username"
DOCKER_PASSWORD="your_docker_password"

2. This is what we use inside the yml file to log and perform operations with docker:
.. code-block:: bash
- name: Build Docker image
run: docker build . -t ${{ secrets.DOCKER_USERNAME }}/myapp:${{ github.sha }}

- name: Log in to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

**Step 5: Pushing the image to docker hub**

.. code-block:: bash

- name: Push Docker image to Docker Hub
run: docker push ${{ secrets.DOCKER_USERNAME }}/myapp:${{ github.sha }}

**Step 6: Deploy the image to render**
1. Get your render deploy hook
- Go to Render, got to your dashboard
- Create a new web service
- In the settings of your service, link your reposiroty to it, add this start command :
.. code-block:: bash
python manage.py runserver 0.0.0.0:$PORT
-Copy the Deploy hook
2. Add the secret variable inside github actions as we previously see as :

.. code-block:: bash
RENDER_DEPLOY_HOOK="your_render_deploy_hook"

3. This is what we use inside the yml file to link this project to your render web service :
.. code-block:: bash
- name: Deploy to Render
run: |
curl -X POST -d '' "${{ secrets.RENDER_DEPLOY_HOOK }}"
27 changes: 27 additions & 0 deletions doc/_build/html/_sources/index.rst.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
.. oc_lettings documentation master file, created by
sphinx-quickstart on Fri Jun 7 14:32:43 2024.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.

Welcome to OC Lettings's Documentation!
======================================

This documentation covers the setup, usage, and other details of the OC Lettings application.

.. toctree::
:maxdepth: 2
:caption: Contents:

presentation
structure
requirements
local_use
sentry_dsngithub_actions


Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
71 changes: 71 additions & 0 deletions doc/_build/html/_sources/local_use.rst.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
Local Usage
===========

Launching the Server
--------------------

**Step 1: Activate the environment**

.. code-block:: bash

# On Windows
.\env\Scripts\activate

# On Unix or MacOS
source env/bin/activate

**Step 2: Launch the server**

.. code-block:: bash

python manage.py runserver

Launching Tests
---------------

**Step 1: Activate the environment**

.. code-block:: bash

# On Windows
.\env\Scripts\activate

# On Unix or MacOS
source env/bin/activate

**Step 2: Navigate to the application**

.. code-block:: bash

cd ./lettings || cd ./profiles || cd ./oc_lettings_site

**Step 3: Execute the tests**

.. code-block:: bash

pytest tests.py

**To test all files at once, without leaving the root directory:**

.. code-block:: bash

pytest --cov

Launching Linting
-----------------

**Step 1: Activate the environment**

.. code-block:: bash

# On Windows
.\env\Scripts\activate

# On Unix or MacOS
source env/bin/activate

**Step 2: Execute flake8**

.. code-block:: bash

flake8
31 changes: 31 additions & 0 deletions doc/_build/html/_sources/presentation.rst.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Presentation
========================================

Oc Lettings
------------

OC Lettings is a django app displaying lettings and profiles to the user and an admin part.
The project was to refactor the app from oc_lettings_site only to oc_lettings_site, lettings and profile apps.
The project is tested thanks to all tests.py files and it is deployed to render url when git pull or push on main branch
and github actions validate the project.

Composition
------

1. **Django**:
- This is a Django project.

2. **Flake8**:
- Flake8 was used for linting.

3. **Sentry**:
- Sentry provides a log system to avoid error and capture exceptions.

4. **Github Actions**:
- Github Actions allows us to test the projec, buld and push the image to docker.

5. **Docker**:
- Docker is used to build and push an image to render and allow our ci/cd pipeline to work efficiently.

6. **Render**:
- Render get our image and deploy it on a url.
46 changes: 46 additions & 0 deletions doc/_build/html/_sources/requirements.rst.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
Requirements
===============================================

Environment Setup
-----------------

After cloning or forking the repository, you need to set up a virtual environment and install the required packages. Follow these steps:

1. **Create a virtual environment**:

Depending on your operating system and preference, you can create a virtual environment using `venv` (included in Python 3.3 and later) or any other tool like `virtualenv`.

For `venv`, run:

.. code-block:: bash

python -m venv env

Activate the environment:

.. code-block:: bash

# On Windows
.\env\Scripts\activate

# On Unix or MacOS
source env/bin/activate

2. **Install the required packages**:

Install all dependencies listed in the `requirements.txt` file using pip:

.. code-block:: bash

pip install -r requirements.txt

This setup will ensure that all necessary libraries and packages are installed in your virtual environment, keeping your project's dependencies isolated from other Python projects.

Secret Variables
-----------------

Create a .env file at root, and add these lines with the proper infos :
.. code-block:: bash
DOCKER_USERNAME="your_docker_username"
DOCKER_PASSWORD="your_docker_password"
SENTRY_DSN="your_sentry_dsn"
11 changes: 11 additions & 0 deletions doc/_build/html/_sources/sentry.rst.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Sentry
========================================

Sentry is used in the views to check for errors with capture_exceptions
and tells us about the issue with capture_messages

It is configured inside our settings :
.. code-block:: bash
sentry_dsn = os.getenv('SENTRY_DSN')

Sentry_DSN is your secret variable in .env file !
Loading