FROM node:14-alpine as builder

COPY package.json package-lock.json ./
RUN npm install

COPY tsconfig.json next-env.d.ts .babelrc next.config.js next-sitemap.js ./
COPY src src/
COPY public public/
COPY types types/

ENV NEXT_TELEMETRY_DISABLED=1
ENV NEXT_PUBLIC_API_URL=https://api.dev.sahkoinsinoorikilta.fi/api
ENV NEXT_PUBLIC_SITE_URL=https://dev.sahkoinsinoorikilta.fi
RUN npm run build

FROM node:14-alpine as server
WORKDIR /www
COPY package.json package-lock.json next.config.js next-sitemap.js ./
COPY --from=builder .next .next
COPY --from=builder node_modules node_modules
COPY --from=builder public public

RUN npm prune --production

EXPOSE 3000
ENTRYPOINT ["npm", "run", "serve"]
