How to Deploy from Monorepos

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 run-time, 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 run-time, only files inside the source directory are accessible. Therefore, if your app needs to access files outside its subdirectory at run-time, 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.

    • Click Scale to select a plan and instance size you would like to use when a container is created from the image.
    • Click the edit icon corresponding to the resource to configure details such as 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 new resources by selecting the type of resource in the Resource Type section and then click Create. If your app needs a database, you can add a dev database or an existing managed database from your DigitalOcean account. The connection details for your database will be accessible via environment variables so that they can be conveniently accessed in your code.

    Click Next.

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

  3. Enter a name for your app and choose the region where you would like your app to be hosted. 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 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.
The build and run commands are the command-line statements that compile your app resource at build time and launch your app resource after it has been built, respectively.
A region is a physical location in the world where DigitalOcean has a datacenter that can run your App Platform app.
Scaling is the process of adding more capacity to a resource in your app, either horizontally (more containers) or vertically (more CPU and memory per container).