Skip to content

Looking for the HydroServer v1 docs?

These docs now cover HydroServer v2. The v1 docs have moved to hydroserver.org/v1 and are still available. View the v1 version of this page.

Setting Up a Production Deployment ​

This guide provides an overview for deploying HydroServer in a production environment. It is intended to help system administrators and developers get started with setting up key infrastructure needed to run HydroServer reliably and at scale based on their needs and use-cases. The guide includes an overview of required infrastructure and production configuration settings.

HydroServer Required Infrastructure ​

Each HydroServer release includes a container image that packages the core HydroServer website, APIs, and supporting services. This image follows the OCI (Open Container Initiative) standard and can be deployed on any platform that supports Docker or other OCI-compatible runtimes, including commercial cloud providers or local environments. The image comes pre-configured with Gunicorn as the web server for production use and can also be used to run administrative and deployment management commands.

HydroServer requires a PostgreSQL database (version 15 or higher) for data storage. At present, no specific PostgreSQL extensions are required, although you should ensure the database is accessible from the HydroServer deployment environment and configured with sufficient resources for your expected workload.

Because Gunicorn is not designed to serve static files on its own, HydroServer bundles WhiteNoise to serve static assets directly from Django whenever local static storage is used, with compression and appropriate cache headers applied automatically. Recommended approaches for serving static files will vary by platform, and details and examples are provided below.

For user account management, HydroServer requires access to an external email server to send account verification and password reset emails. Alternatively, you may integrate third-party identity providers (e.g. Google) for account creation and sign-in. When using third-party authentication exclusively, certain account management features—such as direct password resets via email—may not be required.

Preparing for Production Deployment ​

The example configurations provided in the deployment tutorials are intended for demonstration and evaluation purposes only. For production use, additional configuration and infrastructure are strongly recommended.

HydroServer Production Environment Variables ​

