jojomi/docker-hugo

permissions of output incorrect for standard nginx

zeigerpuppy opened this issue · 0 comments

serving the output dir with docker container nginx:latest fails due to the permissions of the output files being incorrect (results in 13: permission error)

I have kludged a solution that keeps the built files with permission 755 but I'm sure there's a better way to do this. The umask seems OK at 0022 but the built files don't have read permission for other resulting in some issues for nginx containers.

note the line chmod -R 755 $HUGO_DESTINATION below

#!/bin/sh

WATCH="${HUGO_WATCH:=false}"
SLEEP="${HUGO_REFRESH_TIME:=-1}"
HUGO_DESTINATION="${HUGO_DESTINATION:=/output}"
echo "HUGO_WATCH:" $WATCH
echo "HUGO_REFRESH_TIME:" $HUGO_REFRESH_TIME
echo "HUGO_THEME:" $HUGO_THEME
echo "HUGO_BASEURL" $HUGO_BASEURL
echo "ARGS" $@

HUGO=/usr/local/sbin/hugo
echo "Hugo path: $HUGO"

while [ true ]
do
    if [[ $HUGO_WATCH != 'false' ]]; then
            echo "Watching..."
        $HUGO server --watch=true --source="/src" --theme="$HUGO_THEME" --destination="$HUGO_DESTINATION" --baseURL="$HUGO_BASEURL" --bind="0.0.0.0" "$@" || exit 1
    else
            echo "Building one time..."
        $HUGO --source="/src" --theme="$HUGO_THEME" --destination="$HUGO_DESTINATION" --baseURL="$HUGO_BASEURL" "$@" || exit 1
            echo "changing permissions"
        chmod -R 755 $HUGO_DESTINATION
    fi

    if [[ $HUGO_REFRESH_TIME == -1 ]]; then
        exit 0
    fi
    echo "Sleeping for $HUGO_REFRESH_TIME seconds..."
    sleep $SLEEP
done

I sub this file in my docker-compose config (ugly but effective)

    volumes:
      - ${PWD}/run.sh:/run.sh