I need to run a cache purge on cloudflare after a ...
# kubernetes
i
I need to run a cache purge on cloudflare after a deployment rollout is completed. I was previously doing this with a home-grown (4 year old)
rolloutStatus
typescript fn but it is no longer working. I see the pulumi addition of
local.Command
, but it appears it only executes shell commands. Is there a dependency helper I can use that will allow me to procedurally run some code after a deployment rollout is finished? I’m happy to provide my old code, but I’m hoping there is something easier using
dependsOn
or
Output
resolution.
This appears to be what I want, I’ll try to hack around with a node script executed from the
local.Command
and see if I get the right lifecycle (after deployment rollout) https://github.com/pulumi/pulumi-command/issues/7
b
Command is definitely an option here, but you can likely run that typescript function inside an apply
i
@billowy-army-68599 this is a bit hacky but what I came up with since we cannot run direct functions/callbacks:
Copy code
import { Web } from '@alienfast/pulumi-app'
import { local } from '@pulumi/command'
import { unsecret } from '@pulumi/pulumi'

import { apiKey, email, zoneId } from './cloudflare'
import { rules } from './pageRules'

export function purgeCache(web: Web) {
  const cmd =
    'node --experimental-specifier-resolution=node --loader ts-node/esm --no-warnings src/cmdPurgeCache.ts'

  const urls = Object.keys(rules)
  unsecret(apiKey).apply((key) => {
    const cmdPurgeCache = new local.Command(
      'cmdPurgeCache',
      {
        create: cmd,
        update: cmd,
        environment: {
          'trigger-update': new Date().toISOString(),
          EMAIL: email,
          KEY: key,
          ZONE_ID: zoneId,
          URLS: urls.join(','),
        },
      },
      {
        dependsOn: [web],
      },
    )
  })
}
I had to hack the
Copy code
environment: {
          'trigger-update': new Date().toISOString(),
to make it always run
One thing though, I would really like to see my console output, and I cannot see the results of the command execution. This makes it quite difficult to write/debug something like this
Any way to enable console output for it?
I do see the output in ci via
pulumi up -y --non-interactive --skip-preview