Creation of docker-compose.yaml from a Hugomod template

Hi, I want to be able to deploy using docker compose a website with this theme: https://github.com/razonyang/hugo-theme-bootstrap-skeleton on my private server. I find myself unable to create such a docker-compose.yaml to do so, can someone please help me with it?

I have something like so:

version: '3.8'
services:
  private-website-server:
      build:
         context: .
         dockerfile: Dockerfile
      image: hugomods/hugo:latest
      container_name: private-website-server
      restart: always
      command: "hugo server"
      ports:
        - "6969:1313"
      expose:
        - 6969
      volumes:
         - .:/src

Unfortunately, it shows a crazy error message:

2023-08-22 16:38:41 WARN  no such image can be found in page resources and the static folder: images/logo.webp
2023-08-22 16:38:41 WARN  no such image can be found in page resources and the static folder: images/profile.webp
2023-08-22 16:38:44 ERROR render of "page" failed: "/tmp/hugo_cache/modules/filecache/modules/pkg/mod/github.com/razonyang/hugo-theme-bootstrap@v1.2.2/layouts/_default/baseof.html:12:8": execute of template failed: template: docs/single.html:12:8: executing "docs/single.html" at <partial "head.html" .>: error calling partial: partial "head.html" timed out after 30s. This is most likely due to infinite recursion. If this is just a slow template, you can try to increase the 'timeout' config setting.
2023-08-22 16:38:44 ERROR render of "page" failed: "/tmp/hugo_cache/modules/filecache/modules/pkg/mod/github.com/razonyang/hugo-theme-bootstrap@v1.2.2/layouts/_default/baseof.html:12:8": execute of template failed: template: _default/single.html:12:8: executing "_default/single.html" at <partial "head.html" .>: error calling partial: partial "head.html" timed out after 30s. This is most likely due to infinite recursion. If this is just a slow template, you can try to increase the 'timeout' config setting.
2023-08-22 16:38:44 ERROR render of "page" failed: "/tmp/hugo_cache/modules/filecache/modules/pkg/mod/github.com/razonyang/hugo-theme-bootstrap@v1.2.2/layouts/_default/baseof.html:12:8": execute of template failed: template: _default/contact.html:12:8: executing "_default/contact.html" at <partial "head.html" .>: error calling partial: partial "head.html" timed out after 30s. This is most likely due to infinite recursion. If this is just a slow template, you can try to increase the 'timeout' config setting.
2023-08-22 16:38:44 Built in 74324 ms
2023-08-22 16:38:44 Error: error building site: render: failed to render pages: render of "page" failed: "/tmp/hugo_cache/modules/filecache/modules/pkg/mod/github.com/razonyang/hugo-theme-bootstrap@v1.2.2/layouts/_default/baseof.html:12:8": execute of template failed: template: docs/single.html:12:8: executing "docs/single.html" at <partial "head.html" .>: error calling partial: partial "head.html" timed out after 30s. This is most likely due to infinite recursion. If this is just a slow template, you can try to increase the 'timeout' config setting.

Thank you.

Couldn’t reproduce it, you can consider increacing the timeout in configuration file if there are a lot of pages on your site.

Btw, you may need to change the command as hugo server -p 6969 --bind 0.0.0.0, since the URLs is related to the baseURL (localhost:1313 by default on hugo server), otherwise you may encounter unexpected problems. You’ll need to adjust the ports as well.

version: '3.8'
services:
  private-website-server:
      image: hugomods/hugo:latest
      container_name: private-website-server
      restart: always
      command: "hugo server -p 6969 --bind 0.0.0.0"
      ports:
        - "6969:6969"
      expose:
        - 6969
      volumes:
         - .:/src

image

1 Like

Good day to you @razon, can you show me what are the steps you took to make it happen? I don’t have any pages on the theme, it is literally just what is on the GitHub: GitHub - razonyang/hugo-theme-bootstrap-skeleton: The starter template of Hugo Bootstrap Theme.

Hi, I’m using the same template for testing.

Clone the repo

$ cd /tmp
$ git clone git@github.com:razonyang/hugo-theme-bootstrap-skeleton.git
$ cd hugo-theme-bootstrap-skeleton

Install dependencies

$ npm ci

Docker compose (the compose’s config is same as I posted above)

$ vim docker-compose.yml

$ docker-compose up

It takes less than 2s to start the server on my machine, but according to your logs, Hugo took a long time to start the server.

1 Like

@razon Hi Razon

Thank you for your reply.

I followed exactly as what you had explained in your post but I still encounter this error:

