Skip to content

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


Getting Started: Create a Hugo Site

  1. Create a new Hugo site:
    Terminal window
    hugo new site my-hugo-site
    cd my-hugo-site
  2. Add a theme (example: Ananke):
    Terminal window
    git init
    git submodule add https://github.com/theNewDynamic/gohugo-theme-ananke.git themes/ananke
    echo 'theme = "ananke"' >> config.toml
  3. Create a sample page:
    Terminal window
    hugo new posts/hello-klutch.md
    echo 'Hello from Hugo on Klutch.sh!' >> content/posts/hello-klutch.md
  4. Start the development server:
    Terminal window
    hugo server
    Your site should be running at http://localhost:1313.

Deploying Without a Dockerfile

Hugo sites are static after build. Klutch.sh can deploy static sites directly.

  1. Push your Hugo site to a GitHub repository.
  2. Log in to Klutch.sh.
  3. Create a new project.
  4. 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
  5. 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:

  1. Add a Dockerfile to your project root. Example:
    # Build stage
    FROM klakegg/hugo:0.124.1-ext-alpine AS builder
    WORKDIR /src
    COPY . .
    RUN hugo
    # Production stage
    FROM nginx:alpine
    COPY --from=builder /src/public /usr/share/nginx/html
    EXPOSE 80
    CMD ["nginx", "-g", "daemon off;"]
  2. Push your code (with Dockerfile) to GitHub.
  3. In Klutch.sh, create a new app and select the Dockerfile option when prompted.
  4. Set service details and environment variables as needed.
  5. 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.