# syntax=docker/dockerfile:1

FROM alpine:latest

# Install npm and nodejs
RUN apk add --no-cache nodejs npm

# Create non-root user
ARG CUSTOM_UID
ARG CUSTOM_GID
ENV CUSTOM_USERNAME=frontend
ENV CUSTOM_GROUPNAME=frontend
RUN addgroup --gid ${CUSTOM_GID:-1000} ${CUSTOM_GROUPNAME} && \
    adduser --uid ${CUSTOM_UID:-1000} --shell /bin/ash ${CUSTOM_USERNAME} --ingroup ${CUSTOM_GROUPNAME} --disabled-password && \
    mkdir /app && chown ${CUSTOM_UID:-1000}:${CUSTOM_GID:-1000} /app && chmod 700 /app

# Copy source files
COPY --chown=${CUSTOM_USERNAME}:${CUSTOM_GROUPNAME} frontend/ /app/

# Install dependencies
USER ${CUSTOM_UID:-1000}:${CUSTOM_GID:-1000}
WORKDIR /app/
RUN npm install

# Run vite dev server
ENV NODE_ENV=development
EXPOSE 3000
ENTRYPOINT ["npm", "run", "dev"]
