klakegg/docker-hugo

NPM install

pjbakker opened this issue · 4 comments

For use with TailwindCSS, one needs to install an NPM package before running hugo.
So I have a relevant package.json in my hugo folder next to the Dockerfile.

The current Dockerfiles ignore the package.json.

Is there an easy way to hook the npm install command in an onbuild image use?

You are right about onbuild images ignoring any package.json files, and I'm not a big fan of changing that behaviour. To me this starts with the simple question of choosing between npm and yarn, and a lot of thoughts related to the build process itself.

Adding the full instructions for replacing an onbuild image with a "regular" image doesn't add too much of a burden, however I also see adding support for some kind of triggering of a script could be a wanted feature.

What do you think?

I fully agree with you that we shouldn't want to get into that debate!

I think extensibility is key in a lot of use cases. So having a hook / trigger that checks if a specific script is present and then run it, would give full flexibility without having the yarn/npm fight ;)

The -ci builds make it quite easy to run npm install.
This is part of my github action

  build-deploy:
    runs-on: ubuntu-latest
    container:
      image: klakegg/hugo:0.82.0-ext-alpine-ci
    steps:
    - uses: actions/checkout@v2
    - name: build with hugo
      env:
        NODE_ENV: "production"
      run: |
        env NODE_ENV="" npm install --save-dev
        hugo --gc --minify --environment production```

I think this issue is solved by the new support for .hugo-onbuild.sh.

I'm honestly not the biggest fan of the solution, however it is a good solution, it is almost free (rather small code change) and I think the solution solves real issues out there. Github Actions have the benefit of being Github Actions, however this will allow users the benefit of CI without having to completely buy in on the tooling.