Skip to content

Commit

Permalink
fix working Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusbegby committed Apr 26, 2024
1 parent 5461bcf commit 7cf4b78
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,25 @@ WORKDIR /app

# Install build dependencies necessary for native modules
RUN apt-get update && apt-get install -y \
python3 make g++ build-essential ffmpeg libopus-dev
python3 make build-essential

# Copy package.json and package-lock.json
COPY package*.json ./

# Install dependencies with all required build scripts
RUN npm install
RUN npm ci

# Copy tsconfig and other necessary files
COPY . .
COPY tsconfig.json ./
COPY src/ ./src/
COPY config/ ./config/
COPY locales/ ./locales/
COPY prisma/ ./prisma/

# Transpile TypeScript to JavaScript
RUN npm run build && npx prisma generate
RUN npm prune --production

# Ensure production dependencies are installed without dev dependencies
RUN npm ci --only=production
RUN npm run build && \
npx prisma generate && \
npm ci --omit=dev

# Stage 2: Production environment
FROM node:${NODE_VERSION}-bookworm-slim as production
Expand All @@ -38,7 +40,7 @@ WORKDIR /app

# Install runtime dependencies for native modules
RUN apt-get update && \
apt-get install -y ffmpeg libopus0
apt-get install -y ffmpeg

# Copy built artifacts from builder stage
COPY --from=builder /app/node_modules ./node_modules
Expand All @@ -55,10 +57,13 @@ RUN npm cache clean --force && \
# Rebuild all native dependencies
RUN npm rebuild

# Cleanup and reduce image size
RUN apt-get remove -y python3 make g++ build-essential && \
# Cleanup of unneeded packages, apk cache, and TypeScript source files
RUN apt-get update && apt-get install -y ca-certificates && \
apt-get remove -y python3 make build-essential && \
apt-get autoremove -y && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && \
update-ca-certificates

CMD /bin/sh -c "npm run deploy && npm run start"
# CMD /bin/sh -c "npm run deploy && npm run start"
CMD /bin/sh -c "npm run start"

0 comments on commit 7cf4b78

Please sign in to comment.