Skip to content

Commit 3b6faeb

Browse files
authored
chore(linea-ens-app): refactor Dockerfile to reduce image size (#362)
1 parent c72e142 commit 3b6faeb

File tree

4 files changed

+101
-49
lines changed

4 files changed

+101
-49
lines changed

.dockerignore

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Dependencies (will be installed in Docker)
2+
**/node_modules
3+
4+
# Build outputs (will be rebuilt in Docker)
5+
**/.next
6+
**/dist
7+
**/build
8+
**/out
9+
10+
# Development files
11+
**/.gitignore
12+
**/.env.local
13+
**/.env.*.local
14+
15+
# IDE
16+
**/.idea
17+
**/.vscode
18+
**/*.swp
19+
**/*.swo
20+
21+
# Testing
22+
**/coverage
23+
**/e2e
24+
**/test
25+
**/*.test.*
26+
**/*.spec.*
27+
**/playwright
28+
**/playwright-report
29+
30+
# Documentation
31+
**/docs
32+
33+
# Misc
34+
**/.DS_Store
35+
**/Thumbs.db
36+
**/*.log
37+
**/npm-debug.log*
38+
**/yarn-debug.log*
39+
**/yarn-error.log*
40+
41+
# Archives
42+
**/*.tar
43+
**/*.tar.gz
44+
**/*.tar.lz4
45+
**/*.zip
46+
47+
# Other packages not needed for linea-ens-app build
48+
packages/linea-ccip-gateway
49+
packages/linea-ens-resolver
50+
packages/linea-ens-subgraph
51+
packages/linea-state-verifier
52+
packages/poh-signer-api
53+
services
54+
Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
{
2-
"processors": [
3-
"stylelint-processor-styled-components"
4-
],
2+
"processors": ["stylelint-processor-styled-components"],
53
"extends": [
64
"stylelint-config-standard-scss",
75
"stylelint-config-styled-components",
@@ -12,38 +10,27 @@
1210
"selector-type-case": [
1311
"lower",
1412
{
15-
"ignoreTypes": [
16-
"/^\\$\\w+/"
17-
]
13+
"ignoreTypes": ["/^\\$\\w+/"]
1814
}
1915
],
2016
"selector-type-no-unknown": [
2117
true,
2218
{
23-
"ignoreTypes": [
24-
"/-styled-mixin/",
25-
"/^\\$\\w+/"
26-
]
19+
"ignoreTypes": ["/-styled-mixin/", "/^\\$\\w+/"]
2720
}
2821
],
2922
"value-keyword-case": [
3023
"lower",
3124
{
32-
"ignoreKeywords": [
33-
"dummyValue",
34-
"currentColor"
35-
]
25+
"ignoreKeywords": ["dummyValue", "currentColor"]
3626
}
3727
],
3828
"declaration-colon-newline-after": null,
3929
"declaration-empty-line-before": null,
4030
"property-no-unknown": [
4131
true,
4232
{
43-
"ignoreProperties": [
44-
"flex-gap",
45-
"webkit-appearance"
46-
]
33+
"ignoreProperties": ["flex-gap", "webkit-appearance"]
4734
}
4835
],
4936
"color-function-notation": "legacy",
@@ -54,6 +41,6 @@
5441
"rule-empty-line-before": null,
5542
"keyframes-name-pattern": null,
5643
"keyframe-block-no-duplicate-selectors": null,
57-
"no-descending-specificity": false
44+
"no-descending-specificity": null
5845
}
59-
}
46+
}

