Hi,
How can I set a specific version of Hugo to Render ?
Setting the environment variable HUGO_VERSION
has no effect.
Hi,
How can I set a specific version of Hugo to Render ?
Setting the environment variable HUGO_VERSION
has no effect.
Hi Jess,
We donât support multiple versions of hugo at the moment.
Iâd love to learn more about your use case for pinning hugoâs version ? What version are you looking to use ?
Thank you for your response.
Testing multiple Hugo versions is often required to test issues with templates and websites based on Hugo.
Does Renderâs build environment use the latest version of Hugo always?
I havenât tried it in a while, chiefly because of the lack of this capability; but, the last time I did, it wasnât the most current.
Yeah not being able to specify a Hugo version is certainly a bummer. In contrast, Netlify allows a way to specify a version.
EDIT: Thinking about this a bit more. A potential workaround would be to deploy a Docker-based web service that simply serves the static files. It would be still be âfrontedâ with Renderâs CDN. That should work.
Hey there,
So itâs true that we donât have a slick way to control the version of Hugo - but, itâs actually entirely possible to use whichever version you like.
The Render buildCommand
can be a script, as opposed to say, hugo --gc
and if you were to have a render-build.sh
script that did:
# save as render-build.sh and make sure it's executable
hugo version # Output the OLD version
if [[! -f $XDG_CACHE_HOME/hugo]]; then
echo "...Downloading HUGO"
mkdir -p ~/tmp
wget -P ~/tmp https://github.com/gohugoio/hugo/releases/download/v0.99.1/hugo_0.99.1_Linux-32bit.tar.gz
cd ~/tmp
echo "...Extracting HUGO"
tar -xzvf hugo_0.99.1_Linux-32bit.tar.gz
echo "...Moving HUGO"
mv hugo $XDG_CACHE_HOME/hugo
cd $HOME/project/src # Make sure we return to where we were
else
echo "...Using HUGO from build cache"
fi
$XDG_CACHE_HOME/hugo version # Output the NEW version
$XDG_CACHE_HOME/hugo --gc --minify`
then you can control the version of Hugo that your site is built with
John B
@John_B thatâs awesome! It would be nice to mention this in the docs. I am sure itâll be useful for users who use other static site tools. What you suggested is way better (and simpler!) than the workaround I added in my comment.
I have a slightly updated version of what @John_B posted above. This works for me. However, I am not sure how long the build cache stays around. If it stays around until you manually clear build cache and trigger a manual deploy, then itâs likely that the Hugo version will be whatever was last installed. I think this is a great starting point, though.
#!/bin/bash
# In your Render dashboard, set the HUGO_VERSION env var for your static site. You'll get the same experience as, say, Netlify.
TAR_NAME="hugo_extended_${HUGO_VERSION}_Linux-64bit.tar.gz"
hugo version # Output the OLD version
if [[ ! -f $XDG_CACHE_HOME/hugo ]]; then
echo "...Downloading HUGO"
mkdir -p ~/tmp
wget -P ~/tmp https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/${TAR_NAME}
cd ~/tmp
echo "...Extracting HUGO"
tar -xzvf ${TAR_NAME}
echo "...Moving HUGO"
mv hugo $XDG_CACHE_HOME/hugo
# Make sure we return to where we were.
cd $HOME/project/src
else
echo "...Using HUGO from build cache"
fi
$XDG_CACHE_HOME/hugo version
# Render sets IS_PULL_REQUEST to true for PR previews.
if [ "${IS_PULL_REQUEST:-}" = "true" ]; then
$XDG_CACHE_HOME/hugo --gc -e preview
else
$XDG_CACHE_HOME/hugo --gc --minify
fi
Youâre exactly right, the build cache sticks around until you âDeploy and Clearâ the build cache, but if youâre setting the environment variable with the version then it would seem like youâre making a conscious decision to change the version so you should remember to clear the build cache.
Another option would be to compare the version in the environment variable to the output of hugo version
(making sure youâre using the version from the cache) and if itâs different update it to match the version in the environment variable and recache it. Then, aside from changing the environment variable, thereâs no other interaction required.
John B
This is exactly what I was thinking would be the next step. I didnât have the time to do this myself. But I am happy with changing the version and manually clearing the cache for now. Thank you for all the help @John_B!
Also I think it would be good to add this info to the docs somewhere. One could customize the build environment this way and cache their build tools too. Itâs sort of similar to what other CI services offer in their pipelines.
Another way â if you donât mind using Node.js stuff â is to use the hugo-installer package.