FROM node:20-alpine AS base

RUN apk add --no-cache tzdata

# Set the timezone to Asia/Tehran
RUN cp /usr/share/zoneinfo/Asia/Tehran /etc/localtime && echo "Asia/Tehran" > /etc/timezone

FROM base AS deps
WORKDIR /temp-deps
COPY package*.json ./
RUN npm install

FROM base AS builder
WORKDIR /build
COPY . ./
COPY --from=deps /temp-deps/node_modules ./node_modules
RUN npm run build
RUN npm install --omit=dev


FROM base AS runner
WORKDIR /app
ENV NUXT_TELEMETRY_DISABLED=1


RUN addgroup -S appgroup && adduser -S appuser -G appgroup
RUN chown -R appuser:appgroup /app

# COPY --from=builder --chown=appuser:appgroup /build/.nuxt ./.nuxt
# COPY --from=builder --chown=appuser:appgroup /build/static ./static
# COPY --from=builder --chown=appuser:appgroup /build/package.json ./
# COPY --from=builder --chown=appuser:appgroup /build/node_modules/ ./node_modules/
COPY --from=builder --chown=appuser:appgroup /build ./


USER appuser

# Set environment variables
ENV NODE_ENV=production
ENV PORT=7420
ENV HOSTNAME="0.0.0.0"


EXPOSE 7420

# Start the Nuxt 2 app
CMD ["npm", "start"]
