Define a runtime operation
To define a runtime operation, add a configuration similar to the following: When you define a runtime operation, you can specify which users can trigger it according to their userrole:
viewercontributoradmin
role option when configuring your runtime operation,
by default all users with the contributor role can trigger it.
For example, to allow admin users to clear the cache of a Drupal site,
you could define an operation like the following:
The name of the runtime operation in this case is clear-rebuild.
For more possibilities, see other runtime operation examples.
Run a runtime operation
- In the Console
- Using the CLI
First, make sure that you have defined a runtime operation. Then:
- Navigate to the environment where you want to run the operation.
- Click More.
- Click Run runtime operation.
- Select the operation you want to run.
- Click Run.
List your runtime operations
To list all the runtime operations available on an environment, run the following command:Runtime operation examples
Build your app when using a static site generator
During every Upsun deployment, a standardbuild step is run.
When you use a static site generator like Gatsby
or Next.js with a headless backend
you need to run a second build step to get your app ready for production.
This is because, as its framework is being built,
your frontend needs to pull content-related data from your backend’s API
(to generate all the static HTML pages your site is to serve).
To accomplish this on Upsun, where each app goes through a build-deploy pipeline in parallel,
your frontend’s build must be delayed until after your backend has fully deployed.
It’s often delayed up until the post_deploy hook stage,
when the filesystem is read-only.
You can use a runtime operation to trigger the second build step
after the initial deployment of your app or after a redeployment.
You can also trigger it when you need to fetch content from your backend
but want to avoid going through the whole Upsun build and deploy processes again.
The following examples assume that the frontend and backend containers are included in the same environment.
This isn’t necessary for the commands to run successfully.
What is necessary is that the build destination for your frontend is writable at runtime (meaning, you must define a mount for it). If you don’t want to include a build within a mount (especially if your data source isn’t on Upsun), you can use source operations to achieve a similar effect, but through generating a new commit.
What is necessary is that the build destination for your frontend is writable at runtime (meaning, you must define a mount for it). If you don’t want to include a build within a mount (especially if your data source isn’t on Upsun), you can use source operations to achieve a similar effect, but through generating a new commit.
- Gatsby
- Next.js
To run the Gatsby build step,
define a runtime operation similar to the following:To trigger your runtime operation, run a command similar to the following:
.upsun/config.yaml
Execute actions on your Node.js app
You can define runtime operations for common pm2 process manager tasks.- Ping your app
- Reload your app
- Restart your app
To ping your Node.js app, define a runtime operation similar to the following:To trigger your runtime operation, run a command similar to the following:
.upsun/config.yaml
Define management commands on your Django project
On a Django project, you can define customdjango-admin commands, for example to run a one-off management command (manual migration in the example above) outside of the Django ORM migration framework.
To do so, define a runtime operation similar to the following:
To trigger your runtime operation, run a command similar to the following: