Skip to main content

Caprover Deployment

Use cases:

  • Setup a selfhosted server to comply with regulation.
  • Reduce vendor lockin for a specific cloud provider.
  • Quickly add, update & remove containers while prototyping.

Prerequisites

  • VPS with 2 Gb RAM, Ubuntu
  • PostgreSQL database credentials
  • DNS wildcard to the VPS (e.g. *.caprover.example.org)
  • DNS record for the api (e.g. api.example.org)
  • DNS record for the admins/caregivers (e.g. example.org)
  • Public IP address of the VPS

Summary

First we setup Caprover, then we add the platform and admin containers. After this we can setup custom integrations.

Replace every instance of example.org with your donain!

Start Caprover server

For the latest instructions, visit the Caprover docs. Below is the short version for Ubuntu.

Sign in on the VPS and run these commands:

# Install Docker
sudo apt-get install -y ca-certificates curl gnupg lsb-release
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
sudo service docker start

# Run Caprover
sudo docker run -p 80:80 -p 443:443 -p 3000:3000 -v /var/run/docker.sock:/var/run/docker.sock -v /captain:/captain caprover/caprover

# Optional commands
sudo usermod -a -G docker ubuntu
sudo ufw allow 22,80,443,4433,3000,996,7946,4789,2377/tcp
sudo ufw allow 7946,4789,2377/udp
sudo ufw enable
sudo apt upgrade -y
sudo apt autoremove -y

# When everything is finished
exit

At this point, we won't have to ssh into server anymore.

Set caprover server password

Open a terminal on your local machine and run npx caprover serversetup

devmachine » npx caprover serversetup
Setup CapRover machine on your server...
? have you already started CapRover container on your server? Yes
? IP address of your server: ***.***.***.***
? CapRover server root domain: caprover.example.org
? new CapRover password (min 8 characters): [hidden]
? enter new CapRover password again: [hidden]
? "valid" email address to get certificate and enable HTTPS: dev@example.org
⠸ Enabling SSL... Takes a few seconds...
? CapRover machine name, with whom the login credentials are stored locally: example

Add caprover apps

  1. Visit https://captain.caprover.example.org/
  2. Login using the password chosen above
  3. Add two apps: healthblocks-platform, healthblocks-api

Healthblocks platform

  1. Visit https://captain.caprover.example.org/#/apps

  2. Go to "Apps" > "healthblocks-platform" > "HTTP Settings" > "Connect New Domain"

    Domain: api.example.org
    Enable HTTPS
  3. Go to "Apps" > "healthblocks-platform" > "App Configs" > "Environmental Variables" and fill in this:

    PORT=80
    INITIAL_SETUP=1
    ORIGIN=https://api.example.org
    ADMIN_URL=https://example.org
    ALLOWED_ORIGINS=https://api.example.org,https://example.org
    APP_SECRET=1234567890abcdef-make-it-random
    DATABASE_URL=postgres://insert-db-credentials
    DEPLOYMENT_ENV=example-prd
    NODE_ENV=production
    SENTRY_DSN=false
  4. Go to "Apps" > "healthblocks-platform" > "Deployment" > "Method 6: Deploy via ImageName"

    image: healthblocks/platform
  5. Click "Deploy now"

Healthblocks admin

  1. Visit https://captain.caprover.example.org/#/apps

  2. Go to "Apps" > "healthblocks-admin" > "HTTP Settings" > "Connect New Domain"

    Domain: example.org
    Enable HTTPS
  3. Go to "Apps" > "healthblocks-admin" > "App Configs" > "Environmental Variables" and fill in this:

    PORT=80
    HEALTHBLOCKS_API=https://api.example.org
    NEXTAUTH_URL=https://example.org
    NEXTAUTH_URL_INTERNAL=http://127.0.0.1
    NEXTAUTH_SECRET=1234567890abcdef-make-it-random
    DATABASE_URL=postgres://insert-db-credentials
    DEPLOYMENT_ENV=example-prd
    SENTRY_DSN=false
  4. Go to "Apps" > "healthblocks-admin" > "Deployment" > "Method 6: Deploy via ImageName"

    image: healthblocks/admin
  5. Click "Deploy now"

Choose authenticator

Visit example.org and configure the first authenticator. If not sure, choose credentials.

Now visit example.org/register and register the first user.

Disable the initial setup phase

This environment variable is only meant to be enabled shortly during initial setup. So let's disable it now:

  1. Visit https://captain.caprover.example.org/#/apps

  2. Go to "Apps" > "healthblocks-platform" > "App Configs" > "Environmental Variables" and update:

    -INITIAL_SETUP=1
    +INITIAL_SETUP=0

Create a new project

At this point, the deployment is ready to go and it's time to create a project!