Deployment
This part explains how to deploy GENTRAIN for both internal use and external organizations (e.g. research institutes or health agencies).
It details the deployment workflow, environment variables, secrets, and automation using GitHub Actions.
ποΈ 1. Deployment Overviewβ
GENTRAIN supports two main deployment modes:
| Mode | Use Case | Tooling |
|---|---|---|
| Development | Local testing or customization | docker-compose.dev.yaml |
| Production | Stable instance for organizational use | docker-compose.prod.yaml + Caddy |
The repository includes examples and templates to help you get started:
.env.exampleβ shows required and optional environment variables.Caddyfile.exampleβ example reverse proxy configuration for Caddy, including TLS and routing to the API and frontend..github/workflows/prod_deployment.ymlβ production workflow (GitHub Actions CI/CD) used by the core deployment, which can be adapted to your own server.
βοΈ 2. Prerequisitesβ
Install the following dependencies before deploying:
- Docker (β₯ 20.x)
- Docker Compose (plugin β₯ v2)
- Git
π§© 3. Local Development Setupβ
Run GENTRAIN locally to test or modify code. You can find a comprehensive guide in the Getting Started section.
# Start Redis, Postgres, and API
docker compose -f docker-compose.dev.yaml up -d
# Run the frontend with hot reload
npm run dev
Alternatively, use the helper script:
sh dev.sh
π 4. Production Deploymentβ
Production deployment uses Caddy as a reverse proxy with HTTPS support.
Persistent Docker volumes store database, uploads, and built static files.
Step 1 β Clone the repositoryβ
git clone https://github.com/DiltheyLab/GENTRAIN.git
cd GENTRAIN
Step 2 β Configure environment variablesβ
If you are not using a deployment workflow, manually create the variables described in the Explanation of Variables and Secrets section:
cp .env.example .env
Adjust your .env with correct hostnames, secrets, and paths.
Step 3 β Configure Caddyβ
Use Caddyfile.example as reference to configure Caddy for HTTPS termination and routing:
- Serves frontend and documentation under
/ - Proxies
/api/*to the backend container - Supports automatic TLS certificates via Letβs Encrypt
Step 4 β Start the stackβ
docker compose -f docker-compose.prod.yaml up -d --build
βοΈ 5. Automated Deployment with GitHub Actionsβ
The repository includes a production deployment workflow at
.github/workflows/prod_deployment.yml.
This workflow automates:
- Building the frontend and documentation
- Connecting via SSH to the remote production server
- Regenerating
.envfrom GitHub variables and secrets - Creating a database backup (only the last 5 backups will be saved)
- Rebuilding and restarting Docker containers safely
- Sending Slack notifications on success or failure
The created database backup can be used as follows:
docker exec -i gentrain-db psql -U gentrain -d test < db_dumps/<db_dump>.sql
You can create a manuell Backup like this:
docker exec -t gentrain-db pg_dump -d gentrain -U gentrain > db_dumps/`date +%Y-%m-%d"_"%H_%M_%S`.sql
This means organizations can reuse the same pipeline by:
- Forking the repo or mirroring it privately
- Adding their own GitHub Actions variables and secrets
- Defining a
prodbranch for production updates
π§ 6. Explanation of Variables and Secretsβ
The workflow dynamically writes a .env file on the server based on GitHub variables (vars) and secrets (secrets).
Below is an explanation of each one and its purpose.
πΉ General / Connectionβ
| Name | Type | Description |
|---|---|---|
SSH_HOST | Variable | Hostname or IP of the production server (used by appleboy/ssh-action). |
SSH_USER | Variable | Username for SSH connection (e.g. ubuntu, gentrain). |
SSH_PRIVATE_KEY | Secret | Private key for authentication (never commit to repo). |
GENTRAIN_DIR | Variable | Path on the server where GENTRAIN is located (e.g. /opt/gentrain). |
PRODUCTION_BRANCH | Variable | The Git branch that should be deployed (e.g. prod). |
GENTRAIN_PASSWORD | Secret | Sudo password on the remote host, used for restarting Docker with elevated rights. |
πΉ Application / API Configurationβ
| Name | Type | Description |
|---|---|---|
VITE_API_HOST | Variable | Public API endpoint (e.g. https://api.yourdomain.org). Used in frontend builds. |
VITE_APP_URL | Variable | Base URL of your application (used for redirects and link generation). |
APP_ENV or PROD_APP_ENV | Variable | Defines runtime environment (e.g. production). |
API_DATA_DIRECTORY | Variable | Directory path where API stores uploaded files and pathogen data. |
πΉ Database and Redisβ
| Name | Type | Description |
|---|---|---|
DATABASE_DRIVER | Variable | Database driver (usually postgres). |
DATABASE_HOST | Variable | Hostname of PostgreSQL service (container name or external host). |
DATABASE_PORT | Variable | Port of PostgreSQL service (default 5432). |
DATABASE_NAME | Variable | Name of the GENTRAIN database. |
DATABASE_USER | Variable | Username used by GENTRAIN backend. |
DATABASE_PASSWORD | Secret | Password for database authentication. |
REDIS_HOST | Variable | Hostname of Redis service. |
REDIS_PORT | Variable | Redis port (default 6379). |
REDIS_USERNAME | Variable | Optional Redis username. |
REDIS_PASSWORD | Secret | Password for Redis authentication (if enabled). |
πΉ Admin Panelβ
| Name | Type | Description |
|---|---|---|
ADMIN_PANEL_PORT | Variable | Port on which the admin interface runs (e.g. 5540). |
ADMIN_PANEL_URL | Variable | Public or internal URL for admin access. |
DEFAULT_ADMIN_USERNAME | Variable | Default administrator username (used during first setup). |
DEFAULT_ADMIN_PASSWORD | Secret | Default administrator password (should be changed after first login). |
πΉ Security and Sessionsβ
| Name | Type | Description |
|---|---|---|
SESSION_SECRET | Secret | Used for session encryption in the backend. |
COOKIE_SECRET | Secret | Used to sign secure cookies in the admin panel. |
πΉ Notificationsβ
| Name | Type | Description |
|---|---|---|
SLACK_WEBHOOK_URL | Variable | Webhook URL for Slack notifications. Used in all workflow steps to report success or failure. |
π§± 7. Example of Environment Generation in the Workflowβ
During the GitHub Action run, the workflow executes SSH commands like this:
- name: Generate environment variables
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ vars.SSH_HOST }}
username: ${{ vars.SSH_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
cd ${{ vars.GENTRAIN_DIR }}
rm -f .env
touch .env
echo -e "VITE_API_HOST=${{vars.VITE_API_HOST}}" >> .env
...
This ensures the .env file on the server always matches the latest variables from GitHub.
πΎ 8. Persistent Volumesβ
Production Compose defines named Docker volumes:
| Volume | Description |
|---|---|
postgres_data | PostgreSQL database data (must be backed up). |
api_data | Pathogen schemes, example files |
frontend_files, docs_files | Built frontend and docs. |
caddy_config, caddy_data | Caddy state, certificates, and logs. |
To back up:
docker exec -t gentrain-db pg_dumpall -c -U ${DATABASE_USER} > backup.sql
cp -r ./api_data ./backup_api_data_$(date +%F)
π§― 9. Rollback Procedureβ
If a deployment fails:
docker compose -f docker-compose.prod.yaml down
git checkout <previous-tag>
docker compose -f docker-compose.prod.yaml up -d --build
Restore your database if required:
psql -U $DATABASE_USER -d $DATABASE_NAME -f backup.sql
π§ 10. Security Best Practicesβ
- Rotate all GitHub secrets regularly
- Restrict SSH access to trusted IPs
- Use HTTPS with automatic renewal via Caddy
- Never store plaintext passwords in
.envfiles - Use Basic Auth on the admin panel if itβs exposed publicly
π 11. Important Repository Filesβ
| File | Purpose |
|---|---|
.env.example | Example configuration for required environment variables |
Caddyfile.example | Example configuration for HTTPS reverse proxy |
docker-compose.dev.yaml | Development stack |
docker-compose.prod.yaml | Production stack |
.github/workflows/prod_deployment.yml | Production CI/CD workflow |
.github/workflows/dev_deployment.yml | Development CI/CD workflow |
init-entrypoint.sh | Initializes volumes and user permissions for production containers |