packages/linea-ens-app/Dockerfile

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,57 @@
1-
FROM node:18
2-
3-
# Install system dependencies (if necessary)
4-
RUN apt-get update && apt-get install -y \
5-
libcairo2-dev \
6-
libpango1.0-dev \
7-
libjpeg-dev \
8-
libgif-dev \
9-
librsvg2-dev \
10-
build-essential \
11-
&& rm -rf /var/lib/apt/lists/*
1+
FROM node:22-alpine AS base
122

3+
ENV PNPM_HOME="/pnpm"
4+
ENV PATH="$PNPM_HOME:$PATH"
5+
RUN corepack enable
6+
7+
RUN apk add --no-cache libc6-compat python3 make g++ git \
8+
cairo-dev pango-dev jpeg-dev giflib-dev librsvg-dev
9+
10+
FROM base AS builder
1311
WORKDIR /app
1412

1513
ARG NEXT_PUBLIC_ALCHEMY_KEY
1614
ARG NEXT_PUBLIC_INFURA_KEY
1715
ARG NEXT_PUBLIC_WC_PROJECT_ID
1816
ARG NEXT_PUBLIC_THE_GRAPH_MAINNET_API_KEY
1917
ARG NEXT_PUBLIC_THE_GRAPH_SEPOLIA_API_KEY
18+
2019
ENV NEXT_PUBLIC_ALCHEMY_KEY=$NEXT_PUBLIC_ALCHEMY_KEY
2120
ENV NEXT_PUBLIC_INFURA_KEY=$NEXT_PUBLIC_INFURA_KEY
2221
ENV NEXT_PUBLIC_WC_PROJECT_ID=$NEXT_PUBLIC_WC_PROJECT_ID
2322
ENV NEXT_PUBLIC_THE_GRAPH_MAINNET_API_KEY=$NEXT_PUBLIC_THE_GRAPH_MAINNET_API_KEY
2423
ENV NEXT_PUBLIC_THE_GRAPH_SEPOLIA_API_KEY=$NEXT_PUBLIC_THE_GRAPH_SEPOLIA_API_KEY
25-
COPY . .
2624

27-
# Install pnpm and dependencies
28-
RUN npm install -g [email protected]
29-
RUN rm -rf node_modules
30-
RUN pnpm config set store-dir ~/.local/share/pnpm/store
25+
COPY pnpm-lock.yaml pnpm-workspace.yaml package.json ./
26+
27+
COPY packages/linea-ens-app/package.json ./packages/linea-ens-app/
28+
COPY packages/linea-ens-contracts/package.json ./packages/linea-ens-contracts/
29+
30+
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile --prefer-offline
31+
32+
COPY .git ./.git
3133

34+
COPY packages/linea-ens-app/ ./packages/linea-ens-app/
35+
COPY packages/linea-ens-contracts/ ./packages/linea-ens-contracts/
3236

3337
WORKDIR /app/packages/linea-ens-app
38+
RUN pnpm build
3439

35-
# Clear Next.js cache
36-
RUN rm -rf .next
37-
RUN pnpm install
38-
RUN pnpm run build
40+
FROM node:22-alpine AS runner
41+
WORKDIR /app
42+
43+
ENV NODE_ENV=production
44+
ENV NEXT_TELEMETRY_DISABLED=1
45+
46+
RUN addgroup --system --gid 1001 nodejs && \
47+
adduser --system --uid 1001 nextjs
48+
49+
COPY --from=builder --chown=nextjs:nodejs /app/packages/linea-ens-app/.next/standalone ./
50+
COPY --from=builder --chown=nextjs:nodejs /app/packages/linea-ens-app/.next/static ./packages/linea-ens-app/.next/static
51+
COPY --from=builder --chown=nextjs:nodejs /app/packages/linea-ens-app/public ./packages/linea-ens-app/public
3952

4053
EXPOSE 3000
4154

42-
CMD ["pnpm", "start"]
55+
USER nextjs
56+
57+
CMD ["node", "packages/linea-ens-app/server.js"]

packages/linea-ens-app/next.config.mjs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
1-
// @ts-check
2-
3-
/* eslint-disable @typescript-eslint/naming-convention */
4-
/* eslint-disable import/no-extraneous-dependencies */
5-
/* eslint-disable no-param-reassign */
61
import { execSync } from 'child_process'
72
import path, { dirname } from 'path'
83
import { fileURLToPath } from 'url'
9-
104
import { withSentryConfig } from '@sentry/nextjs'
115
import StylelintPlugin from 'stylelint-webpack-plugin'
126

@@ -24,6 +18,9 @@ const babelIncludeRegexes = [
2418
* */
2519
const nextConfig = {
2620
reactStrictMode: true,
21+
output: 'standalone',
22+
// For monorepo support with pnpm - trace dependencies from the root
23+
outputFileTracingRoot: path.join(__dirname, '../../'),
2724
compiler: {
2825
styledComponents: true,
2926
},
@@ -91,8 +88,7 @@ const nextConfig = {
9188
]
9289
},
9390
generateBuildId: () => {
94-
const hash = execSync('git rev-parse HEAD').toString().trim()
95-
return hash
91+
return execSync('git rev-parse HEAD').toString().trim()
9692
},
9793
webpack: (config, options) => {
9894
for (const rule of config.module.rules) {

0 commit comments

Comments
 (0)