HydroServer’s Docker image supports the following environment variables for configuring a deployment:

  • SECRET_KEY
    Secret used by Django to encrypt passwords and sign sessions. Must be securely generated and stored in production.
    Example: See Django docs

  • DEBUG
    Enables debug mode. Must be False in production.
    Example: True / False

  • STRICT_SECURITY
    Enables CSRF protection, requires a real SECRET_KEY, applies default account rate limits, and requires IDP_OIDC_PRIVATE_KEY when OIDC is enabled. Must be True in production. The published Docker image already defaults to True; this only needs to be set explicitly for deployments that don't use that image.
    Example: True / False

  • IDP_OIDC_ENABLED
    Whether HydroServer's built-in OIDC identity provider (discovery, authorize, token, and JWKS endpoints) is enabled. Defaults to True. When STRICT_SECURITY is also True, one of IDP_OIDC_PRIVATE_KEY or IDP_OIDC_PRIVATE_KEY_FILE must be set, or startup will fail.
    Example: True / False

  • IDP_OIDC_PRIVATE_KEY
    RSA private key (PEM format) used to sign OIDC tokens issued by HydroServer's identity provider. Generate one with:

    bash
    openssl genpkey -algorithm RSA -out oidc_private_key.pem -pkeyopt rsa_keygen_bits:2048

    Set this to the contents of that file, or use IDP_OIDC_PRIVATE_KEY_FILE instead to point at its path. Keep it secret and stable across restarts — rotating it invalidates any tokens signed with the old key.
    Example: contents of oidc_private_key.pem

  • IDP_OIDC_PRIVATE_KEY_FILE
    Path to a PEM file containing the RSA private key described above, as an alternative to setting IDP_OIDC_PRIVATE_KEY directly. Takes precedence over IDP_OIDC_PRIVATE_KEY if both are set.
    Example: /run/secrets/oidc_private_key.pem

  • PROXY_BASE_URL
    Base URL for your HydroServer instance.
    Example: https://hydroserver.your-domain.com

  • DATABASE_URL
    PostgreSQL connection string.
    Example: postgresql://hsdbadmin:securepassword123@127.0.0.1:5432/hydroserver

  • CACHE_URL
    Connection string for Django's cache backend. If unset and STRICT_SECURITY is True (as in production), HydroServer defaults to a database-backed cache table in DATABASE_URL shared across worker processes and replicas. If unset and STRICT_SECURITY is False, it uses a per-process in-memory cache. Set this to use a dedicated cache service instead, such as Redis.
    Example: redis://127.0.0.1:6379/1

  • ACCOUNT_SIGNUP_ENABLED
    Whether public account creation is allowed, by email or through a third-party provider.
    Example: True / False

  • ACCOUNT_OWNERSHIP_ENABLED
    Whether new accounts can create or own workspaces by default. Admins can override per user.
    Example: True / False

  • SOCIALACCOUNT_SIGNUP_ONLY
    If True, new accounts can only be created through configured third-party providers. Example: True / False

  • SMTP_URL
    Connection string for sending emails.
    Example: smtp://127.0.0.1:1025

  • DEFAULT_FROM_EMAIL
    Email address used for account management emails if SMTP is configured.
    Example: noreply@example.com

  • MEDIA_STORAGE_ENABLED
    Whether HydroServer will accept file uploads for site/datastream linked resources, and expose them at /media/. Defaults to False — instances that don't want to manage file storage can leave this off and only use external URL linked resources, without needing to configure MEDIA_STORAGE_BACKEND below at all. This does not affect external URL-linked resources, which are always allowed.
    Example: True

  • MEDIA_STORAGE_BACKEND
    Dotted path to the Django storage backend used to store hosted linked resources (only relevant when MEDIA_STORAGE_ENABLED is True). Defaults to django.core.files.storage.FileSystemStorage (local disk), which is not recommended for production — set this explicitly to storages.backends.s3.S3Storage or storages.backends.gcloud.GoogleCloudStorage.
    Example: storages.backends.s3.S3Storage

  • MEDIA_STORAGE_OPTIONS
    JSON object of keyword arguments passed to MEDIA_STORAGE_BACKEND.
    Example (S3): {"bucket_name": "hydroserver-media-your-account-id", "location": "media"}
    Example (GCS): {"bucket_name": "hydroserver-media-your-project-id", "project_id": "your-gcp-project-id", "location": "media"}

  • STATIC_STORAGE_BACKEND
    Dotted path to the Django storage backend used to serve static files. Defaults to django.contrib.staticfiles.storage.StaticFilesStorage (local disk), which is not recommended for production — set this explicitly to storages.backends.s3.S3Storage or storages.backends.gcloud.GoogleCloudStorage.
    Example: storages.backends.s3.S3Storage

  • STATIC_STORAGE_OPTIONS
    JSON object of keyword arguments passed to STATIC_STORAGE_BACKEND.
    Example (S3): {"bucket_name": "hydroserver-static-your-account-id", "location": "static"}
    Example (GCS): {"bucket_name": "hydroserver-static-your-project-id", "project_id": "your-gcp-project-id", "location": "static"}

  • STATIC_HOST
    Optional origin prefixed to STATIC_URL to front static files served by HydroServer with a CDN (e.g., Amazon CloudFront). Only applied when STATIC_STORAGE_BACKEND is local. Leave unset to serve static files at a relative /static/ path.
    Example: https://d123abc4567.cloudfront.net

  • WHITENOISE_MAX_AGE
    Cache-Control max-age, in seconds, that WhiteNoise sets on locally served static files. Defaults to 86400 (1 day).
    Example: 86400

  • WHITENOISE_USE_FINDERS / WHITENOISE_AUTOREFRESH
    Development conveniences that let WhiteNoise serve static files without running collectstatic and pick up changes without a restart. Both default to the value of DEBUG and should be False in production.
    Example: False

Hosts, Origins, and Cookies ​

  • ALLOWED_HOSTS
    Additional host names this instance responds to, as a comma-separated list. The host in PROXY_BASE_URL is always allowed, so set this only if HydroServer is also reached through other host names.
    Example: hydroserver.your-domain.com,www.hydroserver.your-domain.com

  • CSRF_TRUSTED_ORIGINS
    Comma-separated list of origins trusted to make unsafe (e.g. POST) requests with a session cookie. Defaults to PROXY_BASE_URL. Add the origin of any separately hosted frontend that uses session authentication.
    Example: https://hydroserver.your-domain.com,https://app.your-domain.com

  • SAME_ORIGIN_FRONTEND
    Whether the Data Management App is served from the same origin as HydroServer, as it is in the published Docker image. When True, WEB_CLIENT_URL defaults to PROXY_BASE_URL. Defaults to False.
    Example: True

  • WEB_CLIENT_URL
    The URL of the Data Management App, where users are sent after signing in or out of HydroServer's account pages. Defaults to PROXY_BASE_URL when SAME_ORIGIN_FRONTEND is True, otherwise to the local development frontend.
    Example: https://hydroserver.your-domain.com

  • ACCOUNT_RETURN_URL_ALLOWED_HOSTS
    Comma-separated list of additional hosts (with ports, if needed) that the account pages may send users back to after signing in, signing up, or signing out. Set this for separately hosted apps that link users to HydroServer's account pages.
    Example: app.your-domain.com

  • CORS_ALLOW_CREDENTIALS
    Whether browsers may send cookies with cross-origin requests to HydroServer's APIs. Defaults to False when STRICT_SECURITY is True. Cross-origin apps should normally authenticate with OIDC access tokens instead.
    Example: False

  • SESSION_COOKIE_NAME / CSRF_COOKIE_NAME
    Names of the session and CSRF cookies. Default to hs_session and csrftoken. Change them only if they conflict with another application on the same domain.
    Example: hs_session

  • SESSION_COOKIE_AGE
    How long, in seconds, a sign-in session lasts. Defaults to 86400 (1 day).
    Example: 86400

  • NOINDEX
    If True, adds an X-Robots-Tag: noindex header to every response so search engines don't index the instance. Useful for staging and demo instances. Defaults to False.
    Example: True

