Deploy app with Hugo site in a subdirectory

Posted November 9, 2020 1.1k views
DeploymentHTMLDigitalOcean App Platform

When deploying a Hugo site as a DigitalOcean app, is there a way to get it working if the hugo site is not at the root of the repository? I have a “site” directory with the hugo site along with other directories at the root.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
2 answers

Hi @hdlopes, this option is currently supported by the app specification, but not the web control panel so you will need to make this change using either doctl or the API.

On your hugo component, set the source_dir option to the name of the subdirectory that your Hugo site lives in. It will then be used as the working directory for the build.

For example:

  - name: hugo
    source_dir: website

See the App Specification reference.

To make this change using doctl, follow these steps:

  1. Install doctl
  2. List your apps and find your app’s UUID: doctl apps list
  3. Save your app’s spec to a file: doctl apps spec get APP-UUID > app.yaml
  4. Open app.yaml in a text editor and add the source_dir property.
  5. Update your app with the new spec: doctl apps update --spec app.yaml APP-UUID. This will kick off a new deployment
  • Thank you @kamaln7!

    The only caveat is that I had to make a workaround commit with the Hugo’s config file on the repository root, so that the “Create App” process could accept it as a Hugo static site.

    After having the app generated on DO all the steps worked fine.

  • What about the case when the app hasn’t been deployed yet and the APP-UUID is not available

    • Hi @leoWhale, you can use this app spec as reference for a Hugo site:

      name: hugo
      - name: hugo
        build_command: hugo -d public
        environment_slug: hugo
        source_dir: website
          repo: digitalocean/sample-hugo
          branch: main
          deploy_on_push: true