FROM nginx:1.25-alpine

# Create nginx user and required directories with proper permissions
RUN mkdir -p /var/cache/nginx/client_temp \
    /var/cache/nginx/proxy_temp \
    /var/cache/nginx/fastcgi_temp \
    /var/cache/nginx/uwsgi_temp \
    /var/cache/nginx/scgi_temp \
    /tmp \
    && chown -R nginx:nginx /var/cache/nginx \
    && chown -R nginx:nginx /tmp \
    && chmod -R 755 /var/cache/nginx \
    && chmod -R 755 /tmp

COPY nginx.conf /etc/nginx/nginx.conf

COPY dist/ /usr/share/nginx/html/

RUN chown -R nginx:nginx /usr/share/nginx/html \
    && chmod -R 755 /usr/share/nginx/html

HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
    CMD wget --no-verbose --tries=1 --spider http://localhost/ || exit 1

EXPOSE 80

USER nginx

CMD ["nginx", "-g", "daemon off;"]