How to Deploy from Monorepos

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.


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

Deploy Using Monorepo as the Source

  1. Visit the Apps page and click Create App.

  2. Select the GitHub repository that contains your source code and specify the branch or tag in your repository that contains your app’s source code.

  3. In the Source Directory field, specify the folder that contains the source.

    If your app needs to access files outside of its subdirectory at runtime, use / as the source directory.

    At the beginning of the build, the entire repo is cloned to /workspace. When you specify a source directory, it is used as the working directory for the entire build instead of /workspace. Files outside of the selected source directory are accessible only during the build. At runtime, only files inside the source directory are accessible. Therefore, if your app needs to access files outside its subdirectory at runtime, you should not specify a source directory and instead adjust the build and run commands using cd <subdirectory> directives as needed.

If you’d like to automatically re-deploy your app when pushing to this branch/tag, select Autodeploy and click Next.

  1. Configure resources for your app.

    • On the Resources page, click the Edit link beside app resource components to configure their details such as the component’s instance size (the container size and its cost), HTTP routes, the run command, or the HTTP port. App Platform displays build and run commands that it detected, 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.
    • Add additional resources by expanding the Add Resource (Optional) section and selecting the Detect from Source Code option. Then, click Add. If your app needs a database, select the Database option to add a dev database or an existing managed database from your DigitalOcean account. The connection details for your database are accessible via environment variables so that you can access them in your code.

    Click Next.

  2. If you want to use resource- and app-level environment variables, on the Environment page, click Edit to supply them. Click the Encrypt checkbox to ensure a variable’s value is encrypted in the App Spec. Click Next.

  3. If you want to change the default name or project for your app, or choose the region where you would like your app to be hosted, click Edit on the Info page. Click Save and then click Next.

    • The option to select a region is not available for static sites. Static components are served on DigitalOcean’s global CDN.
  4. Review your app’s resources, environment variables and billing information on the Review page 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.

Deploy Apps from Node.js Monorepo

For Node.js monorepos, you need to configure the build and run commands as follows when creating the app:

  • For YARN Workspaces:

    1. Edit the Build Command section and add the following:
    cd <path-to-source-subdirectory>
    yarn build
    
    1. Edit the Run Command section and add the following:
    cd <path-to-source-subdirectory>
    yarn serve
    
  • For Lerna and npm, Lerna and YARN, or Lerna and YARN Workspaces:

    1. Add lerna bootstrap to the scripts property in the package.json file:
    "scripts": {
        "bootstrap": "lerna bootstrap",
        "postinstall": "lerna bootstrap"
    }
    
    1. Edit the Build Command section and add the following:
    yarn bootstrap
    cd <path-to-source-subdirectory>
    yarn build
    
    1. Edit the Run Command section and add the following:
    cd <path-to-source-subdirectory>
    npm run serve
    

Sample Monorepos

We provide the following sample monorepos that you can deploy using App Platform:

  • sample-monorepo: A sample monorepo GitHub repository where each subdirectory is an independent app.
  • sample-yarn-workspaces-monorepo: A sample Node.js monorepo GitHub repository that uses Yarn workspaces and has an app with dependencies outside its subdirectory.
  • sample-yarn-lerna-monorepo: A sample Node.js monorepo GitHub repository that uses Lerna and has an app with dependencies outside its subdirectory.