![Logo](/KDerec/OC-Lettings/raw/master/images/logo.png)
This student project is the #10 of my training.
You can follow the previous one here.
Table of Contents
- Apply a modular architecture in a Python application
- Manage code production using the CI/CD methodology with CircleCI
- Refactor an application to reduce technical debt
- Deploy an application using Heroku
- Implement a code control system using Sentry
I’m a junior developer at Orange County Lettings, a startup in the real estate rental industry and the company has decided to take action to improve them site and its deployment.
For that, Dominique, my technical director, asked me :
“Here are the areas of the site and deployment that we would like you to improve or add:
- Reduction of various technical liabilities on the project
- Redesign of the modular architecture
- Added a CI/CD pipeline using CircleCI and Heroku
- Application monitoring and error tracking via Sentry.
Briefly show the site running on localhost, and explain the problems encountered when setting up the local development environment.
After presenting the link to the Heroku deployment deliverable, delete the Heroku application, create a new one, and redeploy the site by running the CI/CD pipeline in CircleCI.
Once the CI/CD pipeline is complete, resubmit the site via the link to the new Heroku deployment.
Run the Docker command that pulls the image from Docker Hub and manages the site locally.
There are two sections, one to get a local copy and another to deploy the application on a Heroku server.
To get a local copy up and running follow these simple example steps.
- GitHub account with read access to this repository
- Git CLI
- SQLite3 CLI
- Python interpreter, version 3.6 or higher
In the rest of the local development documentation, it is assumed that the python
command in your shell OS runs the above Python interpreter (unless a virtual environment is enabled).
- Clone the project in desired directory ;
git clone https://github.com/KDerec/OC-Lettings.git
- Change directory to project folder ;
cd path/to/OC-Lettings
- Create a virtual environnement (More detail to Creating a virtual environment) ;
- For Windows :
python -m venv venv
- For macOS / Linux :
python3 -m venv venv
- For Windows :
- Activate the virtual environment ;
- For Windows :
.\venv\Scripts\activate
- For macOS / Linux :
source venv/bin/activate
- For Windows :
- Install package of requirements.txt ;
pip install -r requirements.txt
- Create a
.env
file in the root project directory with a SECRET_KEY for Django, for example :# in .env SECRET_KEY = "Yf7S^Z}FShCCm+ZdSb51vA)rr<4eFi"
- Run the server ;
python manage.py runserver
- Now the application is accessible in your browser at http://localhost:8000 🎉.
Adapt the virtual environment activation to your system.
cd path/to/OC-Lettings
source venv/bin/activate
flake8
Adapt the virtual environment activation to your system.
cd path/to/OC-Lettings
source venv/bin/activate
pytest
- Open sqlite3 command-line program (doc here) in your
path/to/OC-Lettings
; - 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(profiles_profile);
- Run a query on the profiles table,
select user_id, favorite_city from profiles_profile where favorite_city like 'B%';
.quit
to exit.
- Go to
http://localhost:8000/admin
; - Log in with user
admin
, passwordAbc1234!
.
The application is deployed on Heroku using CircleCi pipeline, Docker container and Sentry for monitoring and error tracking.
When a developer executes a git push
command to the master
branch of the project, it's run a pipeline on CircleCi and this pipeline run a set of processess consisting of building and testing stage before deployment.
If testing (pytest + flake8) and building (docker image) are successful, docker image is pushed to DockerHub and deploy to Heroku.
The details of the pipeline configuration are available in the config.yml file of the .circleci folder and the the instructions to build docker images are in Dockerfile.
![deployment-schema](/KDerec/OC-Lettings/raw/master/images/illustration.jpg)
Only modification to master
branch execute the push of the Docker image to DockerHub and the Heroku deployment.
Changes to other branches will only trigger testing and linting.
- GitHub account with read access to this repository
- DockerHub Account
- Accept to login to CircleCI with your GitHub account
- Heroku Account
- Heroku CLI installed
- Sentry Account
- Fork this repo (How to fork a repo ? Very clear answer) ;
- Follow the installation guide to setup the project ;
- Logged with your Docker account to hub.docker.com, create a new public repository with
oc-lettings
name (it's important); - Connected to Heroku dashboard, create a new app ;
- Open a new terminal, enter the command below and follow the instruction to login (more detail about Heroku CLI authentification):
heroku login
- Retrieve your API token by entering the command below and keep this token (for example :
c4cd94da15ea0544802c2cfd5ec4ead324327430
):heroku auth:token
- Connected to Sentry, create a new projet and retrieve your DSN key ;
- Login to CircleCI with your GitHub account ;
- Set up your project by selecting your
OC-Lettings
repository and theconfig.yml
file frommaster
branch ;
- You will see your project and it's status will be
Failed
, but it's normal, because we haven't configured the project yet ; - To do that, go to
Project Settings
;
- Add environment variables below ;
Name | Value |
---|---|
DOCKER_PASSWORD | Your docker password account |
DOCKER_USER | Your docker username account |
HEROKU_API_KEY | The token you generated before with the heroku auth:token command |
HEROKU_APP_NAME | The name of the app you created in Heroku |
SECRET_KEY | Your Django secret key |
SENTRY_DSN | Your DSN key from Sentry |
13. Go back to the pipelines of the project, rerun the workflow and wait until Success
;
14. Go to heroku dashboard, open your app and congratulation, it's deploy ! 🎉
Distributed under the MIT License. See LICENSE
for more information.
Kévin Dérécusson 👇🏻
Email : kevin.derecusson@outlook.fr
LinkedIn : https://www.linkedin.com/in/kevin-derecusson/
This student project is the 10# of my training.
You can follow the previous one here.