Skip to content

Commit

Permalink
Optimize Docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
gruz0 committed Nov 20, 2024
1 parent c66d81c commit e6ef4a3
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 28 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
23 changes: 11 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
ARG NODE_VERSION="22.11.0"
ARG ALPINE_VERSION="3.20"
ARG NODE_VERSION="node:22.11.0"
ARG ALPINE_VERSION="alpine3.20"
ARG NPM_SHARP_VERSION="0.33.5"

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

Check failure on line 6 in Dockerfile

View workflow job for this annotation

GitHub Actions / build

DL3006 warning: Always tag the version of an image explicitly

Check failure on line 6 in Dockerfile

View workflow job for this annotation

GitHub Actions / build

DL3006 warning: Always tag the version of an image explicitly

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_VERSION}-${ALPINE_VERSION}" AS builder

Check failure on line 15 in Dockerfile

View workflow job for this annotation

GitHub Actions / build

DL3006 warning: Always tag the version of an image explicitly

Check failure on line 15 in Dockerfile

View workflow job for this annotation

GitHub Actions / build

DL3006 warning: Always tag the version of an image explicitly
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_VERSION}-${ALPINE_VERSION}" AS prod_builder

Check failure on line 60 in Dockerfile

View workflow job for this annotation

GitHub Actions / build

DL3006 warning: Always tag the version of an image explicitly

Check failure on line 60 in Dockerfile

View workflow job for this annotation

GitHub Actions / build

DL3006 warning: Always tag the version of an image explicitly
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_VERSION}-${ALPINE_VERSION}" AS runner

Check failure on line 71 in Dockerfile

View workflow job for this annotation

GitHub Actions / build

DL3006 warning: Always tag the version of an image explicitly

Check failure on line 71 in Dockerfile

View workflow job for this annotation

GitHub Actions / build

DL3006 warning: Always tag the version of an image explicitly

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 e6ef4a3

Please sign in to comment.