floryn90 / docker-hugo

Truly minimal Docker images for Hugo open-source static site generator.
https://hub.docker.com/r/floryn90/hugo
MIT License
31 stars 1 forks source link

Onbuild image ignoring part of `HUGO_CMD` env #92

Closed Timmy1e closed 3 months ago

Timmy1e commented 3 months ago

Hi, I created an issue in the past about the --enableGitInfo flag which was an issue on my end. But when I pass --minify or set a log level using --logLevel info using the onbuild image it doesn't work. My project doesn't contain a .hugo-onbuild.sh file, and I use the following Dockerfile:

FROM docker.io/floryn90/hugo:ext-alpine-onbuild AS build
ENV HUGO_CMD="--enableGitInfo --minify --logLevel info"
ENV HUGO_ENV_ARG="production"

FROM docker.io/nginx:mainline-alpine as final
WORKDIR /usr/share/nginx/html/
RUN rm -rf * .??*
COPY .docker/nginx.conf   /etc/nginx/conf.d/default.conf
EXPOSE 80
COPY --from=build /target /usr/share/nginx/html

With the relevant log section:

[build 4/1] RUN if [ -e ".hugo-onbuild.sh" ]; then exec sh .hugo-onbuild.sh; else exec hugo $HUGO_CMD; fi
0.412 Start building sites … 
0.412 hugo v0.123.8-5fed9c591b694f314e5939548e11cc3dcb79a79c+extended linux/amd64 BuildDate=2024-03-07T13:14:42Z VendorInfo=gohugoio
0.412 
972.5 
972.5                    | EN |  NL   
972.5 -------------------+----+-------
972.5   Pages            | 36 |   89  
972.5   Paginator pages  |  0 |    9  
972.5   Non-page files   |  5 |  507  
972.5   Static files     |  0 |    0  
972.5   Processed images | 14 | 1480  
972.5   Aliases          | 14 |   29  
972.5   Cleaned          |  0 |    0  
972.5 
972.5 Total in 972135 ms
DONE 972.9s

But when I locally run Hugo with the same parameters it does minify and print info level messages.

hugo --enableGitInfo --minify --logLevel info

Which results in the following logs:

Start building sites …
hugo v0.123.8-5fed9c591b694f314e5939548e11cc3dcb79a79c+extended darwin/arm64 BuildDate=2024-03-07T13:14:42Z VendorInfo=brew

INFO  build:  step process substep collect files 540 files_total 540 duration 36.209875ms
INFO  build:  step process duration 36.259667ms
INFO  build:  step assemble duration 2.588583ms
INFO  build:  step render substep pages site en outputFormat html duration 33.130625ms
INFO  build:  step render substep pages site en outputFormat rss duration 1.188958ms
INFO  build:  step render substep pages site nl outputFormat html duration 5m27.3843195s
INFO  build:  step render substep pages site nl outputFormat rss duration 5.4205ms
INFO  build:  step render pages 134 content 77 duration 5m27.425049875s
INFO  build:  step postProcess duration 9.958µs
INFO  build:  duration 5m27.46399s

                   | EN |  NL
-------------------+----+-------
  Pages            | 36 |   89
  Paginator pages  |  0 |    9
  Non-page files   |  5 |  507
  Static files     |  0 |    0
  Processed images | 14 | 1480
  Aliases          | 14 |   29
  Cleaned          |  0 |    0

Total in 327471 ms

The local index.html is 4.0kB and minified. The onbuild index.html is 12kB and has a lot of empty lines.

I have the result of the listed Dockerfile running on a public server, where you can see that the HTML is not being minified.

floryn90 commented 3 months ago

hi @Timmy1e, Did you configured the minify option into config.toml?

Please refer to https://gohugo.io/getting-started/configuration/#configure-minify in order to configure it if not done already!

Timmy1e commented 3 months ago

I used the default settings (no minify object) and just pass the --minify flag.

I added this and it worked.

minify:
  minifyOutput: true

It is strange that it works locally without this in the config. But it still doesn't honour the --logLevel.

floryn90 commented 3 months ago

Hi @Timmy1e, Could you check if you have the docker buildx option —progress as per docker documentation: https://docs.docker.com/reference/cli/docker/buildx/build/#progress

Timmy1e commented 3 months ago

