I have a python batch job that has two tasks. The first task pulls the github code and runs a pip install, and the second task runs the app. How can I find the correct path for the python app to run. Here is my example job config.
The second is that the task dir isn’t found at /local for raw_exec tasks, but the relative path local used in your template and artifact destination is relative to the task working directory .
If you want to want to have a prestart task install software, I’d have it do something like:
job "example-python" {
periodic {
cron = "0 9 * * 1-5"
prohibit_overlap = true
}
datacenters = ["dc1"]
type = "batch"
group "app" {
count = 1
task "setup" {
driver = "raw_exec"
lifecycle {
hook = "prestart"
}
config {
command = "/bin/sh"
args = ["$NOMAD_TASK_DIR}/prestart.sh"]
}
# you could inline this into the args for the command above,
# but it's a little nicer to read and change in the future
# if you do it in a template
template {
data = <-EOT
#!/bin/sh
/usr/bin/pip install -r ${NOMAD_TASK_DIR}/repo/requirements.txt
mv ${NOMAD_TASK_DIR}/repo ${NOMAD_ALLOC_DIR}/repo
EOT
destination = "local/prestart.sh"
}
artifact {
source = "git@github.com:example/daily_quotes.git"
destination = "local/repo"
options {
sshkey = "xxxx"
}
}
}
task "run" {
driver = "raw_exec"
config {
command = "/usr/bin/python"
args = ["${NOMAD_ALLOC_DIR}/repo/app.py"]
}
}
}
}