Installation¶
To install the API you need a Python 3.x installed also venv module and pip.
Here will be covered two types of installation for debugging and for production.
Mutual Steps¶
Clone the repository with the command
Rename.env.example
to .env
In linux
Enter all needed environment variables in .env
file.
PAGINATION_PAGE_SIZE
is used for pagination used in the API certain endpoint.DJANGO_SECRET
you can generate the secret online -> link
or with the following command if you have installed django on the machineDOMAIN_NAME_NGINX
the domain which will serve the apiX_AUTH_HEADER
also you can generate random UUID online that will be used for authentication
for the read only endpoint. Example header261ec18d-0e81-4073-8d9e-b34a7a1e5e06
(Don`t use it this is for demo purpose)CORS_ALLOWED_HOSTS
are the front end domain namesOPENAI_API_KEY
is the API KEY from OpenAI for the scraping recipe functionalityOPENAI_MODEL
is the default model at this stage thegpt-4o-mini
is most cost-efficient and is working ok for the scraping task
Scrape functionality dependencies
The API use playwright python package to open the scrape url recipe link. The docker images in Docker Hub include the dependancy there no need of manaul installation.
Installing locally (Debug mode)¶
You can create a virtual environment and click of the API. Note replace the 3.x with actual Python version
Make the needed migrations so Django can create sqlite database file with tables.
$ cd forkapi
$ python manage.py makemigrations authentication
$ python manage.py makemigrations recipe
$ python manage.py migrate
At this point everything should be ok, and you can start the server.
localhost:8000
.
In this mode you can use it locally if in debug mode which you can change in /forkapi/settings.py
file line 27
Raspberry Pi¶
Info
- For Raspberry Pi with Raspbian OS make sure to uncomment the packages in the main Dockerfile in line
16
and replace the method frompull
from registry tobuild
from Dockerfile located at the root folder. This should be happen in thedocker-compose.yml
file line25
. - If you pull from Docker hub make sure to change the image in compose with
mikebgrep/forkapi:arm64
this image is tested for Raspberry Pi with Ubuntu server.
Installing in Docker container (Production SSL)¶
To installing in Docker container follow the steps bellow.
- Fist step is to clone the repo. The needed files are in
nginx
folder,.env
file anddocker-compose.yml
file. - Next step is setting up the
fullchain.pem
andprivkey.pem
files needed for the ssl settings innginx
. - After you obtain ssl certificates for your domain you need to copy them in the
nginx/ssl
folder. - Then add environment variable (if you didn't add it already) in
.env
file forDOMAIN_NAME_NGINX
that should be used with your actual domain name in thenginx/forkapi-ssl.nginx.template
configuration file. - Next uncomment the commented lines
8
,12
and21
in thedocker-compose.yml
and comment lines7
and22
. -
That all you need to run the
docker compose up
command and the API will be deployed on the server instance or locally on your machine. -
Access the admin dashboard at
your-domain:80
oryour-domain:443
Info
I will not include steps for setting the domain name servers on this as you can follow the official documentation on your server or the Raspberry Pi documentation.
Installing in Docker container (Production No SSL)¶
- Fist step is to clone the repo. The needed files are in
nginx
folder,.env
file anddocker-compose.yml
file. - Add environment variable (if you didn't add it already) in
.env
file forDOMAIN_NAME_NGINX
that should be used with your actual domain name in thenginx/forkapi.nginx.template
configuration file. - That all you need to run the
docker compose up
command and the API will be deployed on the server instance or locally on your machine.
Note
This method is the prefered choice if your server already provide ssl connection by default as Digital ocean do for their apps.
Follow next step to check how you can and must be made your first request.