I'm looking for a way to run a single job when I d...
# kubernetes
d
I'm looking for a way to run a single job when I do
pulumi up
. I read somewhere that I should do a CronJob without a schedule but the typescript didn't like that. Any other suggestions?
l
You mean you want to run a Kubernetes Job each time you run
pulumi up
?
d
@limited-rainbow-51650 yes, exactly! It doesn't have to be a cronjob per se but I want to run something on each
pulumi up
. I tried working with
initContainers
but that runs every time a new pod is created.
I also tried creating a job with
suspend: true
after googling a bit but that just didn't create a single job, I guess I would have to change it to true after the first run or something
l
At the moment, I lack a suggestion. Can you elaborate on your use case? Maybe it is possible to find a non-Pulumi alternative.
d
Of course! I'm in the process of moving our Magento2 server to Kubernetes and on deploys I need to run a few commands, for example
bin/magento setup:db-schema:upgrade
which is basically a db-migration. I only want to run this once per deploy. When I say "deploy" I mean
pulumi up
l
@dazzling-sundown-39670 I usually keep the db migrations out of a declarative Pulumi stack. Such an action is more imperative. When you build your infrastructure over multiple Pulumi projects/stack, the orchestrations happens more on a “workflow” level. Have a look at the recently announced alpha of the
Automation API
. See the #announcements channel for more info.
Other multi-step delivery tooling I have in view are tools like Spinnaker (https://spinnaker.io/) or ArgoCD (https://argoproj.github.io/argo-cd/)
d
Okay thanks, that looks like a bit more work than I was hoping for but I'll look into it!
l
@dazzling-sundown-39670 try ArgoCD first. Spinnaker is a beast… 😉
d
Cheers!
l
@dazzling-sundown-39670 db migrations as a part of updates was definitely something we had in mind when designing automation api. Feel free to join us in #automation-api or reach out to me directly if you want some pointers.
b
@dazzling-sundown-39670 have you tried using a standard job, not a cronjob?
d
@lemon-agent-27707 cheers, I'll check it out! @billowy-army-68599 I haven't, but now I will! Thank you!
So what I ended up doing was creating a
Job
which ran my migrations and then I had my
Deployment
have a dependency on that Job. Seems to work out great. Will definitely look into the automation API when it comes with Typescript support but this seems to work out great for now!
b
a job is one solution, also take a look at schemahero for a more robust solution: https://github.com/schemahero/schemahero
👍🏼 2