MYCOMPUTER MINGW64 /f/website
$ git clone git@github.com:razonyang/hugo-theme-bootstrap-skeleton.git
Cloning into 'hugo-theme-bootstrap-skeleton'...
remote: Enumerating objects: 7347, done.
remote: Counting objects: 100% (737/737), done.
remote: Compressing objects: 100% (262/262), done.
remote: Total 7347 (delta 442), reused 541 (delta 346), pack-reused 6610
Receiving objects: 100% (7347/7347), 4.60 MiB | 3.65 MiB/s, done.
Resolving deltas: 100% (3616/3616), done.
Updating files: 100% (78/78), done.

MYCOMPUTER MINGW64 /f/website
$ cd hugo-theme-bootstrap-skeleton

MYCOMPUTER MINGW64 /f/website/hugo-theme-bootstrap-skeleton (main)
$ npm ci
npm WARN deprecated @braintree/sanitize-url@3.1.0: Potential XSS vulnerability patched in v6.0.0.

added 514 packages, and audited 515 packages in 2m

47 packages are looking for funding
  run `npm fund` for details

13 vulnerabilities (2 moderate, 11 high)

To address issues that do not require attention, run:
  npm audit fix

To address all issues (including breaking changes), run:
  npm audit fix --force

Run `npm audit` for details.

MYCOMPUTER MINGW64 /f/website/hugo-theme-bootstrap-skeleton (main)
$ vim docker-compose.yaml

MYCOMPUTER MINGW64 /f/website/hugo-theme-bootstrap-skeleton (main)
$ docker compose up
Network hugo-theme-bootstrap-skeleton_default  Creating
Network hugo-theme-bootstrap-skeleton_default  Created
Container private-website-server  Creating
Container private-website-server  Created
Attaching to private-website-server
private-website-server  | hugo: downloading modules …
private-website-server  | hugo: collected modules in 5147 ms
private-website-server  | Watching for changes in /src/{archetypes,assets,content,layouts,package.hugo.json,package.json,static}
private-website-server  | Watching for config changes in /src/config/_default, /src/go.mod
private-website-server  | Start building sites …
private-website-server  | hugo v0.117.0-b2f0696cad918fb61420a6aff173eb36662b406e+extended linux/amd64 BuildDate=2023-08-07T12:49:48Z
private-website-server  |
private-website-server  | ERROR render of "page" failed: "/tmp/hugo_cache/modules/filecache/modules/pkg/mod/github.com/razonyang/hugo-theme-bootstrap@v1.2.2/layouts/_default/baseof.html:12:8": execute of template failed: template: _default/single.html:12:8: executing "_default/single.html" at <partial "head.html" .>: error calling partial: partial "head.html" timed out after 30s. This is most likely due to infinite recursion. If this is just a slow template, you can try to increase the 'timeout' config setting.
private-website-server  | ERROR render of "page" failed: "/tmp/hugo_cache/modules/filecache/modules/pkg/mod/github.com/razonyang/hugo-theme-bootstrap@v1.2.2/layouts/_default/baseof.html:12:8": execute of template failed: template: docs/single.html:12:8: executing "docs/single.html" at <partial "head.html" .>: error calling partial: partial "head.html" timed out after 30s. This is most likely due to infinite recursion. If this is just a slow template, you can try to increase the 'timeout' config setting.
private-website-server  | Built in 83466 ms
private-website-server  | Error: error building site: render: failed to render pages: render of "page" failed: "/tmp/hugo_cache/modules/filecache/modules/pkg/mod/github.com/razonyang/hugo-theme-bootstrap@v1.2.2/layouts/_default/baseof.html:12:8": execute of template failed: template: _default/single.html:12:8: executing "_default/single.html" at <partial "head.html" .>: error calling partial: partial "head.html" timed out after 30s. This is most likely due to infinite recursion. If this is just a slow template, you can try to increase the 'timeout' config setting.
private-website-server exited with code 1
private-website-server  | Watching for changes in /src/{archetypes,assets,content,layouts,package.hugo.json,package.json,static}
private-website-server  | Watching for config changes in /src/config/_default, /src/go.mod
private-website-server  | Start building sites …
private-website-server  | hugo v0.117.0-b2f0696cad918fb61420a6aff173eb36662b406e+extended linux/amd64 BuildDate=2023-08-07T12:49:48Z

Not too sure what is wrong with it, it keeps saying it goes into an infinite recursion. It is quite upsetting because I think your Theme is one of the most beautiful themes on Hugo and I would love to use it for my engineering blog.

Sorry for the lately response.

Does it work when using native Hugo command other than docker-compose? Is the docker-compose work for other themes?

From the logs, there maybe an IO performance issue on your machine.

added 514 packages, and audited 515 packages in **2m**

It takes too long to install the dependencies (2m, NPM) and build the site (Hugo). The former took 25s, and later took 8s on my Windows, Linux should be more faster. GitHub Action is about the same.

Hi @razon, I understand that using command: "hugo server" to run a blog in production is not the best way to do; you have a documentation on how to deploy using Dockerfile [link], can you help me to deploy using docker-compose.yaml as well?

