Simplify the wait_for template usage

This commit is contained in:
Daniel Berteaud 2023-10-30 23:37:11 +01:00
parent 59ccf31656
commit 448197abf9

View File

@ -1,31 +1,37 @@
[[ if and (has . "wait_for") (gt (len .wait_for) 0) -]]
# wait for required services tp be ready before starting the main task
task "wait-for" {
driver = "docker"
user = 1053
config {
image = "[[ .ctx.docker.repo ]][[ .ctx.docker.base_images.wait_for.image ]]"
image = "[[ .docker.repo ]][[ .docker.base_images.wait_for.image ]]"
readonly_rootfs = true
pids_limit = 20
}
lifecycle {
hook = "prestart"
}
env {
[[- range $idx, $service := .wait_for ]]
[[- if $service.service | regexp.Match "\\.$" ]]
SERVICE_[[ $idx ]] = [[ $service.service | toJSON ]]
[[- else ]]
SERVICE_[[ $idx ]] = [[ printf "%s%s.service.%s" $service.service $.ctx.consul.suffix $.ctx.consul.domain | toJSON ]]
SERVICE_[[ $idx ]] = [[ printf "%s%s.service.%s" $service.service $.consul.suffix $.consul.domain | toJSON ]]
[[- end ]]
[[- if has $service "count" ]]
COUNT_[[ $idx ]] = [[ $service.count ]]
[[- end ]]
[[- end ]]
}
lifecycle {
hook = "prestart"
}
resources {
cpu = 10
memory = 10
memory_max = 30
}
}
[[ end ]]