DEV Community

Cover image for Deploying a React App on DigitalOcean App Platform Using GitHub Actions
Glover
Glover

Posted on

Deploying a React App on DigitalOcean App Platform Using GitHub Actions

Deploying a React app on the DigitalOcean App Platform can be streamlined using GitHub Actions. In this article, we'll go through the process of setting up a deployment workflow and automating the deployment using a GitHub Actions workflow file.

Prerequisites:
Before we begin, make sure you have a DigitalOcean Personal Access Token. If you don't have one, follow the instructions provided by DigitalOcean to create a token.

Setting Up the Personal Access Token:

  • Access your GitHub repository and navigate to the repository's Secrets settings.
  • Declare a new secret called DIGITALOCEAN_ACCESS_TOKEN and set its value to your DigitalOcean Personal Access Token. This token will be securely stored and used in the deployment process.

Creating the GitHub Action Workflow:

  • Create a new GitHub Action workflow file or modify an existing one in your repository.
  • Add the following workflow configuration to the file:
name: Deploy app

on:
  push:
    branches:
      - main

jobs:
  build_and_deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout main branch
        uses: actions/checkout@v2

      - name: Use Node.js
        uses: actions/setup-node@v1
        with:
          node-version: '16.x'

      - name: Install dependencies
        run: yarn install

      - name: Test application
        run: yarn test

      - name: Deploy to DigitalOcean
        uses: digitalocean/app_action@main
        with:
          app_name: my_react_app
          token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}

Enter fullscreen mode Exit fullscreen mode

Let's go through the different steps in the workflow:

Checking out the main branch: This step ensures that the workflow operates on the main branch of your repository.

Setting up Node.js: This step sets up the required Node.js environment for the deployment process. We specify the desired Node.js version (in this case, 16.x).

Installing dependencies: This step installs the project dependencies using the yarn install command. Make sure to customize it if you're using a different package manager.

Testing the application: This step runs the tests for your React app using the yarn test command. Adjust this step if you have different testing requirements.

Deploying to DigitalOcean: The final step utilizes the digitalocean/app_action action to trigger the deployment to the DigitalOcean App Platform. Set the app_name parameter to the name of your React app on DigitalOcean. The token parameter fetches the previously set DIGITALOCEAN_ACCESS_TOKEN secret securely.

By following the steps outlined in this article and using the provided GitHub Actions workflow file, you can automate the deployment of your React app on the DigitalOcean App Platform. This streamlined process allows you to focus on developing your app while ensuring efficient and reliable deployments

Top comments (0)