How to Deploy Your Gridsome Site

Gridsome is a modern Vue-powered static site generator that helps you build fast, SEO-friendly websites using GraphQL and Vue components. In this guide, we’ll walk you through deploying a Gridsome project to an Ubuntu server using CloudRay, a platform that helps you manage your infrastructure and automate deployments using reusable Bash scripts.

This guide assumes you already have a Gridsome project set up. If not, check out the Getting Started Guide to scaffold your project.

Contents

Adding Servers to CloudRay

Before getting started, make sure your machine is added to a CloudRay project and connected using the CloudRay Agent.

Create a Deployment Script

Now that your machine is connected to CloudRay, let’s create a reusable Bash script to automate the deployment process. You need to follow these steps to create the script in CloudRay.

Screenshot for deployment script of Gridsome site
  1. Go to Scripts in your CloudRay project
  2. Click New Script
  3. Name: Deploy Gridsome Site. You can give it any name of your choice
  4. Copy this code:
#!/bin/bash

# Exit on error
set -e

echo "📦 Updating system and installing dependencies..."
sudo apt update && sudo apt install -y \
    curl git nginx build-essential make gcc g++ python3 libvips-dev

echo "🧰 Installing Node.js LTS..."
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt install -y nodejs

echo "🚀 Installing global packages..."
sudo npm install -g pm2

echo "📁 Cloning Gridsome repo..."
git clone "{{repo_url}}" "{{app_name}}"
cd "{{app_name}}"

echo "📦 Installing project dependencies..."
npm install

echo "🏗️ Building the Gridsome app..."
npm run build

echo "📡 Serving with PM2 on port $PORT..."
pm2 start "npx serve dist -l {{port}}" --name "{{app_name}}"
pm2 save
pm2 startup

echo "🌐 Configuring Nginx reverse proxy..."
NGINX_CONF="/etc/nginx/sites-available/{{app_name}}"
sudo tee "$NGINX_CONF" > /dev/null <<EOF
server {
    listen 80;
    server_name {{domain}};

    location / {
        proxy_pass http://localhost:{{port}};
        proxy_http_version 1.1;
        proxy_set_header Upgrade \$http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host \$host;
        proxy_cache_bypass \$http_upgrade;
    }
}
EOF

echo "🔗 Enabling Nginx config and restarting..."
sudo ln -sf "$NGINX_CONF" /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx

echo "✅ Deployment complete! Access your site at http://{{domain}}"

Here is what the Deploy Gridsome Site does:

  • Installs system dependencies and Node.js
  • Clone your Gridsomeproject from a Git repository
  • Build the project
  • Serves the site with PM2
  • Sets up Nginx as a reverse proxy

Define the Variable Group

To make this script reusable across multiple projects or servers, you’ll define a variable group inside CloudRay. These variables dynamically fill in the placeholders like {{repo_url}}, {{app_name}}, {{port}} and {{domain}}. CloudRay processes all scripts as Liquid templates.

Screenshot of adding a new variable group

To ensure that these values are automatically substituted when the script runs, follow these steps to create a variable Group:

  1. Navigate to Variable Groups: In your CloudRay project, go to “Scripts” in the top menu and click on “Variable Groups”.
  2. Create a new Variable Group: Click on “Variable Group”.
  3. Add the following variables:
  • repo_url: The URL of your GitHub repository
  • deploy_dir: Your Gridsome deployment directory
  • clone_dir: This is the name of the GitHub repository

Since the variables is setup, proceed with running the scripts with CloudRay

Run the Deployment Script

CloudRay uses Runlogs to execute scripts on your servers while providing real-time logs of the execution process.

Once the script is saved, you can deploy your Gridsome site by creating a Runlog:

  1. Navigate to Runlogs: In your CloudRay project, go to the Runlogs section in the top menu.
  2. Create a New Runlog: Click on New Runlog.
  3. Configure the Runlog: Fill in the required details:
  • Server: Select the server you added earlier.
  • Script: Choose the “Deploy Gridsome Site”
  • Variable Group (optional): Select the variable group you created earlier.
Screenshot of creating a new runlog
  1. Execute the Script: Click on Run Now to start the execution.
Screenshot of the output of the Gridsome deployment script

CloudRay will automatically connect to your server, run the Deploy Gridsome Site, and provide live logs to track the process. If any errors occur, you can review the logs to troubleshoot the issue.

Once the deployment is complete, you can visit http://<your_domain>. You should see your Gridsome site up and running

Screenshot showing Gridsome Site running

Next Step

To improve your deployment and security:

  • You can use Let’s Encrypt to add HTTPS support
  • Set up automatic redeployment with webhooks or CI/CD

Summary

With CloudRay, deploying your Gridsome site to Ubuntu becomes a structured and repeatable process. Scripts remain organised, server access is centralised, and you can easily tweak configurations with variable groups.

For more deployment guides and use cases, check out our CloudRay Guides or explore the CloudRay Docs.

Avatar for Olusegun Durojaye

Written by Olusegun Durojaye
CloudRay Team