Source codes of resource controllers and services in WebEng IoT testbed, written in Python
Docker + Flask + Redis + Gunicorn
- install docker
- build docker image from Dockerfile:
docker build -t webeng_{provider name}:latest .
- run the docker image to construct a container:
docker run -d -p 8000:8000 webeng_{provider name}:latest {provider name} {ID} {URL:PORT}
The format of -p
port option is {host's port}:{container's port}
.
You can also set a name of the container by using --name {name}
option.
For instance, provider {provider name}
is dummy_resource
, and it should be same with the file name.
You can copy dummy_resource.py
, or dummy_service.py
and following below instruction
- add a new controller file, name as
{provider name}_{provider type}.py
- from
base.py
, importResourceAPI
orServiceAPI
and define new resource's or service's API by inherit it, name asclass {provider name}{provider type}API
with capitalization - implement all abstract methods
- write execution code of flask app
- WSGI: Gunicorn integrated
- Visualization of the architecture
- Docker compose (divide Flask, Redis, NginX to different containers): maintain one container for each controller
docker ps
shows every containers.-a
option shows stopped containers.-l
option shows latest containers.docker logs {container ID}
shows execution logs of the container.docker kill {container ID}
kills the container by sending aSIGKILL
signal.docker system prune
removes all stopped containers, dangling images, unused networks.docker rm $(docker ps -a -q)
removes all docker containers
from flask_cors import CORS
app = Flask(__name__)
CORS(app)
- Containers cannot communicate directly to each other. Be cautious