Also, running the Dockerfile itself using docker run gives me this error:

private-website-server  | hugo v0.121.2-6d5b44305eaa9d0a157946492a6f319da38de154+extended linux/amd64 BuildDate=2024-01-05T12:21:15Z
private-website-server  | GOOS="linux"
private-website-server  | GOARCH="amd64"
private-website-server  | GOVERSION="go1.21.5"
private-website-server  | github.com/sass/libsass="3.6.5"
private-website-server  | github.com/webmproject/libwebp="v1.3.2"
private-website-server exited with code 0

This is my current docker-compose.yaml file.

version: '3.8'
services:
  private-website-server:
      image: hugomods/hugo:latest
      container_name: private-website-server
      restart: always
      build:
        # context: .
        dockerfile: Dockerfile
      # command: "hugo server -p 1313 --bind 0.0.0.0"
      ports:
        - "1313:1313"
      expose:
        - 1313
      volumes:
         - .:/src

Thank you!

@razon

Managed to somehow get the Dockerfile to run until the RUN hugo --minify --gc --enableGitInfo command.

My objective is to put the static files in a container, then serve the static files behind a Caddy.

But got this error instead.

------
 > [private-website-server builder 7/8] RUN hugo --minify --gc --enableGitInfo:
2.452 hugo: downloading modules …
2.775 hugo: collected modules in 2324 ms
2.844 Start building sites … 
2.844 hugo v0.111.3+extended linux/amd64 BuildDate=unknown
3.662 WARN 2024/01/21 18:44:53 no such image can be found in page resources and the static folder: consts-ext.png#center
8.319 Total in 7870 ms
8.319 Error: Error building site: failed to render pages: render of "section" failed: "/tmp/hugo_cache/modules/filecache/modules/pkg/mod/github.com/razonyang/hugo-theme-bootstrap@v1.2.2/layouts/docs/list.html:6:4": execute of template failed: template: docs/list.html:6:4: executing "content" at <partial "docs/sidebar" .>: error calling partial: "/tmp/hugo_cache/modules/filecache/modules/pkg/mod/github.com/razonyang/hugo-theme-bootstrap@v1.2.2/layouts/partials/docs/sidebar.html:6:7": execute of template failed: template: partials/docs/sidebar.html:6:7: executing "partials/docs/sidebar.html" at <partial "hooks/docs/sidebar-end" .>: error calling partial: "/src/layouts/partials/hooks/docs/sidebar-end.html:1:9": execute of template failed: template: partials/hooks/docs/sidebar-end.html:1:9: executing "partials/hooks/docs/sidebar-end.html" at <partial "docs/repo" .>: error calling partial: "/tmp/hugo_cache/modules/filecache/modules/pkg/mod/github.com/razonyang/hugo-theme-bootstrap@v1.2.2/layouts/partials/docs/repo.html:15:13": execute of template failed: template: partials/docs/repo.html:15:13: executing "partials/docs/repo.html" at <partialCached "functions/working-directory" .>: error calling partialCached: "/tmp/hugo_cache/modules/filecache/modules/pkg/mod/github.com/razonyang/hugo-theme-bootstrap@v1.2.2/layouts/partials/functions/working-directory.html:5:15": execute of template failed: template: partials/functions/working-directory.html:5:15: executing "partials/functions/working-directory.html" at <os.Getenv>: error calling Getenv: access denied: "PWD" is not whitelisted in policy "security.funcs.getenv"; the current security configuration is:
8.319 
8.319 [security]
8.319   enableInlineShortcodes = false
8.319 
8.319   [security.exec]
8.319     allow = ['^dart-sass-embedded$', '^go$', '^npx$', '^postcss$']
8.319     osEnv = ['(?i)^((HTTPS?|NO)_PROXY|PATH(EXT)?|APPDATA|TE?MP|TERM|GO\w+)$']
8.319 
8.319   [security.funcs]
8.319     getenv = ['^HUGO_', '^CI$']
8.319 
8.319   [security.http]
8.319     methods = ['(?i)GET|POST']
8.319     urls = ['.*']
8.319 
8.319 
------
failed to solve: process "/bin/sh -c hugo --minify --gc --enableGitInfo" did not complete successfully: exit code: 255

That’s expected, since the default command of this image is hugo version, so it prints Hugo version and then exit. To override the default command, you’ll need to append it to the end, e.g. docker run hugomods/hugo hugo server for running a Hugo server.

You’ll need to 1) either upgrade Hugo to v0.112.0 (or later), 2) or append the PWD to security.funcs.getenv.

[security.funcs]
  getenv = ['^HUGO_', '^CI$', 'PWD']

Related notes Release v1.0.2 · razonyang/hugo-theme-bootstrap · GitHub