Database Connections ​

  • SSL_REQUIRED
    If True, requires SSL for the database connection (sslmode=require). Defaults to False.
    Example: True

  • DB_POOL_MIN_SIZE / DB_POOL_MAX_SIZE / DB_POOL_TIMEOUT
    Size of each HydroServer process's database connection pool, and how many seconds a request waits for a free connection. Default to 5, 10, and 60. Make sure the total across all processes and replicas stays below your database's connection limit.
    Example: 5 / 10 / 60

  • CONN_MAX_AGE / CONN_HEALTH_CHECKS
    Django's persistent connection lifetime in seconds and whether to check connections before reuse. Default to 0 and True.
    Example: 0 / True

Rate Limiting ​

  • API_RATE_LIMITS
    JSON object setting request rate limits for the Data Management API, with anonymous and authenticated rates. Leave unset to disable API rate limiting.
    Example: {"anonymous": "20/s", "authenticated": "50/s"}

  • ACCOUNT_RATE_LIMITS
    JSON object of django-allauth rate limits for account actions such as sign-in, sign-up, and password reset. When STRICT_SECURITY is True, allauth's default limits apply unless you override them here.
    Example: {"login_failed": "10/m/ip,5/5m/key"}

OIDC Tokens and Service Accounts ​

  • IDP_OIDC_ACCESS_TOKEN_EXPIRES_IN
    Lifetime, in seconds, of access tokens issued by HydroServer's OIDC identity provider. Defaults to 3600 (1 hour).
    Example: 3600

  • IDP_OIDC_ROTATE_REFRESH_TOKEN
    Whether a new refresh token is issued each time a refresh token is used. Defaults to True.
    Example: True

  • SERVICE_ACCOUNT_EMAIL_DOMAIN
    Domain used for the generated email address that identifies each service account. Defaults to hydroserver.local.
    Example: hydroserver.your-domain.com

Task Runs and Logging ​

  • TASK_RUN_RETENTION_DAYS
    Number of days of Job Orchestration System task run history to keep. Older runs are deleted by a scheduled cleanup task, which requires a Celery worker and scheduler and keeps running when CELERY_ENABLED is False. Defaults to 7.
    Example: 30

  • TASK_RUN_CLEANUP_CRONTAB
    Crontab schedule (minute, hour, day of month, month, day of week) for the task run cleanup. Defaults to 0 3 * * * (daily at 03:00).
    Example: 0 3 * * *

  • LOG_FORMAT
    standard for plain-text logs or json for structured JSON logs. Defaults to standard.
    Example: json

Storing Secrets ​

Store sensitive environment variables (database credentials, API keys, etc.) securely, using a secret manager such as AWS Systems Manager Parameter Store, HashiCorp Vault, or GCP Secret Manager. Avoid committing secrets to version control or hardcoding them into configuration files.

Serving Static and Media Files ​

Static files (CSS, JavaScript, and images bundled with the application) are served directly by HydroServer, using Django WhiteNoise, whenever STATIC_STORAGE_BACKEND is local. WhiteNoise applies gzip compression and necessary cache headers automatically. For higher-traffic deployments, set STATIC_HOST to a CDN domain (e.g., AWS CloudFront) pointed at your HydroServer instance as its origin; WhiteNoise's cache headers let the CDN serve cached static assets without re-fetching from HydroServer on every request.

