FROM nginx:alpine

COPY public/ /usr/share/nginx/html/
COPY nginx.conf /etc/nginx/conf.d/default.conf

RUN HTML=/usr/share/nginx/html/index.html && \
    for f in $(find /usr/share/nginx/html/assets -name "*.css" -o -name "*.js"); do \
        hash=$(md5sum "$f" | cut -c1-8); \
        rel="${f#/usr/share/nginx/html}"; \
        sed -i "s|${rel}\"|${rel}?v=${hash}\"|g" "$HTML"; \
    done

EXPOSE 80