App Platform is a Platform-as-a-Service (PaaS) offering that allows developers to publish code directly to DigitalOcean servers without worrying about the underlying infrastructure.
App Platform supports running commands during build and run times for web and worker components. You can add these commands during app creation time or after you have deployed the app.
App Platform executes build commands before building your app’s container image. They are usually used to install app dependencies. For example, the npm run build
command installs the dependencies defined in a Node.js package.json
file.
If you do not specify any build commands, App Platform uses the default build command for your app’s language.
App Platform executes run commands after the app’s container has been deployed. They are usually used to configure and start the app. For example, the npm run start
command starts the Node.js server. You can also use run commands to run any additional commands in the container, such as running tests and or connecting to a database.
If you do not specify any run commands, App Platform uses the default run command for your app’s language.
To add build and run commands at app creation time, see the Configure Resource Settings section of the app creation workflow.
To add, edit, or delete buildtime and runtime commands on a deployed app, go to https://cloud.digitalocean.com/apps, click on your app, and click on the Settings tab. Scroll down to the Commands section, then click the Edit link. Two fields are displayed: Build Command and Run Command.
Enter your commands into their respective fields, and click Save. This triggers a redeployment of your app with the new commands.
You can also add, edit, or delete build and run commands for your app from the app’s spec. To do this, download your app’s spec and add the build_command
or run_command
fields to the to the applicable service or work object in the spec, and then upload the spec.
For example, the following spec file defines a build and run command for a service in Go app:
services:
- environment_slug: go
github:
branch: master
deploy_on_push: true
repo: digitalocean/sample-golang
instance_count: 1
instance_size_slug: basic-xxs
internal_ports:
- 8080
name: internal-service
build_command: go build
run_command: bin/sample-golang
You can define environment variables to use in your commands. For example, you can define a DATABASE_URL
environment variable that contains the database connection string and then reference it in your commands as $DATABASE_URL
.
Being that App Platform doesn’t support injecting values as files on disk at build time, you can also use environment variables and run commands to create necessary configuration files on the disk at run time.
For example, MongoDB requires a Certificate Authority (CA) certificate for clients to connect to a cluster, and most MongoDB clients require the certificate to be a file on disk. You can work around the injection limitation by creating an environment variable, such as MONGO_CA_CERT=${db.CA_CERT}
, during the app’s creation process or by updating its settings. Then, you can add a command to the app that creates the certificate file upon runtime, such as echo $MONGO_CA_CERT > ca_cert.cert && <original run command>
. App Platform requires the original run time command to start the app upon runtime.
See How to Use Environment Variables in App Platform for more information on how to set up environment variables for your build and run time commands.