Created
June 1, 2019 10:52
-
-
Save darkslategrey/d7c477dfb9bee7157ea1a1331141a368 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
job "db" { | |
datacenters = ["dc1"] | |
type = "service" | |
update { | |
max_parallel = 1 | |
min_healthy_time = "10s" | |
healthy_deadline = "3m" | |
progress_deadline = "10m" | |
auto_revert = false | |
canary = 0 | |
} | |
migrate { | |
max_parallel = 1 | |
health_check = "checks" | |
min_healthy_time = "10s" | |
healthy_deadline = "5m" | |
} | |
group "db" { | |
count = 1 | |
restart { | |
attempts = 2 | |
interval = "30m" | |
delay = "15s" | |
mode = "fail" | |
} | |
ephemeral_disk { | |
size = 300 | |
} | |
task "db" { | |
driver = "docker" | |
config { | |
image = "postgres:10.4" | |
port_map { | |
db = 5432 | |
} | |
volumes = [ | |
"local/docker-postgres-init:/docker-entrypoint-initdb.d/docker-postgres-init.sh" | |
] | |
} | |
template { | |
data = <<EOF | |
echo "Creating database '$POSTGRES_TEST_DB' owned by user '$POSTGRES_USER'" | |
psql -v ON_ERROR_STOP=1 --username $POSTGRES_USER -d $POSTGRES_DB <<-EOSQL | |
CREATE DATABASE $POSTGRES_TEST_DB OWNER $POSTGRES_USER; | |
EOSQL | |
EOF | |
destination = "local/docker-postgres-init" | |
} | |
env { | |
POSTGRES_DB = "app" | |
POSTGRES_TEST_DB = "app_test" | |
POSTGRES_USER = "postgres" | |
POSTGRES_PASSWORD = "secret" | |
} | |
resources { | |
network { | |
mbits = 10 | |
port "db" { } | |
} | |
} | |
service { | |
name = "db" | |
tags = ["db"] | |
port = "db" | |
check { | |
name = "alive" | |
type = "tcp" | |
interval = "10s" | |
timeout = "2s" | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment