DEV Community

loading...
Cover image for Strapi QuickStart on DigitalOcean App Platform

Strapi QuickStart on DigitalOcean App Platform

thewdhanat profile image Thew Dhanat ใƒป2 min read

This is the first article of the series Trying DigitalOcean App Platform which is part of DigitalOcean App Platform Hackathon

In this post, I will deploy a Strapi quickstart to DigitalOcean App Platform.

Setup strapi

Create a strapi project in to my-project directory.

npx create-strapi-app my-project --quickstart
Enter fullscreen mode Exit fullscreen mode

The quickstart project will use a local sqlite as a database. The default sqlite database file is at ./.tmp/data.db.

After the project has been created, the browser will be opened with admin setup page automatically. The admin user and content you create at this step will be available only on your computer since it is stored in local sqlite.

Admin setup page

Production database config

To tell Strapi to use DigitalOcean database when we deploy it, create the following ./config/env/production/database.js file.

module.exports = ({ env }) => ({
  defaultConnection: "default",
  connections: {
    default: {
      connector: "bookshelf",
      settings: {
        client: "postgres",
        host: env("DATABASE_HOST", "localhost"),
        port: env.int("DATABASE_PORT", 5432),
        database: env("DATABASE_NAME", "strapi"),
        username: env("DATABASE_USERNAME", "strapi"),
        password: env("DATABASE_PASSWORD", "strapi"),
        ssl: {
          ca: env("DATABASE_CA", ""),
        },
      },
    },
  },
});
Enter fullscreen mode Exit fullscreen mode

Develop Strapi

Develop Strapi as usual. If you are new to Strapi, you can try Quick Start Guide

Push code to GitHub repository

For example, here is my repository.

Launch DigitalOcean App

  1. Go to DigitalOcean App Platform Console and choose the repository. Choose the repository
  2. Choose the region that is close to your user Choose region
  3. Set the following environment variables and change HTTP port to 1337. Notice the db prefix in environment variables.
    • NODE_ENV = production
    • DATABASE_HOST = ${db.HOSTNAME}
    • DATABASE_PORT = ${db.PORT}
    • DATABASE_NAME = ${db.DATABASE}
    • DATABASE_USERNAME = ${db.USERNAME}
    • DATABASE_PASSWORD = ${db.PASSWORD} (Encrypt)
    • DATABASE_CA = ${db.CA_CERT}Set enivronment variables and HTTP port
  4. Add database, set its name to db. The name must be the same as the prefix you used in environment variables.Add database
  5. Choose your plan and container size. The lowest cost plan is $12 (Basic $5/mo). Then launch your Strapi App! ๐ŸŽ‰ Choose pricing plan

Congratulations! ๐ŸŽŠ

The Strapi application is being deployed and will be ready in around 10 minutes. You can visit https://<your-url>/admin to setup production admin account.

Buy Me A Coffee

Discussion (0)

Forem Open with the Forem app