Deploying a Hugo Site
Hugo is a fast and flexible static site generator written in Go. It is known for its speed, ease of use, and powerful templating, making it ideal for building blogs, documentation, and content-driven websites.
This guide explains how to deploy a Hugo application to Klutch.sh, both with and without a Dockerfile. It covers installation, sample code, and deployment steps.
Prerequisites
- Go installed (Download)
- Hugo installed (Install guide)
- Git and GitHub account
- Klutch.sh account
Getting Started: Create a Hugo Site
- Create a new Hugo site:
Terminal window hugo new site my-hugo-sitecd my-hugo-site - Add a theme (example: Ananke):
Terminal window git initgit submodule add https://github.com/theNewDynamic/gohugo-theme-ananke.git themes/anankeecho 'theme = "ananke"' >> config.toml - Create a sample page:
Terminal window hugo new posts/hello-klutch.mdecho 'Hello from Hugo on Klutch.sh!' >> content/posts/hello-klutch.md - Start the development server:
Your site should be running at http://localhost:1313.
Terminal window hugo server
Deploying Without a Dockerfile
Hugo sites are static after build. Klutch.sh can deploy static sites directly.
- Push your Hugo site to a GitHub repository.
- Log in to Klutch.sh.
- Create a new project.
- Create a new app:
- Select your Hugo GitHub repository and branch
- Choose “Static Site” as the app type
- Set build command:
hugo
- Set output directory:
public
- Configure region, compute, and environment variables as needed
- Click “Create” to deploy. Klutch.sh will build and serve your static Hugo site.
Deploying With a Dockerfile
If you need custom server logic or want to use a Dockerfile:
- Add a
Dockerfile
to your project root. Example:# Build stageFROM klakegg/hugo:0.124.1-ext-alpine AS builderWORKDIR /srcCOPY . .RUN hugo# Production stageFROM nginx:alpineCOPY --from=builder /src/public /usr/share/nginx/htmlEXPOSE 80CMD ["nginx", "-g", "daemon off;"] - Push your code (with Dockerfile) to GitHub.
- In Klutch.sh, create a new app and select the Dockerfile option when prompted.
- Set service details and environment variables as needed.
- Click “Create” to deploy. Klutch.sh will build your Docker image and serve your Hugo site via Nginx.
Resources
Deploying Hugo to Klutch.sh is fast and flexible. Use static site deployment for most cases, or Dockerfile for custom setups.