Media files are only relevant if MEDIA_STORAGE_ENABLED is True — instances that only use external URL linked resources for their sites/datastreams can leave media storage unconfigured. Django is not optimized for storing or serving user-uploaded media files in production. Recommended approaches include:

Since these approaches bypass HydroServer’s internal authorization system, you may need to add additional security controls to protect private media files (for example, by using signed URLs).

Sign-In Provider Icons ​

OpenID Connect sign-in buttons show the icon at provider-icons/<provider ID>.png in static storage, or text only if there's no file. Icons for github, google, microsoft, and orcid are included.

To add or replace an icon, publish a small square PNG (about 64 × 64 pixels) to that path during deployment:

Static storageWhere to put icons
Cloud bucket (S3, Google Cloud Storage)provider-icons/ under the static location (e.g. static/provider-icons/utahid.png)
Local, published imageA directory mounted at /app/django/staticfiles/provider-icons; restart after changes
Local, custom image or developmentdjango/static/provider-icons/

To use another path or format, set "icon" in the provider's Settings, e.g. "icon": "provider-icons/cuahsi.svg".

New icons can take up to five minutes to appear. collectstatic --clear deletes icons published to a bucket, and manifest (content-hashed) static storage isn't supported.

Email Configuration ​

HydroServer requires an SMTP server to send emails (e.g., password resets, email verification). For production, use a reliable external email provider such as Amazon Simple Email Service (SES) or Gmail SMTP with authentication and TLS enabled.

HTTPS ​

HydroServer should be served exclusively over HTTPS in production. Options include:

Load Balancing and System Requirements ​

When planning a production deployment of HydroServer, it is important to consider performance, scalability, and fault tolerance. Key areas include:

  • Web Server Load Balancing
    For deployments that need to serve a large number of concurrent requests, place HydroServer behind a load balancer (such as AWS Application Load Balancer (ALB), Google Cloud Load Balancer, or NGINX). The load balancer distributes incoming traffic across multiple HydroServer containers or instances, improving reliability and response times. When running HydroServer on serverless architecture, scaling HydroServer up and down based on user traffic can also help lower costs.

  • Application Server Requirements
    HydroServer runs on the Django Framework, which by default uses a single-threaded development server. In production, you should run HydroServer behind the built-in Gunicorn service with worker processes scaled to the available CPU and memory resources. Containers or VMs should be sized to handle the expected workload, and additional replicas can be added horizontally. Web server resource requirements will vary greatly depending on expected concurrent traffic and types of workloads being performed with your HydroServer deployment.

  • Database Requirements
    PostgreSQL should be provisioned with sufficient CPU, memory, and disk throughput to handle both transactional workload and background tasks (e.g., data ingestion). It is recommended to run PostgreSQL as a managed service where available, or to configure regular backups and monitoring if self-managed.

  • Database Connection Pooling
    When scaling up the number of HydroServer web servers or worker processes, a large number of short-lived database connections can be generated under high traffic loads. To avoid overwhelming PostgreSQL with connection overhead for larger deployments, consider setting up a connection pooling service such as PgBouncer. Connection pooling reduces latency, stabilizes performance under high concurrency, and allows more efficient use of database resources.

Security and Access Control ​

When deploying HydroServer in production, you should implement multiple layers of security to reduce risk:

  • Database Access
    Restrict external access to the PostgreSQL database. It should only be accessible by the HydroServer service or other explicitly authorized services (e.g., a database backup service). Consider using managed database services that provide built-in encryption, automated backups, and fine-grained access control.

  • Network Restrictions
    Configure a firewall or security group to only allow required inbound traffic (typically HTTPS for HydroServer). Deny all other external connections by default, and restrict outbound access to only the services HydroServer needs to reach.

  • Secure Communication
    Ensure all internal services (e.g., HydroServer, reverse proxy, database) communicate over a secure network. For distributed deployments, use TLS for connections between services where possible.

  • Authentication and Authorization
    Apply the principle of least privilege for all user roles and service accounts. For external APIs, consider rate limiting and monitoring to detect unusual activity.

  • Regular Updates
    Keep HydroServer, its dependencies, and all supporting infrastructure (e.g., Docker base images, PostgreSQL) up to date with the latest security patches.

  • Monitoring and Logging
    Enable logging at both the application and infrastructure layers. Use monitoring tools to detect suspicious activity, unauthorized access attempts, and to track overall system health. HydroServer also provides a /health-check endpoint that can be used by external monitoring services.

Enabling Celery for HydroServer ​

