Hugo Module Mounts + Circleci Failing

Hi all,

I have my Hugo project set up with deployment to s3 via Circleci.

Everything is working fine except for Module Mounts.

Here’s my Circleci config:

version: 2.1

commands:
  install_dependencies:
    steps:
      - restore_cache:
          keys:
          - node_modules-{{ .Branch }}-{{ checksum "package.json" }}
          # fallback to using the latest cache if no exact match is found
          - node_modules-{{ .Branch }}-
      - run: sudo apt-get update
      - run: sudo apt-get install hugo
      - run: sudo apt-get install nodejs
      - run: curl -o- -L https://yarnpkg.com/install.sh | bash
      - run: echo 'export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH"' >> $BASH_ENV
      - run: yarn install
      - run: sudo apt-get install awscli
      - save_cache:
          key: node_modules-{{ .Branch }}-{{ checksum "package.json" }}
          paths:
            - ./node_modules

executors:
  init:
    docker:
      - image: circleci/golang:1.12

jobs:
  build:
    executor: init
    steps:
      - checkout
      - install_dependencies
      - run: yarn fetch
      - run: yarn build

  deploy:
    parameters:
      deploy_stage:
        type: string
        default: staging
      bucket:
        type: string
      baseUrl:
        type: string
      hugoEnvironment:
        type: string
        default: test
    executor: init
    steps:
      - checkout
      - install_dependencies
      - run: yarn fetch
      - run: yarn build --baseURL <<parameters.baseUrl>> --environment <<parameters.hugoEnvironment>>
      - run:
          name: Deploy to AWS
          command: aws s3 sync ./projectdirectory/public s3://<<parameters.bucket>> --delete --acl public-read

workflows:
  build-and-deploy:
    jobs:
      # Testing to be added in the future 
      - build
      - deploy:
          name: deploy-prod
          deploy_stage: prod
          bucket: projectdirectory-serverless
          baseUrl: "https://www-new.myproject.com/"
          hugoEnvironment: production
          requires:
            - build
          filters:
            branches:
              only: master
      - deploy:
          name: deploy-staging
          deploy_stage: staging
          bucket: projectdirectory-serverless-staging
          hugoEnvironment: test
          baseUrl: "https://staging-www-new.myproject.com/"
          requires:
            - build
          filters:
            branches:
              only: dev
      - deploy:
          name: deploy-uat
          deploy_stage: uat
          bucket: projectdirectory-serverless-uat
          hugoEnvironment: test
          baseUrl: "https://uat-www-new.myproject.com/"
          requires:
            - build
          filters:
            branches:
              only: uat

The yarn build command is hugo.

In my config.toml I have:

[module]
  
  [[module.mounts]]
    source = "assets/theme/assets/svg"
    target = "static/theme/assets/svg"

  [[module.mounts]]
    source = "assets/theme/assets/vendor/font-awesome/webfonts"
    target = "static/webfonts"

When I run yarn build (hugo) locally, everything builds and the mounted directories in my config.toml are placed into the relevant folders in the site root as expected.

However when Circleci builds, those two folders are missing.

I feel like this is an issue related to Circleci and Go modules, I’m hoping someone with someone can enlighten me.

Thanks in advance.

Hugo Modules were introduced in Hugo v.0.56.0

Which Hugo version is used in the CircleCI environment?

Thanks @alexandros the build script runs sudo apt-get install hugo which should be Hugo v.0.57.2

Are you sure?

If the Linux VM used in CircleCI is Ubuntu 16.04 then the hugo version in the official repo is ancient.

In your command try installing the Hugo binary directly from GitHub via wget.

Ah that would make sense thanks @alexandros, I believe the Circle default Ubuntu version is 16.04.

I will check and report back in this thread for anyone reading in future.

Indeed it is.The following quote is from over here:

If you do not provide any custom images, all machine executor and remote Docker jobs will be run on instances built with one of our default AMIs, which have Ubuntu 16.04…

In Ubuntu 16.04 the available Hugo package in the apt-repo is:

hugo (0.15+git20160206.203.ed23711-1) [universe]
    Fast and flexible Static Site Generator written in Go

So that is why Hugo Modules don’t work in your CicleCI setup.

1 Like

Thanks @alexandros this appears to have been the issue.

For anyone reading in future I updated my config to replace:

- run: sudo apt-get install hugo

With:

- run: wget https://github.com/gohugoio/hugo/releases/download/v0.59.1/hugo_0.59.1_Linux-64bit.deb
- run: sudo dpkg -i hugo_0.59.1_Linux-64bit.deb
1 Like