Skip to content

Commit

Permalink
Merge pull request #169 from gruz0/refactor/optimize-docker-image
Browse files Browse the repository at this point in the history
Optimize Docker image
  • Loading branch information
gruz0 authored Nov 20, 2024
2 parents 57c6885 + 77731c6 commit 91086f8
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 26 deletions.
21 changes: 21 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,26 @@ coverage
.env*
*.db
*.db-journal
/prisma/*.db
/prisma/*.db-journal
.husky
docker-compose.*.yml
jest.config.ts
.prettier*
.eslint*
.editorconfig
LICENSE
Makefile
codespell.txt
architecture
__tests__
docker

/prompts/*.txt
!/prompts/00-*.txt

/shared/
!/shared/.gitkeep

/screenshots/
!/screenshots/idea-report-*.png
19 changes: 9 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,23 @@ ARG ALPINE_VERSION="3.20"
ARG NPM_SHARP_VERSION="0.33.5"

# Install dependencies only when needed
FROM node:${NODE_VERSION}-alpine${ALPINE_VERSION} AS base
FROM node:"${NODE_VERSION}"-alpine"${ALPINE_VERSION}" AS base

WORKDIR /app

COPY package.json package-lock.json ./

RUN npm install sharp@${NPM_SHARP_VERSION} && npm ci
RUN npm install "sharp@${NPM_SHARP_VERSION}" && npm ci

# Rebuild the source code only when needed
FROM node:${NODE_VERSION}-alpine${ALPINE_VERSION} AS builder
FROM node:"${NODE_VERSION}"-alpine"${ALPINE_VERSION}" AS builder
WORKDIR /app

COPY --from=base /app/node_modules ./node_modules
COPY . .

ENV NODE_ENV production

ENV NEXT_TELEMETRY_DISABLED 1

ARG DOMAIN
Expand Down Expand Up @@ -53,23 +55,20 @@ ENV CONCEPT_SERVICE_API_BASE=$CONCEPT_SERVICE_API_BASE
ARG FEEDBACK_SERVICE_API_BASE
ENV FEEDBACK_SERVICE_API_BASE=$FEEDBACK_SERVICE_API_BASE

RUN npm run prisma:generate_client && \
npm run build
RUN npm run build

FROM node:${NODE_VERSION}-alpine${ALPINE_VERSION} AS prod_builder
FROM node:"${NODE_VERSION}"-alpine"${ALPINE_VERSION}" AS prod_builder
WORKDIR /app

ENV NODE_ENV production

COPY --from=base /app/node_modules ./node_modules
COPY . .

RUN npm install && \
npm run prisma:generate_client && \
cp -R node_modules prod_node_modules
RUN npm install && cp -R node_modules prod_node_modules

# Production image, copy all the files and run next
FROM node:${NODE_VERSION}-alpine${ALPINE_VERSION} AS runner
FROM node:"${NODE_VERSION}"-alpine"${ALPINE_VERSION}" AS runner

WORKDIR /app

Expand Down
18 changes: 3 additions & 15 deletions next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ const nextConfig = {
trailingSlash: false,
output: 'standalone',
productionBrowserSourceMaps: false,
experimental: {
instrumentationHook: true,
},
}

const bundleAnalyzer = withBundleAnalyzer({
Expand All @@ -26,24 +29,9 @@ export default withSentryConfig(bundleAnalyzer(nextConfig), {
// For all available options, see:
// https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/

// Upload a larger set of source maps for prettier stack traces (increases build time)
widenClientFileUpload: true,

// Route browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers.
// This can increase your server load as well as your hosting bill.
// Note: Check that the configured route will not match with your Next.js middleware, otherwise reporting of client-
// side errors will fail.
tunnelRoute: '/monitoring',

// Hides source maps from generated client bundles
hideSourceMaps: true,

// Automatically tree-shake Sentry logger statements to reduce bundle size
disableLogger: true,

// Enables automatic instrumentation of Vercel Cron Monitors. (Does not yet work with App Router route handlers.)
// See the following for more information:
// https://docs.sentry.io/product/crons/
// https://vercel.com/docs/cron-jobs
automaticVercelMonitors: false,
})
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"analyze": "cross-env ANALYZE=true next build",
"dev": "NODE_OPTIONS='--inspect --trace-deprecation' next dev",
"build": "next build",
"build": "prisma generate && next build",
"start": "next start",
"next-lint": "next lint --no-cache",
"eslint": "npx eslint . --ext .ts,.tsx,.js,.jsx",
Expand Down

0 comments on commit 91086f8

Please sign in to comment.