Deployment in ShipMySaaS

ShipMySaaS provides a fully automated deployment system to quickly deploy your application to your preferred VPS. With Docker, Docker Compose, and a GitHub Action included, deploying your SaaS is streamlined and efficient, saving you valuable time.

Command to run on your VPS only once (for the first time)

  1. Connect to your VPS as the root user.

  2. Change the SSH port on your VPS:

    • Edit the SSH configuration file:
      sudo nano /etc/ssh/sshd_config
    • Locate the line that starts with #Port 22 and change it to your preferred port (e.g., Port 51011). Remove the # at the beginning of the line to uncomment it.
    • Save the file and exit (press Ctrl+X, then Y to confirm, and Enter to save).
    • Restart the SSH service:
      sudo systemctl restart ssh
      # Or
      sudo reboot
  3. Create a non-root user (example: shipmysaas):

    sudo adduser shipmysaas
  4. Install Docker (for Ubuntu):

    a. Set up Docker's repository:

    sudo apt-get update
    sudo apt-get install ca-certificates curl
    sudo install -m 0755 -d /etc/apt/keyrings
    sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
    sudo chmod a+r /etc/apt/keyrings/docker.asc

    b. Add Docker's repository to Apt sources:

    echo \
      "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
      $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
      sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
    sudo apt-get update

    c. Install Docker:

    sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
  5. Add the non-root user to the Docker group:

    sudo usermod -aG docker shipmysaas
  6. Initialize Docker Swarm and create a network:

    docker swarm init
    docker network create --driver overlay web
  7. Create the directory /run/secrets/shipmysaas and set proper permissions:

    sudo mkdir -p /run/secrets/shipmysaas
    sudo chown shipmysaas /run/secrets/shipmysaas
    sudo chmod 700 /run/secrets/shipmysaas
  8. Create an SSH key for password-less connection in the release action:

    ssh-keygen -t rsa -b 4096 -C "[email protected]" -f ~/.ssh/id_rsa
  9. Copy the public SSH key to your VPS:

    ssh-copy-id -i ~/.ssh/id_rsa.pub normal@YOUR_VPS_IP
  10. Copy the private key to your GitHub repository as the VPS_SSH_KEY secret.

Deployment setup

The deployment files are located in the root of the project:

  • docker-compose.yml: Configures your services (backend, frontend, database, etc.).
  • Dockerfile: Builds the Docker image for your application.
  • Release GitHub Action: Automates the deployment process.

This setup enables you to deploy your application in just a few minutes.

Running a release

To deploy your application:

  1. Trigger the release GitHub Action.
  2. Specify the type of release:
    • Patch: For minor fixes.
    • Major: For significant updates.
  3. Choose whether to update:
    • All applications (frontend, backend, etc.), or
    • Specific components (e.g., only the backend).

The GitHub Action will handle the entire process, from building the application to deploying it on your VPS.

Required environment variables

To ensure a successful deployment, you must set the following environment variables in your GitHub repository:

  • CLOUDFLARE_TOKEN: If your domains are managed via Cloudflare. (Adjustments to docker-compose.yml are needed if using another reverse proxy like Traefik.)
  • MONGO_URL: The connection URL for your production MongoDB database.
  • RESEND_SECRET_KEY: For email integration with Resend.
  • STRIPE_SECRET_KEY: For payment processing with Stripe.
  • VPS_SSH_KEY: The private SSH key to connect to your VPS.

Benefits of automated deployment

  • Time-saving: Deploy your application with minimal effort.
  • Consistency: Ensures deployments are repeatable and free from manual errors.
  • Scalability: Quickly update and scale your application as needed.
  • Flexibility: Supports partial or full deployments based on your requirements.