Skip to content

Sample Python+TS full stack template for developing containerized web apps, featuring E2E tests with Puppeteer and a complete CI pipeline with Azure DevOps. These are personal notes so take them with a grain of salt.

License

danicc097/FastAPI-React-Postgres-Docker-Traefik-template

Repository files navigation

FastAPI-React-Postgres-Docker-Traefik-template

Build Status

1 2

3 4

5 6

7 8

Table of contents

Dev setup

Root dir setup

Create and fill in .env, .env.dev and .env.prod from .env.template.

Backend dev setup

Run the installation scripts in /docs.

Create .env.dev and .env.prod from .env.template.

Frontend dev setup

cd frontend && pnpm i

Create .env.development and .env.production from .env.template.

E2E dev setup

cd e2e && npm install

Run E2E tests

This will setup dev environment normally but run the tests in a bundled frontend.

bin/run-e2e-tests

Traefik setup

Create certificates with mkcert.

For linux VM:

mkdir traefik/certificates
cd traefik/certificates
sudo apt install libnss3-tools
wget https://github.com/FiloSottile/mkcert/releases/download/v1.4.3/mkcert-v1.4.3-linux-amd64 -O mkcert
chmod +x mkcert
sudo mv mkcert /usr/bin/
source ~/.bashrc
mkcert --cert-file localhost.pem --key-file localhost-key.pem  "dev.localhost" "*.dev.localhost" "prod.localhost" "*.prod.localhost" "e2e.localhost" "*.e2e.localhost" "e2e.localhost" "*.e2e.localhost" "wiki.localhost"
mkcert --install

For Windows: Copy the CAROOT from the virtualmachine: cat "$(mkcert -CAROOT)/rootCA.pem" over to windows: code "$(.\mkcert.exe -CAROOT)/rootCA.pem"

Run mkcert --install for the first time to create a CAROOT. Then replace the contents and run mkcert -install again to update the CAROOT.

Azure pipelines

  • Variables named "*secret*" in .env* files are ignored, and SECRET_KEY=something in variables: key won't be parsed either and yield SECRET_KEY=. They have to be set in Azure Devops and mapped in pipeline tasks with the env: key.

  • If ENV_VAR is set as an azure pipeline variable at the top level, it's available as ${ENV_VAR} in compose.

Troubleshooting

Pydantic validation

Fastapi won't give a meaningful error when the response model typing in a route does not match the return value.

    if errors:
    >               raise ValidationError(errors, field.type_)
    E               pydantic.error_wrappers.ValidationError: <unprintable ValidationError object>

/usr/local/lib/python3.9/site-packages/fastapi/routing.py:138: ValidationError

We should always look into the response_model of the route first of all to ensure it's correct.

Traefik

  • Ensure different routers traefik.http.routers.<my-router> are used for different environments. Else we get a 404 when the service container is actually running

About

Sample Python+TS full stack template for developing containerized web apps, featuring E2E tests with Puppeteer and a complete CI pipeline with Azure DevOps. These are personal notes so take them with a grain of salt.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published