Skip to content

Deploying Apps to Our CapRover Server

Song Zheng edited this page Mar 5, 2022 · 3 revisions

Background

We maintain a Digital Ocean server to deploy different services app and our database on. Everything that we don't on Vercel. The various apps on this server were either managed or proxied by myProxy. myProxy wasn't an ideal experience and so we decided to replace it with CapRover. CapRover manages deployment and containerization for apps while providing a better development experience and features like automatic ssl management.

Usage

Relevant URL and credentials for the CapRover dashboard and admin controls are available with engineering channel

Deploying new apps on the server can be performed in the following ways:

Deploying as a Docker image

Steps

  1. Dockerize App
  2. Create an App on CapRover
  3. Create a GitHub workflow

1. Dockerize App

Create a Dockerfile for your app. https://github.com/garageScript/c0d3-js5/blob/prod/Dockerfile is a sample file you can for node apps using yarn. Optionally add a .dockerignore file to prevent unnecessary files from being included in the image, like https://github.com/garageScript/c0d3-js5/blob/prod/.dockerignore


2. Create an App on CapRover

  • Name and create your app

image

  • Open the app's details

image

  • Enable https and websocket support as required.
  • If your app needs some environment variables, add them in the App Configs tab

3. Create a GitHub Workflow

  • In your app's GitHub repo, Setup a new workflow.

image

name: 'Deploy to Caprover'

on:
  push:
    branches: [ main ]
  workflow_dispatch:

jobs:
  caprover-deploy:
    runs-on: ubuntu-latest
    steps:
      # Checking out to the correct repo is required  
      - name: Checkout Repository
        uses: actions/checkout@v2
      - name: Deploy to Caprover
        uses: JasirZaeem/caprover-deploy@v1
        with:
          token: ${{secrets.GITHUB_TOKEN}}
          server: ${{secrets.CAPROVER_URL}}
          password: ${{secrets.CAPROVER_PASSWORD}}
          app: "example-app"

GITHUB_TOKEN is an Environment Variable built into GitHub actions, CAPROVER_URL is already set in the garageScript organisation, if working on a repo on your personal profile you will have to add it, same for CAPROVER_PASSWORD

  • Create a pull request with your new workflow, merge it or do it after approval if required, the setups before this must've all been done before you merge it

image`

You are good to go! Your app will now be deployed on [your-app-name].c0d3.com . This is a one time task, All further commits will automatically be built and deployed from here on.


OneClick Apps

CapRover maintains a collection of OneClick apps, if the app you want to deploy is an existing app you can use this method to deploy it. https://caprover.com/docs/one-click-apps.html

image

Name and select the app you want and input the required configurations.

Proxied by CapRover

You can use this method for apps already running on the server or ones you wish to deploy outside caprover.

  • Deploy your app as you would on the server and make note of it's localhost PORT.
  • Once done create a new OneClick app using the Nginx Reverse Proxy image

image

  • Enter the app name and the upstream address of your app. For apps running on the server the upstream address is of the form https://172.17.0.1:PORT where PORT should be replaced with your id you applications port.

image