https://pulumi.com logo
d

dazzling-sundown-39670

09/09/2020, 8:47 AM
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

limited-rainbow-51650

09/09/2020, 8:52 AM
You mean you want to run a Kubernetes Job each time you run
pulumi up
?
d

dazzling-sundown-39670

09/09/2020, 8:57 AM
@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

limited-rainbow-51650

09/09/2020, 9:01 AM
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

dazzling-sundown-39670

09/09/2020, 9:04 AM
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

limited-rainbow-51650

09/09/2020, 9:08 AM
@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

dazzling-sundown-39670

09/09/2020, 9:13 AM
Okay thanks, that looks like a bit more work than I was hoping for but I'll look into it!
l

limited-rainbow-51650

09/09/2020, 9:17 AM
@dazzling-sundown-39670 try ArgoCD first. Spinnaker is a beast… 😉
d

dazzling-sundown-39670

09/09/2020, 9:18 AM
Cheers!
l

lemon-agent-27707

09/09/2020, 2:15 PM
@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

billowy-army-68599

09/09/2020, 2:25 PM
@dazzling-sundown-39670 have you tried using a standard job, not a cronjob?
d

dazzling-sundown-39670

09/09/2020, 4:31 PM
@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

billowy-army-68599

09/09/2020, 10:31 PM
a job is one solution, also take a look at schemahero for a more robust solution: https://github.com/schemahero/schemahero
👍🏼 2
8 Views