5.2 KiB
Deploying on DigitalOcean App Platform
This is a guide for deploying a Medusa project on DigitalOcean App Platform.
It is assumed, that you are currently running a local instance of Medusa. If not, check out our Quickstart or use
npx create-medusa-appto set up your application in a matter of minutes. For the latter, see this guide for a small walkthrough.
1. Configure Medusa
Before jumping into DigitalOcean, your Medusa application needs to be configured.
Update medusa-config.js
Instead of using a single environment variable for the database, DATABASE_URL, set DB_* variables and declare DATABASE_URL like so:
const DB_USERNAME = process.env.DB_USERNAME;
const DB_PASSWORD = process.env.DB_PASSWORD;
const DB_HOST = process.env.DB_HOST;
const DB_PORT = process.env.DB_PORT;
const DB_DATABASE = process.env.DB_DATABASE;
const DATABASE_URL = `postgres://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_DATABASE}`;
Update module.exports to include the following:
module.exports = {
projectConfig: {
redis_url: REDIS_URL,
database_url: DATABASE_URL,
database_type: "postgres",
store_cors: STORE_CORS,
admin_cors: ADMIN_CORS,
database_extra: { ssl: { rejectUnauthorized: false } }
},
plugins,
};
Update package.json
Update scripts to have the following:
...
"scripts": {
"serve": "medusa start",
"start": "medusa migrations run && medusa develop",
"build": "babel src -d dist --extensions \".ts,.js\""
}
...
Add a newer version of node to engines:
...
"engines": {
"node": "14.x"
}
...
Push changes to your repository
git add .
git commit -m "chore: DigitalOcean setup"
git push origin master
2. DigitalOcean
Sign in to your DigitalOcean Account or create a new one.
3. Create an App
Navigate to the top-right dropdown Create and select Apps.
4. Connect you Git repository
Choose GitHub or GitLab and select the repository that holds your Medusa project. Check Autodeploy code changes, if you want DigitalOcean to deploy on every push to your repository.
It's important, that DigitalOcean is pointing to the directory holding the Medusa store engine as it is only this which that will be deployed (If you followed the quickstart guide this will simply be the created project, and if you used the npx command this will be the backend folder inside of the newly created project).
5. Configure environment variables
The default settings for your app should be sufficient. We only need to change environment variables to hold the following:
DB_USERNAME=${db.USERNAME}
DB_PASSWORD=${db.PASSWORD}
DB_HOST=${db.HOSTNAME}
DB_PORT=${db.PORT}
DB_DATABASE=${db.DATABASE}
REDIS_URL=${redis.DATABASE_URL}
JWT_SECRET=your-jwt-secret
COOKIE_SECRET=your-cookie-secret
Make sure to use actual secrets in a production environment
6. Set up a Database
Click Add a Database. If you named your database instance something different than db, make sure your environment variable reflect this. See our use of db below.
DB_USERNAME=${db.USERNAME}
7. Give your app a name
Enter a name for your app and select the most suitable region for your setup.
8. Finalize the setup
Choose a plan for your App. For just getting started, the Basic plan should be sufficient. For a production environment, the Pro plan is recommended.
Finally, launch the app.
9. Add a Redis Database
The following steps will add a Redis database to your Medusa setup.
- Navigate to the top-right dropdown Create and select Databases
- Select Redis
- Select the same region you chose for your App
- Leave VPC Network as it is
- Choose a name for your Redis Database
Similarly to our other database, if you choose to name Redis something different than redis, you should udpdate the environment variable as well. See our use of redis below.
REDIS_URL=${redis.DATABASE_URL}
- Create the Redis database for your project
10. Configure Redis for your App
- In the navbar on the left, click Apps and select your Medusa App
- Select Settings ➜ Add component ➜ Database
- Select Previously Created DigitalOcean Database
- Select the Redis Cluster created in the previous step
11. Deploy Medusa
If you haven't already, make sure to rebuild and deploy your Medusa App.
12. Try it out!
In DigitalOcean, navigate to your App overview and access your endpoint to try out your new setup.
https://your-endpoint.ondigitalocean.app/health
What's next?
You now have an application running on DigitalOcean. This can be scaled and configured to fit your business needs.
Furthermore, you can deploy a Medusa Admin for your application, such that you can start managing your store from an interface.
- Deploy Admin on Netlify
- Deploy Admin on Gatsby Cloud (Coming soon)