How to Create Apps in App Platform

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 retrieves your app’s code from your linked repository (GitHub or GitLab) or container registry (DOCR or Docker Hub), detects the type of language the app is written in, and deploys the app into an appropriate container environment. App Platform hosts the app at a public URL provided by DigitalOcean and can automatically redeploy the app when it detects changes in the repo.

Creating an App Platform app involves three steps:

  1. Selecting the code base (repository) to pull the code from
  2. Configuring the detected service, such as environment variables and HTTP routes
  3. Choosing the app’s details: its name, region, instance type, and size

You can change the configuration and add more services, static sites, and databases after you create the app.

Note
You must have an Owner or Maintainer permissions-role in any GitHub repository that you want to access from App Platform.

Create Resource From Source Code Using Automation

To create an app using the CLI or API, provide a path to an app spec file (JSON or YAML) as the argument for the --spec flag using the CLI, or provide a spec as a JSON object in the spec field of the App Create API request.

How to create an app using the DigitalOcean CLI

To create an app via the command-line, follow these steps:

  1. Install doctl, the DigitalOcean command-line tool.

  2. Create a personal access token, and save it for use with doctl.

  3. Use the token to grant doctl access to your DigitalOcean account.

                  doctl auth init
                
  4. Finally, create an app with doctl apps create. The basic usage looks like this, but you'll want to read the usage docs for more details:

                  doctl apps create [flags]
                

    The following example creates an app in a project named example-project using an app spec located in a directory called /src/your-app.yaml. Additionally, the command returns the new app’s ID, ingress information, and creation date

                   doctl apps create --spec src/your-app.yaml --format ID,DefaultIngress,Created
                
How to create an app using the DigitalOcean API

To create an app using the DigitalOcean API, follow these steps:

  1. Create a personal access token, and save it for use with the API.

  2. Send a POST request to https://api.digitalocean.com/v2/apps

    cURL

    To create an app with cURL, call:

    
                    curl -X POST \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
      "https://api.digitalocean.com/v2/apps"
      -d '{"spec":{"name":"web-app","region":"nyc", \
      "services":[{"name":"api","github":{"branch":"main",\
      "deploy_on_push":true,"repo":"digitalocean/sample-golang"}, \
      "run_command":"bin/api","environment_slug":"node-js", \
      "instance_count":2,"instance_size_slug":"basic-xxs", \
      "routes":[{"path":"/api"}]}]}}'

    Python

    
                    import os
    from pydo import Client
    
    client = Client(token=os.environ.get("DIGITALOCEAN_TOKEN"))
    
    create_resp = client.apps.create(
        {
            "spec": {
                "name": "web-app",
                "region": "nyc",
                "services": [
                    {
                        "name": "api",
                        "github": {},
                        "run_command": "bin/api",
                        "environment_slug": "node-js",
                        "instance_count": 2,
                        "instance_size_slug": "basic-xxs",
                        "routes": [],
                    }
                ],
            }
        }
    )

Create Resource From Source Code Using the Control Panel

To start creating an app using the DigitalOcean Control Panel, click the Create button and then select Apps from the drop-down menu.

On the Choose Resource From Source Code screen, select the code repository service your app resides on. If you have not previously created an app on App Platform, the repository service prompts you to provide DigitalOcean with read permissions to your account.

Build and deploy your app in the cloud with App Platform.

Select the app’s repo from the Repository drop-down and then select the branch to deploy from in the Branch drop-down menu.

The Source Directory is the directory inside the repo from which to build the app from. The default is the repo’s root directory. If you’re deploying from a monorepo or a container image registry, see Deploy from a Monorepo or How to Deploy from Container Images for more information on how to deploy app’s using these options.

You can choose to opt out of auto-deploying code changes. Uncheck the Autodeploy box to disable App Platform from redeploying the app when it detects changes in the app’s repo.

Once you have selected the app’s repo and branch, click Next. App Platform retrieves your app’s code.

App Platform inspects the code and app resources, and selects an appropriate runtime environment (such as Node, or Ruby). If you need to override this, upload a Dockerfile to your branch and restart the app creation process.

To detect your app, App Platform looks for specific prerequisite files to determine which language your app is written in. For example, if your app is written using NodeJS, App Platform requires one or more of package.json, package-lock.json, and yarn.lock to be present in your app’s root directory to begin a build.

A No component detected error means that App Platform did not find any of the prerequisite files. To fix this, check which prerequisite files are necessary in the buildpack documentation for your app’s language, then add the necessary files to your app’s root directory. If you are deploying a static site, App Platform looks for an index.html file in the root directory of your app.

Resources

Resources are deployable runtime software elements in your app. A resource can be a database, a service, a worker, or a static site. On the Resources page, you can change the plan, configure resource settings or create new resources for your app.

Change Plan

Click the Edit Plan button on the Resources screen to scale the app’s resources.

Scale app

