Skip to content

xebia/ovhcloud-simple-static

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🚀 OVHcloud Static Next.js Site Experiment

This project is an experiment for deploying a static Next.js app to OVHcloud Object Storage using Terraform. It's a playground for cloud, infra-as-code, and static hosting. 😸

✨ Features

  • Next.js app for the frontend
  • Terraform for managing OVHcloud resources
  • CDN for global content delivery and caching
  • Makefile for easy commands

🏢 Project Structure

.
├── nextjs-app/         # Your Next.js frontend app
├── terraform/          # Terraform config for OVHcloud infra
├── Makefile            # Root orchestrator for all tasks
├── README.md           # This file

🛠️ Prerequisites

⚡ Quickstart

The following steps will take you through a simple flow to set up and deploy a static app to a bucket in OVHcloud.

  1. Configure Terraform Variables

    • Copy the example secrets file:
      cp terraform/secrets.tfvars.example terraform/secrets.tfvars
    • Get your API key from OVH Cloud
    • Enter your OVHcloud API credentials in terraform/secrets.tfvars.
    • CDN cache rules in terraform/cdn_cache_rules.tf if you want to customize caching behavior.
    • The default CDN domain provided by OVHcloud will be shown in the Terraform outputs after deployment.
  2. Initialize Terraform

    make tf-init
  3. Install Next.js App Dependencies

    make app-install
  4. Plan and Apply Terraform

    make tf-plan   # See what will be created
    make tf-apply  # Actually create the resources
  5. Build the (static) Next.js App

    make app-build
  6. Setup OVHcloud AWS CLI profile for uploading

    make setup-profile
  7. Deploy to OVHcloud

    make deploy

🧰 Makefile Commands

Run these from the project root:

  • make tf-init – Initialize Terraform
  • make tf-plan – Preview Terraform changes
  • make tf-apply – Apply Terraform changes
  • make tf-destroy – Destroy all Terraform-managed resources
  • make app-install – Install Next.js dependencies
  • make app-build – Build the Next.js app
  • make app-dev – Run the Next.js dev server
  • make setup-profile – Set up the AWS profile to deploy the app
  • make deploy – Deploy the application to OVHcloud Object Storage

🛜 CDN purpose

The CDN provides several advantages over serving directly from S3:

  • Usual CDN advantages: Content caching, DDos Protection, faster loading
  • Content Mapping: The CDN will map item with extensions to friendly urls: /index.html > /

Cache Rules

The CDN is configured with optimized cache rules, which you can edit in terraform/cdn_cache_rules.tf. You can add, remove, or change rules in that file to fit your needs.

CDN Domain

  • OVHcloud will provide a default CDN domain for you (see Terraform outputs after deployment).

🤔 Why Not SST or Pulumi?

  • SST is awesome for AWS Lambda/serverless, but doesn't support OVHcloud or S3-compatible object storage as a first-class target. It's overkill for a static site on OVHcloud and some of the best features (like sst.aws.Nextjs in our case) aren't supported for OVHcloud. SST is designed for serverless architectures with Lambda, API Gateway, and other AWS services - perfect for dynamic apps but unnecessary complexity for a static site that just needs object storage.
  • Pulumi requires a Pulumi Cloud account and backend service for state management (unlike Terraform which can work locally with local state files). The OVHcloud provider is not as mature or well-documented as Terraform's. For simple, reproducible infra, Terraform is the most reliable and community-supported option for OVHcloud right now.
  • Terraform is boring, but boring is good when you want your infra to just work. 😎

About

This project is an experiment for deploying a static Next.js app to OVHcloud Object Storage using Terraform.

Resources

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published