lhaig / nomad-postgresql

Published by Lance Haig | Raw HCL

job
0 stars
Description
Postgresql Job
License
MPL-2.0
Tags
#database #postgresql
Versions
Select a version to see its documentation and run command.
Quick Run (v0.0.1)
ramble job run lhaig/nomad-postgresql@v0.0.1
README
# PostgreSQL A powerful, open-source relational database. ## Overview This job deploys [PostgreSQL](https://www.postgresql.org/) as a service job on Nomad with sensible defaults for development and testing. ## Requirements - Docker driver enabled on Nomad clients ## Usage ```bash nomad job run postgresql.nomad.hcl ``` With custom variables: ```bash nomad job run \ -var="database=myapp" \ -var="username=myuser" \ -var="password=secretpassword" \ -var="memory=1024" \ postgresql.nomad.hcl ``` ## Variables | Name | Description | Default | |------|-------------|---------| | `datacenters` | List of datacenters to deploy to | `["dc1"]` | | `postgres_version` | PostgreSQL Docker image tag | `16-alpine` | | `port` | Static port (0 for dynamic) | `5432` | | `database` | Default database name | `postgres` | | `username` | Database superuser username | `postgres` | | `password` | Database superuser password | `postgres` | | `cpu` | CPU allocation in MHz | `500` | | `memory` | Memory allocation in MB | `512` | | `service_provider` | Service discovery provider | `nomad` | ## Connecting From another Nomad job using Nomad service discovery templates: ```hcl template { data = <<EOF {{- range nomadService "postgresql" }} DATABASE_URL=postgres://user:pass@{{ .Address }}:{{ .Port }}/dbname {{- end }} EOF destination = "local/env" env = true } ``` ## Persistence This job does not include persistent storage by default. Data will be lost when the container restarts. For production use, consider: - Adding a host volume mount for `/var/lib/postgresql/data` - Using CSI volumes for cloud-native storage Example with host volume: ```hcl volume "pgdata" { type = "host" source = "postgresql" } task "postgresql" { volume_mount { volume = "pgdata" destination = "/var/lib/postgresql/data" } # ... rest of task config } ``` ## Security Notes - Default credentials are for development only - For production, use Nomad variables or a secrets manager - Consider network policies to restrict database access ## License MPL 2.0