Dockerfile 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # base image
  2. FROM node:20-alpine3.20 AS base
  3. LABEL maintainer="takatost@gmail.com"
  4. # if you located in China, you can use aliyun mirror to speed up
  5. # RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
  6. RUN apk add --no-cache tzdata
  7. # install packages
  8. FROM base AS packages
  9. WORKDIR /app/web
  10. COPY package.json .
  11. COPY yarn.lock .
  12. # if you located in China, you can use taobao registry to speed up
  13. # RUN yarn install --frozen-lockfile --registry https://registry.npmmirror.com/
  14. RUN yarn install --frozen-lockfile
  15. # build resources
  16. FROM base AS builder
  17. WORKDIR /app/web
  18. COPY --from=packages /app/web/ .
  19. COPY . .
  20. RUN yarn build
  21. # production stage
  22. FROM base AS production
  23. ENV NODE_ENV=production
  24. ENV EDITION=SELF_HOSTED
  25. ENV DEPLOY_ENV=PRODUCTION
  26. ENV CONSOLE_API_URL=http://1.14.94.79:5001
  27. ENV APP_API_URL=http://1.14.94.79:5001
  28. ENV PORT=3000
  29. ENV NEXT_TELEMETRY_DISABLED=1
  30. # set timezone
  31. ENV TZ=UTC
  32. RUN ln -s /usr/share/zoneinfo/${TZ} /etc/localtime \
  33. && echo ${TZ} > /etc/timezone
  34. WORKDIR /app/web
  35. COPY --from=builder /app/web/public ./public
  36. COPY --from=builder /app/web/.next/standalone ./
  37. COPY --from=builder /app/web/.next/static ./.next/static
  38. COPY docker/pm2.json ./pm2.json
  39. COPY docker/entrypoint.sh ./entrypoint.sh
  40. # global runtime packages
  41. RUN yarn global add pm2 \
  42. && yarn cache clean \
  43. && mkdir /.pm2 \
  44. && chown -R 1001:0 /.pm2 /app/web \
  45. && chmod -R g=u /.pm2 /app/web
  46. ARG COMMIT_SHA
  47. ENV COMMIT_SHA=${COMMIT_SHA}
  48. USER 1001
  49. EXPOSE 3000
  50. ENTRYPOINT ["/bin/sh", "./entrypoint.sh"]