Week 13 / 2023
Git
- First time, Run
pre-commit
install to install the hooks into your local Git repository. - When using the Black hook in pre-commit, the black hook ran successfully and reformatted the
[file-name].py
file. However, it failed the pre-commit check because the file was modified by the hook. the commit will fail, and the file will be left in a modified state, So you need to add the file to the staging area and commit again. Now the commit will succeed.
Frappe Infrastructure
common_site_config.json
stores configuration shared by your bench. This file is automatically generated and managed by the Bench CLI.- Locally, using docker, nginx, fastapi, run 3 fastapi servers each in docker container, with nginx container, all in the same network, add custom domain for each fastapi server
encryption_key
: Key used to encrypt Passwords. This password is created automatically on a fresh site. Upon site restore, this key will have to be restored as well to be able to use existing passwords.
Multi-tenancy
- Locally, using docker, nginx, fastapi, run 3 fastapi servers each in docker container, with nginx container, all in the same network, add custom domain for each fastapi server
-
Create a Docker network to connect all the containers together:
docker network create my-network
-
Create the three Docker containers for the FastAPI servers. You can use the following command for each container, replacing
my-fastapi-app-X
with a unique name for each container:docker run -d --name my-fastapi-app-X --network my-network my-fastapi-image-X
Note that each container should be built from a Docker image that contains a unique FastAPI application. Replace my-fastapi-image-X with the appropriate image name for each container.
-
Create a Docker container for Nginx, which will act as a reverse proxy to route incoming requests to the appropriate FastAPI container. Use the following command to create the Nginx container:
docker run -d --name my-nginx --network my-network -p 80:80 -v /path/to/nginx.conf:/etc/nginx/nginx.conf nginx
This command creates a container named
my-nginx
and maps its port80
to the host machine's port80
. It also mounts a customnginx.conf
file from the host machine to the container's/etc/nginx
directory. You can create this file and configure Nginx to route requests to each of the three FastAPI containers. -
Configure Nginx to route requests to each FastAPI container based on a custom domain. You can add the following server blocks to the nginx.conf file:
server { listen 80; server_name my-domain-1.com; location / { proxy_pass http://my-fastapi-app-1:80; } } server { listen 80; server_name my-domain-2.com; location / { proxy_pass http://my-fastapi-app-2:80; } } server { listen 80; server_name my-domain-3.com; location / { proxy_pass http://my-fastapi-app-3:80; } }
Note that the
proxy_pass
directive should point to the name of the FastAPI container, not the name of the Docker image. -
Restart the Nginx container to apply the changes:
docker exec my-nginx nginx -s reload
Now, you can access each FastAPI application at its custom domain. For example, you can access the first FastAPI application at
http://my-domain-1.com
.
Python
-
josn.dumps()
takes a Python dictionary and encodes it as a JSON Unicode string.cls=
: custom class to encode the Python object into a JSON object.ensure_ascii=
: ifFalse
, the result can contain non-ASCII characters. otherwise, all non-ASCII characters in the output are escaped.
-
json.loads()
takes a JSON Unicode string and decodes it into a Python dictionary.object_hook=
: custom function to convert the JSON object into a Python object.
-
JsonEncoder
- To extend this to recognize other objects, subclass and implement a
default(obj)
method with another method that returns a serializable object forobj
. otherwise it should call the superclass implementation
- To extend this to recognize other objects, subclass and implement a
-
python -m json.tool
: pretty print json -
RELEASE IT!, all team members must have the privilege to release the software. The release process should be documented and available to all team members. The release process should be test. The release process should be (automated and repeatable).