Application Deployment
Used technologies:
CircleCI as CI/CD tool
Docker and DockerHub as containerization tool
Gunicorn as WSGI HTTP server
Render as web hosting provider
CI/CD Workflow
There are 3 jobs in the workflow, with the following actions:
to run the testsuite
to build the docker image and to push it to DockerHub
to deploy the new image on Render
The testing job is run on every (remote pushed) commit, while the other two are run only on the ones on the master branch.
The presented order has its importance: the docker job is run only if the tests are successful. As the Render deployment rely on the docker image, it is run only if the image is built successfully.
The workflow is defined in the .circleci/config.yml file.
Docker
The docker image is built using the Dockerfile in the root of the project.
The application image:
is based on a small Linux image with a Python runtime (
python:3.11-slim),installs the project dependencies and the project itself (using
Poetry),exposes the port 8000,
defines the entrypoint script to run the migrations, the collectstatic command and the server itself using
gunicorn.
The entrypoint script is defined in the docker-entrypoint.sh file, in the root of the project.
The docker image is available on DockerHub at the following address: lettings-auto-build.
Images are tagged with their git commit hash, and the latest build is also tagged latest.
To run the application locally, you can use the following command:
docker run --env-file .env nannakin/lettings-auto-build:latest
Then, you can access the application at http://0.0.0.0:8000.
Note
In order to push images from the CICD pipeline, to DockerHub, the DOCKERHUB_USERNAME and DOCKERHUB_TOKEN environment variables must be set in the CircleCI project settings.
Render
The project Render web service is parametrized to use the nannakin/lettings-auto-build:latest docker image.
To trigger manually a new deployment from the command line (without going to the dashboard):
curl -X GET $RENDER_DEPLOY_HOOK_URL
Where RENDER_DEPLOY_HOOK_URL is the environment variable containing the project deploy hook URL (example: https://api.render.com/deploy/secrethookurl), generated by Render.
The hosted webapp is available here: https://holidays-homes.onrender.com/ .