How to Deploy from Monorepo on DigitalOcean App Platform
Deploy a monorepo to DigitalOcean App Platform by connecting your Git repository, specifying source directories for each service in the control panel, configuring build and run commands, and setting environment variables. For complex multi-service setups, containerize services with Docker to ensure independent scalability and isolation. Expect 1-2 hours for initial setup with autodeploy enabled for faster subsequent deployments.
Prerequisites
- DigitalOcean account with App Platform access
- Git repository (GitHub, GitLab, etc.) hosting your monorepo
- Monorepo structured with clear subdirectories for each service (e.g., /frontend, /api)
- Docker and Docker Compose installed locally for containerizing services
- Environment variables and secrets prepared for each service
Step-by-Step Instructions
Log in and Navigate to App Platform
Go to the DigitalOcean dashboard at cloud.digitalocean.com/apps. Click Create in the top right corner, then select App Platform from the dropdown menu. This opens the app creation wizard where you can begin configuring your monorepo deployment.
Select Repository and Branch
Connect your GitHub or GitLab account if not already linked. Choose the monorepo repository containing your source code. Specify the branch or tag (e.g., main) with your app code. Enable Autodeploy for automatic redeploys on pushes to this branch or tag, then click Next.
Configure Source Directory for Initial Resource
In the Source Directories field, enter the subdirectory for your first service (e.g., frontend for a web app or api for a backend service). Use / for root-level apps or if runtime access to the full repo is needed. The entire repo clones to /workspace at build time; your specified subdirectory becomes the working directory. Files outside the source directory are accessible only during the build phase. If your app needs to access files outside its subdirectory at runtime, adjust build and run commands with cd <subdirectory> directives (e.g., in Run Command: cd api && npm start). Click Next.
Review and Configure Resources Page
App Platform auto-detects the initial resource (e.g., Web Service). Click Edit next to it to configure: Instance size (Basic defaults to 0.25GB RAM, 1 vCPU, ~$5/month; scale later as needed), HTTP Port (auto-detected, e.g., 8080; customize if needed), Run Command (override detected command, e.g., npm run start:prod; for Dockerfiles, this overrides ENTRYPOINT), and Build Command (customize for monorepo, e.g., pnpm install if using PNPM; the Node.js buildpack supports it natively). Expand Add Resource (Optional) > Detect from Source Code > Add for additional services (e.g., /api as another Web Service). Repeat the source directory configuration for each resource. Add Database if needed (dev database or existing managed database; credentials are accessible via environment variables). Click Next.
Set Environment Variables
On the Environment page, click Edit to add app-level or resource-level environment variables (e.g., DATABASE_URL, API_KEY, NODE_ENV). Check the Encrypt checkbox for sensitive values like API keys and database passwords to ensure they are encrypted in the App Spec. Common variables include database connection strings, API endpoints, and feature flags. Click Next.
Configure App Info and Region
On the Info page, click Edit to set the App Name (auto-generated but customizable, e.g., my-monorepo-app, Project (select the project where your app will be deployed), and Region (choose the geographic region closest to your users for optimal performance; note that static sites are served on DigitalOcean's global CDN and region selection is not available for them). Click Next.
Review Deployment Configuration
On the Review page, verify your app's resources, environment variables, billing information, and deployment settings. Review each service's source directory, build command, run command, and instance size. Confirm that all environment variables are correctly set and encrypted where necessary. Once you have verified all settings are correct, click Create Resources to initiate the deployment process.
Monitor Deployment and Access Your App
App Platform automatically builds, deploys, and provisions each container. Monitor the deployment progress in the Overview page, where you can view build logs and deployment status for each service. Once deployment completes successfully, your app is accessible at the URL displayed at the top of the Overview page. Each service operates independently, allowing isolated updates, quicker deployments, and consistent environments across all stages.
Containerize Services with Docker (Optional for Complex Setups)
For advanced multi-service isolation and independent scalability, containerize each service using Docker. Create a Dockerfile for each service specifying its dependencies and runtime environment. Set up a docker-compose.yml file for local development and inter-service communication. In App Platform, select the appropriate registry image and ensure it is correctly tagged and points to the correct Dockerfile within your monorepo. This approach enables better scalability, modular development, and streamlined CI/CD pipelines. Each service operates independently, allowing isolated updates and quicker deployments.
Enable Autodeploy and Monitor Ongoing Deployments
With Autodeploy enabled, your app automatically redeploys whenever you push changes to the specified branch. Monitor deployment history and logs in the App Platform dashboard. Set up alerts for deployment failures and performance issues. For subsequent deployments, the process takes 15-30 minutes with autodeploy enabled, significantly faster than manual redeployments. This structure aligns with modern DevOps principles and provides a solid foundation for adding autoscaling, centralized logging, and API gateways in the future.
Common Issues & Troubleshooting
Build fails with Module not found or pnpm command not found during install
Use the updated Node.js buildpack which supports pnpm natively. Add pnpm install as your build command. Ensure your monorepo uses proper workspace configuration for dependency resolution across services.
Runtime error: Cannot access files outside source directory
Use / as the source directory instead of a subdirectory. Adjust build and run commands with cd <subdirectory> directives (e.g., cd api && npm start). This allows runtime access to the full repository while maintaining proper working directories.
Incorrect source directory specification causes deployment to fail or services to not start
Verify that source directories match your actual monorepo structure (e.g., frontend, api). Use the Detect from Source Code option to automatically identify services. Test locally with Docker Compose before deploying to ensure correct paths and commands.
Environment variables not accessible to services or secrets exposed in logs
Ensure environment variables are set at both app-level and resource-level as needed. Always check the Encrypt checkbox for sensitive values like API keys and database passwords. Verify that variable names match what your application code expects.
Buildpack mismatch or custom build requirements not recognized
Explicitly specify build and run commands in the Resources configuration. For Dockerfile-based builds, entering a run command overrides the Dockerfile's ENTRYPOINT. Refer to cloud-native buildpack documentation for language-specific requirements and customization options.