On the Edit Plan screen, you can select one of the following plans as well as scale the app resources vertically by increasing the amount of CPU and memory or horizontally by adding more container instances:

  • Starter - You can only select the Starter plan to host static websites, such as Hugo sites.
  • Basic - Basic plans allow for only one container, vertical scaling, and less outbound transfer and build minutes than the Pro plan. Use the Basic plan for small-scale apps or prototyping your app. Specify the size of the container in the Size section.
  • Pro - The Pro plan includes all of the attributes of the Basic plan and adds more build minutes, horizontal scaling, and high availability. Use the Pro plan to deploy a fully production-ready iteration of your app. Select the number of containers you would like your app to run in the Containers section. Adding additional containers horizontally scales your app to make it more highly available.

Configure Scaling

Under each applicable component on the Edit Plan page, you can set the number of containers the component uses.

Alternatively, enable autoscaling to allow your app to automatically add or remove containers. Autoscaling sets the minimum and maximum number of containers based on the average CPU usage of the app’s containers.

Note
Autoscaling is currently in Early Availability.

See How to Scale Apps in App Platform for more information on scaling.

Autoscaling is only available for app components using dedicated CPUs.

The Web Services menu with a sample app component selected. The component's scaling options are set to autoscale.

As you change the size or the number of containers, the Monthly App Cost section updates to give you an overview of the app’s monthly cost. If you’ve enabled autoscaling, the monthly total becomes a range between the possible minimum and maximum cost per month.

For static sites, the Scale screen displays the number of apps on your account, the static site’s name, and other resources.

After you configure your scaling settings, click Back to go back to the Resources screen.

Configure Resource Settings

To configure the app resource settings, click the edit icon corresponding to the resource on the Resources screen.

App configuration options

App Platform presents several configuration options, several of which may be auto-filled by the app’s detection. You can configure the following options for your app:

  • Name - Unique name for the resource.

  • Resource Type - The type of app to be deployed, either a web service, static site, or worker service. This field determines which additional configuration options are available for your app on this screen.

  • Build Command - Custom build commands to run upon deployment.

  • Run Command - For web and worker services only. You can specify custom run commands for the application to run after deployment. If no run commands are specified, the default run command for your app’s language is used, such as npm start for a Node.js app.

  • HTTP Port - For web services only. The port that the app receives HTTP requests on. The default port is 8080.

  • HTTP Request Routes - For web services and static sites only. The URL path where the app can be accessed, such as your-app-v3cl4.ondigitalocean.app/api. If not specified, the app is accessible from the provided hostname’s root.

  • Output Directory - For static sites only. An optional path to where the build assets are located, relative to the build context. If not set, App Platform automatically scans for these directory names: _static, dist, public, build.

App Platform displays build and run commands that it detects, which you can customize as needed. Refer to the cloud-native buildpacks for instructions for specific buildpacks. For Dockerfile-based builds, entering a run command overrides the Dockerfile’s entrypoint.

After you configure the resource settings, click Back to go back to the Resources screen.

Create New Resources

Once you configure your app, you can optionally create additional resources for the app. In the Create Resource section of the Resources screen, select the type of resource in the Resource Type section.

Add resource
  • For service, worker, or static site: Select the Detect from Source Code option and click Create. Select the resource from your repository, container registry, or sample app and click Next.

  • For database: Select the Database option and click Next. Choose the Dev Database option to connect a small development-level PostgreSQL database to your app and click Create and Attach. We do not recommend using this initial size for production-ready apps, but you can upgrade the database to a production-ready size at a later time. Alternatively, you can select the Previously Created DigitalOcean Database option and click Attach Database to attach an existing DigitalOcean database to your app as a resource. All DigitalOcean database clusters support apps as trusted sources. This creates a secure connection to the database and it accepts traffic only from the app.

The new resources are added to your app and appear on the Resources screen.

New resources added

Once you configure the resources, click Next.

Environment

If your app requires environment variables, such as the app’s URL or database connection strings, you can define them in this section. These can be runtime and build time environment variables. We also provide several app-specific dynamic environment variables that the app can reference. App-level variables can be accessed by all resources in your app.

On the Environment screen, click the corresponding Edit link to specify app-level or resource-specific environment variables. Click the Encrypt checkbox to obscure the variable’s values from all build, deployment, and application logs.

Once you configure the environment variables, click Next.

Info

On the Info screen, click Edit to specify the name of your app and the project your app belongs to. The name can only contain lowercase alphanumeric characters and dashes.

In the Region field, select a datacenter region for the app to reside in. For performance purposes, it is best to select the region geographically closest to the app’s user base.

You cannot select a region for static sites. Static resources are served on DigitalOcean’s global CDN.

Once you enter a name for your app and select a region, click Next.

Review

On the Review screen, review your app’s resources, environment variables and billing information and then click Create Resources.

Once your app deploys, you can view the app at the URL at the top of the app’s Overview page.

The app's provided URL above the Overview page