Deployment¶
For more detailed information about deployment of fastapi-based services see FastAPI deployment
Services based on fastapi-serviceutils
can be easily deployed inside
a docker-container.
Before deployment you need to:
update the dependencies
run all tests
create the current
requirements.txt
ensure the
docker-compose.yml
is defined correctly including theenvironment-variables
To run these tasks run:
make finalize
To run the service using docker-compose customize the docker-compose.yml
and run:
sudo docker-compose up -d
Basics¶
Docker¶
The basic Dockerfile should look like:
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.7
COPY requirements.txt ./
RUN pip install -r requirements.txt
COPY . /app
Docker-compose¶
The service can be deployed with Docker compose using the Docker compose file:
version: '3.7'
services:
<SERVICENAME>:
build:
context: .
dockerfile: Dockerfile
image: <SERVICENAME>
ports:
- "<SERVICE_PORT>:80"
environment:
- <SERVICENAME>_SERVICE__MODE="prod"
- ...
volumes:
- type: bind
source: <LOGFOLDER_ON_HOST>
target: <LOGFOLDER_INSIDE_DOCKER_CONTAINER>
Environment-variables¶
Setting environment-variables overwrites the default values defined in the config.
Please ensure to use the environment-variables (Environment variable) if you want to overwrite some default-settings of the service.
The environment-variables to use should be defined inside the config.yml
.
Set the values of the environment-variables inside the docker-compose.yml
.