Deployment¶
Cloud Build¶
- Google Cloud Build pipelines handle application deployment
- The development environment is deployed to the
developmentnamespace in GKE - The deployment process:
- Builds a container image
- Uses Helm to apply changes to Kubernetes manifests
- Deploys the updated application code
Helm Chart¶
- The application uses Helm for Kubernetes deployments
- Helm is used for the Development deployment of the application.
- Helm charts define the application's GKE resources.
- Configuration files are located in the
helmdirectory - More details are in the README.md in the
helmdirectory.
Container Startup Process¶
The application uses an entrypoint script and start script to initialize the container.
Entrypoint Script (compose/production/django/entrypoint)¶
The entrypoint script runs first and handles database connectivity:
- Sets PostgreSQL connection defaults
- Constructs the
DATABASE_URLenvironment variable - Waits for PostgreSQL to become available using
wait-for-it - Passes control to the start script
Start Script¶
Production (compose/production/django/start):
collectstatic- Collects static files for servingmigrate- Applies database migrationsensure_adhs_organization- Creates the default ADHS organization if it doesn't existsetup_permission_groups- Creates/updates permission groups and their associated permissions- Starts Gunicorn WSGI server on port 8000
Local Development (compose/local/django/start):
migrate- Applies database migrationsensure_adhs_organization- Creates the default ADHS organizationsetup_permission_groups- Creates/updates permission groups- Starts Django development server with
runserver_pluson port 8000
Key Management Commands¶
| Command | Description |
|---|---|
ensure_adhs_organization |
Creates the default ADHS organization required for the platform |
setup_permission_groups |
Creates all permission groups (Platform Admin, Lab Director, etc.) with their associated Django permissions |
seed_metadata_templates |
Seeds/updates metadata templates, keys, values, and source types for file metadata |
Metadata Template Seeding¶
The application uses a configurable metadata template system for tagging files and datasets with structured metadata. The seed_metadata_templates management command populates and updates the database with predefined metadata schemas.
Running the Command¶
Data Model Overview¶
The metadata system consists of several interconnected models:
| Model | Location | Purpose |
|---|---|---|
Key |
asu_apgap/metadatatags/models.py |
Predefined metadata field names with data types (TEXT, NUMBER, DATE, SELECT) |
Value |
asu_apgap/metadatatags/models.py |
Predefined values that can be assigned to keys (e.g., dropdown options) |
SourceType |
asu_apgap/metadata_requirements/models.py |
Sample source categories (Human Host, Water Sample, etc.) |
MetadataTemplate |
asu_apgap/metadata_requirements/models.py |
Defines which keys apply to which source types, with requirement rules |
MetadataTemplateOption |
asu_apgap/metadata_requirements/models.py |
Links predefined values to templates for select/multi-select fields |
How the Seeding Works¶
The management command (asu_apgap/metadatatags/management/commands/seed_metadata_templates.py) performs the following operations in a single atomic transaction:
-
Source Types Creation: Creates 12 predefined source types (Human Host, Companion Animal Host, Wildlife Host, Vectors, Livestock AG Animal Host, Air, Produce AG, Food Product, Surface, Soil Sample, Water Sample, Wastewater Sample)
-
Keys & Values Collection: Collects all unique metadata keys and values from two data structures:
ALL_SEQUENCES: Core metadata fields that apply to all source types (e.g., Sample ID, Pathogen name, Date Collected, Sequencing instrument)-
SOURCE_TYPE_METADATA: Source-type-specific fields (e.g., "Biospecimen type" for Human Host, "Water source" for Water Sample) -
Bulk Key Creation: Creates
Keyobjects with normalized names (uppercase, trimmed) and appropriate data types mapped from field types: text,text_field,text_input→TEXTselect,multi_select→SELECTdate,time→DATE-
number→NUMBER -
Bulk Value Creation: Creates
Valueobjects for all predefined dropdown/select options -
Template Creation: Creates
MetadataTemplaterecords that define: - Which key applies to which source type (or
Nonefor core templates) - Whether the field is required
- Whether multiple values can be selected
- Display sort order
-
The UI field type (select, multi_select, text, etc.)
-
Template Options Creation: Links predefined
Valueobjects to their correspondingMetadataTemplaterecords for select/multi-select fields
Data Structure Definition¶
The metadata schemas are defined as Python dictionaries in the management command file:
# Core fields applied to ALL sequences (source_type=None)
ALL_SEQUENCES = {
"keys": [
{"name": "Sample ID", "required": True, "type": "text", "values": []},
{"name": "Pathogen/organism name", "required": True, "type": "multi_select", "values": ["SARS-CoV-2", "Influenza", ...]},
{"name": "Date Collected", "required": True, "type": "date", "values": []},
# ... more fields
]
}
# Source-type specific metadata requirements
SOURCE_TYPE_METADATA = {
"HUMAN_HOST": {
"keys": [
{"name": "Biospecimen type", "required": True, "type": "select", "values": ["Nasopharyngeal swab", "Saliva", ...]},
{"name": "Age (in years)", "required": False, "type": "number", "values": []},
# ... more fields
]
},
"WATER_SAMPLE": {
"keys": [
{"name": "Water source", "required": True, "type": "select", "values": ["Municipal tap", "Irrigation line", ...]},
{"name": "pH", "required": True, "type": "number", "values": []},
# ... more fields
]
},
# ... more source types
}
Idempotent Behavior¶
The command is designed to be run multiple times safely:
- Existing records are updated if their properties have changed
- New records are created only if they don't exist
- Uses
ignore_conflicts=Trueon bulk creates to handle race conditions - All operations are wrapped in a database transaction
Modifying Metadata Templates¶
To add or modify metadata templates:
- Edit the
ALL_SEQUENCESdictionary for core fields that apply to all source types - Edit the
SOURCE_TYPE_METADATAdictionary for source-type-specific fields - Run the management command to apply changes:
The command will output a summary of created/updated records upon completion.