How to Manage Services in App Platform

The usual app creation process will create a service by default; you only need to follow this process if you’re creating another component for your app that needs an internet-accessible endpoint. If your component only needs to be internally accessible, create a internal service instead. If you don’t need this component to be internet-accessible, create a worker instead.

Create a Service

  1. In the Apps section of the DigitalOcean Control Panel, select your app, then click the Actions button and choose Create Resources to add a Web Service.
Resources screen
  1. Select the repository service to retrieve your source code from, either: GitHub, GitLab, DigitalOcean Container Registry, Docker Hub, or a sample app. If you are connecting to your repository from DigitalOcean for the first time, you will need to click the Manage Access button to provide DigitalOcean access to the repositories or containers, then refresh this page.

  2. Select the repository from the Repository drop-down list. Next, select which branch of the source repo you’d like to use as the source. Optionally, for monorepos, specify the folder that contains the source in the Source Directory field. For containers, specify the image tag to use. Click Next.

    App Platform will inspect the code, select an appropriate resource type and also detect any appropriate build and run commands.

    Create resource

    To change to a different resource type, click the edit icon to open the Settings page of the resource. Click the Edit link next to Resource Type, choose another option from the Type drop-down list and click Save. Additionally, you can change the resource’s name, scaling behavior, edit the build and run commands, the HTTP port and request route, and more.

    Specify resource settings
  3. Optionally, if you want to specify additional resources, click the Add Additional Resource From Source link, repeat the procedure and click Next.

  4. If you need to use environment variables, click Edit to the right of the resource name and supply them. Click the Encrypt checkbox to ensure a variable’s value is obscured in all build, deploy, and application logs.

    To specify an app-level environment variable, click Edit to the right of Global. Click Save and then click Next.

    Resources env variables
  5. Review the resources, environment variables and pricing, and click Create Resources.

Note
The service must bind to and expose the HTTP port on the network interface 0.0.0.0 , rather than on the localhost (localhost) or loopback interface (127.0.0.1).

Full HTTP request path preservation for services is not available in the control panel. Instead, set the preserve_path_prefix annotation in the App Spec to true.

Edit a Service

In the Apps section of the DigitalOcean Control Panel, select your app and click on the Settings tab. Click the Web Service you’d like to edit.

You can use the configuration settings you see here to change the Web Service’s scaling behavior, modify environment variables, edit commands, and more.

Destroy a Service

In the Apps section of the DigitalOcean Control Panel, select your app and click on the Settings tab. Click on the Web Service you’d like to destroy.

You can destroy the Web Service by clicking the Destroy Component button on the bottom of the page and entering its name to confirm your selection.

Create an Internal Service

Internal services are not available for creation via the control panel, they need to be created within the App spec. Documentation to deploy via doctl.

Adding another service to your app spec, like so:

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
  run_command: bin/sample-golang

This service has no HTTP port and route, making it inaccessible from the outside world. However, port 8080 is exposed internally making it an internal service. This service can be reached by workers and other services using the component name and the port, which in this example would be http://internal-service:8080. Keep in mind, services that are publicly accessible can function as an internal service as well by defining internal ports.

The build and run commands are the command-line statements that compile your app component at build time and launch your app component after it has been built, respectively.
A container is a single running instance of a service, worker, or static site component shipped on App Platform.
The HTTP route for a service is the publicly-accessible directory path that maps to the root of your service.
In App Platform, a service is a type of component that is both accessible and running server-side code written in a supported programming language, such as Python, Ruby, Go, Node.js, or PHP.