Question

App Platform support for `release` process in Procfile or npm postinstall

Posted January 20, 2021 845 views
Node.jsDigitalOcean App Platform

I have come to DO App Platform from Heroku, and one teething problem i’ve had, is running processes after release, or during release for a Node.js app. Specifically running migrations .

In the past I’ve used postinstall, which usually works, but more recently I’ve used the release process type in a Procfile, which makes more sense.

DO doesn’t seem to support the release process type, but I wonder if i’m using it wrongly for DO?

web: npm start
release: npm run migrate

Also, I get unexpected behaviour using the postinstall method, as DO doesn’t run npm install when it has a cache of the node_modules I presume from package-lock.json.

I tried using a appspec.yml file, with an added build_command, and building via doctl apps create-deployment, but that doesn’t appear to run the postinstall command either.

  build_command: npm install --production

Any ideas?! :)

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.

×
Submit an Answer
1 answer

The build_command is run once when commits are pushed to your repo, or in some cases when changes (ex. environment variables or changing the build command itself) are made to your apps configuration.

A good option for running migrations is the pre-deploy and post-deploy job types. These are run just before or just after launching your application containers. If the job fails, your app will be rolled back to its previous version. These run in a separate, short-lived container from your application so they have their own resource allocation and won’t steal CPU or memory from your application.

We strongly recommend against running migrations directly in the service container via run_command (ex. npm run migrate && npm run start). Running in the service container means the migration could run several times (potentially concurrently) based on the component’s instance count. Also, this (anti-)pattern slows the start of your application, which could potentially cause it to fail health checks at deploy, or if ever restarted.

See: How-to Manage Jobs for details on creating and configuring jobs.

I’ll file an internal feature request for directly supporting the release procfile option.