@@ -0,0 +1,17 @@
|
||||
node_modules
|
||||
dist
|
||||
coverage
|
||||
.git
|
||||
.github
|
||||
.env
|
||||
.env.*
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
.vscode
|
||||
.idea
|
||||
.DS_Store
|
||||
*.md
|
||||
Dockerfile*
|
||||
docker-compose*
|
||||
+22
-17
@@ -1,37 +1,42 @@
|
||||
FROM node:20-alpine AS base
|
||||
|
||||
ENV TZ=Asia/Tehran
|
||||
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 yarn install
|
||||
WORKDIR /app
|
||||
RUN corepack enable
|
||||
COPY package.json yarn.lock ./
|
||||
RUN yarn install --frozen-lockfile
|
||||
|
||||
FROM base AS builder
|
||||
WORKDIR /build
|
||||
COPY . ./
|
||||
COPY --from=deps /temp-deps/node_modules ./node_modules
|
||||
WORKDIR /app
|
||||
RUN corepack enable
|
||||
COPY package.json yarn.lock nest-cli.json tsconfig.json tsconfig.build.json ./
|
||||
COPY --from=deps /app/node_modules ./node_modules
|
||||
COPY src ./src
|
||||
RUN yarn build \
|
||||
&& mkdir -p dist/config \
|
||||
&& cp src/config/swagger.json dist/config/
|
||||
|
||||
# Check if a build script exists and run the build if it does
|
||||
RUN if [ -f package.json ] && grep -q '"build":' package.json; then yarn build; fi
|
||||
FROM base AS prod-deps
|
||||
WORKDIR /app
|
||||
RUN corepack enable
|
||||
COPY package.json yarn.lock ./
|
||||
RUN yarn install --production --frozen-lockfile
|
||||
|
||||
|
||||
FROM base AS runner
|
||||
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
|
||||
WORKDIR /app
|
||||
|
||||
COPY --from=builder /build ./
|
||||
ENV NODE_ENV=production
|
||||
|
||||
RUN chown -R appuser:appgroup /app
|
||||
COPY --from=prod-deps --chown=appuser:appgroup /app/node_modules ./node_modules
|
||||
COPY --from=builder --chown=appuser:appgroup /app/dist ./dist
|
||||
COPY --from=builder --chown=appuser:appgroup /app/package.json ./package.json
|
||||
|
||||
USER appuser
|
||||
|
||||
ENV NODE_ENV=production
|
||||
|
||||
EXPOSE 3000
|
||||
|
||||
CMD ["npm", "start"]
|
||||
CMD ["node", "dist/main"]
|
||||
|
||||
Reference in New Issue
Block a user