Deploy Hugo static sites on Digitalocean App Platform via Docker

DigitalOcean app platform offers a starter tier, which allows creating up to three static sites for free, in this article, you'll learn how to host Hugo static sites on DigitalOcean by using Docker.
Donate

Become a backer or sponsor to support our work.

Sponsors

Requirements

  • DigitalOcean Account
  • Domain (Optional)

Create Dockerfile

Create the Dockerfile on your site root, let’s take HugoMods Docker image (hugomods/hugo:exts) as an example.

1FROM hugomods/hugo:exts
2
3COPY . /src
4
5# Uncomment below to install dependencies via NPM, it depends on your site.
6# RUN npm i
7
8# Build site.
9RUN hugo --minify 

In this Dockerfile, it copies the site source file to /src, install dependencies (it depends on your site) and build the site.

Create App

  1. Navigate to DigitalOcean Dashboard.
  2. Navigate to the Apps page.
  3. Click the Create App button.
  4. Fill up the form as follows.

Create App

Tweak Resources

In this step, we’ll need to tweak the resources, since currently DigitalOcean app platform Buildpack unable to detect Hugo sites those configured via configuration directory.

Resources

You may see multiple resources as image above shown, you’ll need to remove unnecessary resources except the one in type Dockerfile.

Edit Dockerfile Resources

Since the web services are not free of charge, so we need to edit the Dockerfile resource to be a static site.

  1. Click the Edit button on the right of the Dockerfile resource, then you’ll be navigated to the resource setting panel.
  2. Edit the Resource Type and change it to Static Site.
  3. Edit the Output Directory and set it as /src/public.

Edit Dockerfile resource

Once done, you will get the above similar settings, now let’s click the Back button to check the resources.

If everything goes fine, you should got only one resource, which is in type Static Site | Dockerfile.

Review App

Please reviewing the billing section, you won’t be charged if you deploy not more than 3 static sites.

Please note that exceeded bandwidth (outbound transfer) usage will be charged, read more on pricing.

Deploy App

It’s time to deploy site by clicking the Create Resources button if everything is OK.

What’s Next?

Once the app was created, it will be deployed automatically, you can then check the build logs if something went wrong. You’ll able to customize domain after deploying successfully.