Setting --progress=plain doesn't fix it, this is the relevant output:

#15 [build 4/1] RUN if [ -e ".hugo-onbuild.sh" ]; then exec sh .hugo-onbuild.sh; else exec hugo $HUGO_CMD; fi
#15 0.387 Start building sites …
#15 0.387 hugo v0.124.1-db083b05f16c945fec04f745f0ca8640560cf1ec+extended linux/amd64 BuildDate=2024-03-20T11:40:10Z VendorInfo=gohugoio
#15 0.387
#15 723.3
#15 723.3                    | EN |  NL
#15 723.3 -------------------+----+-------
#15 723.3   Pages            | 36 |   89
#15 723.3   Paginator pages  |  0 |    9
#15 723.3   Non-page files   |  5 |  507
#15 723.3   Static files     |  0 |    0
#15 723.3   Processed images | 14 | 1480
#15 723.3   Aliases          | 14 |   29
#15 723.3   Cleaned          |  0 |    0
#15 723.3
#15 723.3 Total in 722955 ms
#15 DONE 725.6s
floryn90 commented 3 months ago

hi @Timmy1e, As per onbuild image documented here - https://github.com/floryn90/docker-hugo#using-onbuild-image - the HUGO_CMD should be passed to the docker build as argument and not as env variable!

eg:

docker build --progress plain --build-arg HUGO_CMD="--enableGitInfo --minify --logLevel info" --build-arg HUGO_ENV_ARG="production" .

Example using your Dockerfile where I removed only

ENV HUGO_CMD="--enableGitInfo --minify --logLevel info"
ENV HUGO_ENV_ARG="production"

Which will produce the following output:

#12 0.402 Start building sites …
#12 0.402 hugo v0.124.1-db083b05f16c945fec04f745f0ca8640560cf1ec+extended linux/amd64 BuildDate=2024-03-20T11:40:10Z VendorInfo=gohugoio
#12 0.402
#12 0.415 INFO  build:  step process substep collect files 0 files_total 0 duration 34.2µs
#12 0.415 INFO  build:  step process duration 212.4µs
#12 0.415 INFO  build:  step assemble duration 583.299µs
#12 0.437 INFO  Data for key 'showcase' in path 'homepage.yml' is overridden by higher precedence data already in the data tree
#12 0.437 INFO  Data for key 'about' in path 'homepage.yml' is overridden by higher precedence data already in the data tree
#12 0.437 INFO  Data for key 'education' in path 'homepage.yml' is overridden by higher precedence data already in the data tree
#12 0.437 INFO  Data for key 'experience' in path 'homepage.yml' is overridden by higher precedence data already in the data tree
#12 0.437 INFO  Data for key 'client_and_work' in path 'homepage.yml' is overridden by higher precedence data already in the data tree
#12 0.437 INFO  Data for key 'testimonial' in path 'homepage.yml' is overridden by higher precedence data already in the data tree
#12 0.437 INFO  Data for key 'contact' in path 'homepage.yml' is overridden by higher precedence data already in the data tree
#12 0.437 INFO  Data for key 'newsletter' in path 'homepage.yml' is overridden by higher precedence data already in the data tree
#12 0.447 INFO  build:  step render substep pages site en outputFormat html duration 30.986976ms
#12 0.447 INFO  deprecated: .Site.Author was deprecated in Hugo v0.124.0 and will be removed in a future release. Use taxonomies instead.
#12 0.448 INFO  build:  step render substep pages site en outputFormat rss duration 1.925598ms
#12 0.448 INFO  build:  step render pages 5 content 0 duration 33.130874ms
#12 0.449 INFO  build:  step postProcess duration 750.299µs
#12 0.449 INFO  build:  duration 35.505772ms
#12 0.490 INFO  static: syncing static files to / duration 75.95804ms
#12 0.490
#12 0.490                    | EN
#12 0.490 -------------------+------
#12 0.490   Pages            |   5
#12 0.490   Paginator pages  |   0
#12 0.490   Non-page files   |   0
#12 0.490   Static files     | 150
#12 0.490   Processed images |   0
#12 0.490   Aliases          |   0
#12 0.490   Cleaned          |   0
#12 0.490
#12 0.490 Total in 91 ms
#12 DONE 0.5s