HydroServer's Job Orchestration System uses Celery to run data ingestion, data product, and quality monitoring tasks in the background. To use it, you must set up several additional services, including at least one worker instance, a scheduler, and a broker such as Redis. The rest of HydroServer works without these services.

The following HydroServer settings can be used to configure Celery:

  • CELERY_ENABLED
    Controls whether the Job Orchestration System is enabled. Defaults to True. Set it to False if you don't run the Celery services, or to turn off orchestration on an instance that does. When False:

    • Users can't create new tasks or run existing tasks. The API returns 501 Not Implemented for these requests, and the Job Orchestration page in the Data Management App disables these buttons.
    • Users can still view, edit, and delete existing tasks, and can create, edit, and delete data connections.
    • The scheduler stops sending scheduled tasks, and workers skip any tasks they receive, including ones that were queued before the setting changed. Data connection notification emails are not sent. The task run cleanup (see TASK_RUN_RETENTION_DAYS) keeps running if able.
    • Task schedules are left unchanged, so they resume as they were when you set CELERY_ENABLED back to True.

    Set CELERY_ENABLED to the same value on the web server, worker, and scheduler containers, and restart all of them after changing it.
    Example: True / False

  • CELERY_BROKER_URL The URL of the broker service Celery should use to orchestrate tasks. Example: redis://127.0.0.1:6379/0

To start a Celery worker, use the following entrypoint command with HydroServer’s Docker image. This container must have database and broker access.

bash
celery -A hydroserver worker --loglevel=INFO

To start a Celery scheduler, use the following entrypoint command with HydroServer’s Docker image. This container must have database and broker access.

bash
celery -A hydroserver beat --loglevel=INFO

HydroServer Management Commands ​

After provisioning your infrastructure, but before starting HydroServer’s web server, you must run several management commands to complete setup. In the demo deployments from the deployment tutorials, these steps are bundled into the convenience command:

bash
python manage.py run_demo

This command is intended for demonstration purposes only. It runs the required setup steps and starts Django’s development server. Do not use it in production. For production deployments, run the following commands individually, or configure an automated process to run them once your database and storage volumes are ready:

bash
python manage.py migrate

Initializes all required HydroServer database tables in your PostgreSQL database.
This must be run first. You may also need to rerun it when upgrading HydroServer (always check new version release notes first for details).

bash
python manage.py collectstatic

Copies HydroServer’s static files to the deployment location.
Run this after upgrades to ensure new or updated static files are available.

bash
python manage.py createsuperuser

Creates the initial admin account for your HydroServer instance (Django will prompt for an email and password).
Run once only. Additional admin accounts can be created later through the dashboard.

Starting HydroServer with Gunicorn ​

HydroServer’s Docker image comes pre-installed with Gunicorn as the production-ready application server. After provisioning all deployment infrastructure, completing database migrations, collecting static files, and setting up an admin user, you can start the web server using Gunicorn.

Use the following entrypoint command when starting a HydroServer container in production:

bash
gunicorn hydroserver.wsgi:application --bind 0.0.0.0:8000 --workers 3
  • hydroserver.wsgi:application
    Points Gunicorn to HydroServer's WSGI application.

  • --bind 0.0.0.0:8000 Exposes the application on all container network interfaces at port 8000. This will work for most deployment methods, but it can be adjusted if needed.

  • --workers 3 The number of worker processes Gunicorn will spawn. Adjust this number based on available CPU cores and expected traffic. Gunicorn generally recommends setting the number of workers to (2 * num_cores) + 1. The example above is intended for a HydroServer instance running on a single core.

After the server is running, visit your configured domain in a browser to access HydroServer.

Updating to a New Version ​

To update an existing HydroServer deployment to a new version:

  1. Read the release notes for every version between your current version and the target version. Some releases include required manual steps, database migration prerequisites, or breaking changes that must be addressed before or after upgrading. Release notes are published on the HydroServer GitHub releases page.

  2. Back up your database. Always take a snapshot of your PostgreSQL database before applying an upgrade, especially for releases that include database migrations.

  3. Pull the new image. Update your deployment configuration to reference the new container image version and redeploy.

  4. Run post-deployment management commands. After the new container is running, execute the following:

    bash
    python manage.py collectstatic

    Collects any new or updated static files included in the release.

    bash
    python manage.py migrate

    Applies any database schema changes included in the release.

  5. Restart Celery workers (if applicable). If your deployment uses Celery for background task scheduling, restart your worker and beat containers after the upgrade to pick up any changes.