GitHub - MBerkhout/prefect-server · GitHub
Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

Repository files navigation

Prefect Server

Standalone Prefect server (API + UI only). No flow code, no worker. Use this repo to run the Prefect API and dashboard with a PostgreSQL backend. Workers and clients in another repo connect via PREFECT_API_URL and PREFECT_API_AUTH_STRING.

Architecture

[This repo: Prefect Server]  →  PostgreSQL (e.g. shared DB)
        ↑
        | PREFECT_API_URL + PREFECT_API_AUTH_STRING
        |
[Worker repo]  →  runs flows, talks to this server

Requirements

  • Docker (build from the included Dockerfile)
  • PostgreSQL instance for Prefect’s database (migrations and run history)

Environment variables

Configure these where the server runs (e.g. Railway Variables).

Variable Required Description
PREFECT_API_DATABASE_CONNECTION_URL Yes PostgreSQL URL for Prefect’s DB. Must use the async driver: postgresql+asyncpg://user:password@host:port/database. Can be the same Postgres as the rest of your stack; Prefect creates its own tables.
PREFECT_SERVER_API_AUTH_STRING Recommended Basic Auth for API and UI. Format: username:password. Example: admin:your_secure_password. The worker repo must set PREFECT_API_AUTH_STRING to this same value.
PORT If platform sets it Port the process should listen on (e.g. Railway sets this). Default in image: 4200. The image maps this to Prefect’s PREFECT_SERVER_API_PORT.

Build and run

docker build -t prefect-server .
docker run --rm -p 4200:4200 \
  -e PREFECT_API_DATABASE_CONNECTION_URL="postgresql+asyncpg://user:pass@host:5432/prefect" \
  -e PREFECT_SERVER_API_AUTH_STRING="admin:password" \
  prefect-server

Deploying (e.g. Railway)

  1. Create a new service from this repo; build from the Dockerfile.
  2. Set the env vars above (at least PREFECT_API_DATABASE_CONNECTION_URL and PREFECT_SERVER_API_AUTH_STRING). Set PORT only if your platform requires it (Railway sets it automatically).
  3. Expose the service (e.g. public domain) so:
    • Users can open the Prefect UI in the browser (with Basic Auth).
    • The worker service can reach the API (internal URL like http://<service-name>.railway.internal:4200/api or the public URL + /api if the worker is elsewhere).

Connecting the worker repo

In the repo that runs flows and the Prefect worker:

  • PREFECT_API_URL — API base URL of this server, e.g. http://<prefect-server-service>.railway.internal:4200/api or https://your-prefect-server.up.railway.app/api.
  • PREFECT_API_AUTH_STRING — Same value as this server’s PREFECT_SERVER_API_AUTH_STRING (e.g. admin:your_secure_password).

No code or config changes are needed in this server repo when you update the worker repo; the server is stateless except for the database.

Image details

  • Base: prefecthq/prefect:3-latest
  • Extra: asyncpg is installed so the server can use PostgreSQL with SQLAlchemy async. Set the URL as postgresql+asyncpg://user:password@host:port/database; using postgresql:// (sync driver) causes The loaded 'psycopg2' is not async.
  • Start: prefect server start --host 0.0.0.0, with port taken from PREFECT_SERVER_API_PORT (derived from PORT when set by the platform).

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages