# Example PostgreSQL job file: https://github.com/GuyBarros/nomad_jobs/blob/master/postgresSQL.nomad
job "postgres" {
datacenters = ["dc1"]
type = "service"
group "postgres" {
count = 1
volume "postgres-data" {
type = "host"
read_only = false
source = "postgres-data"
}
network {
mode = "bridge"
# port "db" {
# static = 5432
# to = 5432
# }
service {
name = "postgres"
port = "5432"
# check {
# name = "alive"
# type = "tcp"
# interval = "10s"
# timeout = "2s"
connect {
sidecar_service {}
task "postgres" {
driver = "docker"
config {
# ports = ["db"]
image = "postgres"
volume_mount {
volume = "postgres-data"
destination = "/var/lib/postgresql/data"
template {
# Consul Template only works in template stanza.
# We need it to fetch secret values from Consul.
# The "env = true" parameter sets the environment with the data.
# "destination" key is required but its value doesn't matter.
data = <<EOH
POSTGRES_USER = "{{ key "secrets/postgres/user" }}"
POSTGRES_PASSWORD = "{{ key "secrets/postgres/password" }}"
EOH
destination = "secrets/env.env"
env = true
change_mode = "restart"
env {
PGDATA = "/var/lib/postgresql/data"
# resources {
# # cpu = 1000
# # memory = 1024
# network {
# # mbits = 10