How to run script pre-deployment on AppPlatform


I have an app on App Platform. It is gathering custom logs on local files. Every time I deploy the app, the log files are destroyed (I know this is expected behavior).

I do not want to forward my logs (to Papertrail, Datadog, or Logtail). Instead, I just want to upload them to an online storage service anytime the app redeploys, and I need this to happen BEFORE the redeploy starts and the local files are destroyed. I have coded all the upload functionality into a script that can be called from npm.

My question: Is there a way of telling App Platform to run a certain command before it destroys the local files on a redeploy? I can do it manually via the console but it’s extremely tedious to have to do it every time I merge in a PR or redeploy the app.

A.K.A is there a way of adding a pre-deploy step to the “deploy” pipeline that uses the currently deployed app?

I was looking into Workers, but it seems like they need a separate source, whereas I just want to run a command from within my existing main app component (so it can access the logs).

Thanks for your help!

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Jon Friesen
DigitalOcean Employee
DigitalOcean Employee badge
August 15, 2022

👋 Hi @jhappy77

You can run some cleanup code by monitoring for a termination signal. For example, in a node.js app you could have:

process.on('SIGTERM', () => {'SIGTERM signal received.');

     * This is where cleanup code can be run. For example, closing down the http server.
    console.log('Closing http server.');
    server.close(() => {
        console.log('Http server closed.');


For more information on shutdown sequences in App Platform (which runs on Kubernetes), checkout this article: Kubernetes best practices: terminating with grace

Some additional notes:

  • By the time this signal is given, traffic will no longer be reaching this instance of your app.
  • This cleanup code should execute fairly quickly before the process will be terminated within 30 seconds.
Bobby Iliev
Site Moderator
Site Moderator badge
August 15, 2022

Hi there,

This is not currently an option with the App Platform, but what you could do is to use GitHub actions to run specific actions on every pull request for example:

That way, before merging your pull request, which triggers the deployment on the App Platform side, the GitHub action will run and execute the specific steps that you need. You could for example have an API endpoint that the GitHub action triggers which then starts the upload process of your files.

Hope that this helps!



Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

card icon
Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Sign up
card icon
Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We’d like to help.

Learn more
card icon
Become a contributor

You get paid; we donate to tech nonprofits.

Learn more
Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow – whether you’re running one virtual machine or ten thousand.

Learn more ->
DigitalOcean Cloud Control Panel
Get started for free

Enter your email to get $200 in credit for your first 60 days with DigitalOcean.

New accounts only. By submitting your email you agree to our Privacy Policy.