shiveshnavin commited on
Commit
6970102
·
1 Parent(s): 190ffc1

Add common-utils build stage to multi-stage Dockerfile

Browse files
Files changed (2) hide show
  1. .dockerignore +4 -0
  2. Dockerfile.build.multistage +29 -0
.dockerignore CHANGED
@@ -4,6 +4,10 @@ npm-debug.log*
4
  yarn-debug.log*
5
  yarn-error.log*
6
 
 
 
 
 
7
  # Git
8
  .git
9
  .gitignore
 
4
  yarn-debug.log*
5
  yarn-error.log*
6
 
7
+ # Common-utils build artifacts - we build these separately
8
+ common-utils/dist
9
+ common-utils/node_modules
10
+
11
  # Git
12
  .git
13
  .gitignore
Dockerfile.build.multistage CHANGED
@@ -41,6 +41,27 @@ RUN set -e && \
41
  ln -sf /usr/local/bin/ffprobe /usr/bin/ffprobe && \
42
  ffmpeg -version
43
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  # Dependencies stage - isolate dependency installation
45
  FROM base as dependencies
46
 
@@ -52,6 +73,9 @@ WORKDIR /app
52
  COPY --chown=1000 package*.json ./
53
  COPY --chown=1000 .npmrc ./
54
 
 
 
 
55
  # Set comprehensive npm configurations for reliability and speed
56
  RUN npm config set fetch-retry-mintimeout 20000 && \
57
  npm config set fetch-retry-maxtimeout 120000 && \
@@ -75,6 +99,7 @@ RUN npm cache clean --force
75
 
76
  # Install dependencies with multiple fallback strategies and comprehensive error handling
77
  # Note: NOT using --no-optional to allow esbuild platform-specific binaries to install
 
78
  RUN set -e && \
79
  echo "Starting dependency installation..." && \
80
  (timeout 900 npm ci --verbose --ignore-scripts --production=false 2>&1 | tee /tmp/npm-install.log) || \
@@ -88,7 +113,10 @@ RUN set -e && \
88
  timeout 1200 npm install --verbose --maxsockets 1 --production=false 2>&1 | tee -a /tmp/npm-install.log)
89
 
90
  # Run postinstall scripts separately for better control and debugging
 
91
  RUN echo "Running postinstall scripts..." && \
 
 
92
  npm rebuild --verbose 2>&1 | tee -a /tmp/npm-rebuild.log || \
93
  echo "Some rebuilds failed, but continuing..."
94
 
@@ -107,6 +135,7 @@ RUN mkdir -p /app /app/public /app/out /app/frames /app/uploads && chown -R 1000
107
  # Copy installed dependencies from the dependencies stage
108
  COPY --from=dependencies --chown=1000 /app/node_modules ./app/node_modules
109
  COPY --from=dependencies --chown=1000 /app/package*.json ./app/
 
110
 
111
  USER 1000
112
  WORKDIR /app
 
41
  ln -sf /usr/local/bin/ffprobe /usr/bin/ffprobe && \
42
  ffmpeg -version
43
 
44
+ # Common-utils build stage - build the local common-utils dependency
45
+ FROM base as common-utils-builder
46
+
47
+ RUN mkdir /app && chown 1000 /app
48
+ USER 1000
49
+ WORKDIR /app
50
+
51
+ # Copy common-utils source and package files
52
+ COPY --chown=1000 common-utils/ ./common-utils/
53
+
54
+ # Install TypeScript globally for building common-utils
55
+ USER root
56
+ RUN npm install -g typescript
57
+ USER 1000
58
+
59
+ # Build common-utils - install dependencies and compile
60
+ WORKDIR /app/common-utils
61
+ RUN npm install && \
62
+ npm run build && \
63
+ echo "Common-utils build completed successfully"
64
+
65
  # Dependencies stage - isolate dependency installation
66
  FROM base as dependencies
67
 
 
73
  COPY --chown=1000 package*.json ./
74
  COPY --chown=1000 .npmrc ./
75
 
76
+ # Copy built common-utils from the builder stage
77
+ COPY --from=common-utils-builder --chown=1000 /app/common-utils ./common-utils
78
+
79
  # Set comprehensive npm configurations for reliability and speed
80
  RUN npm config set fetch-retry-mintimeout 20000 && \
81
  npm config set fetch-retry-maxtimeout 120000 && \
 
99
 
100
  # Install dependencies with multiple fallback strategies and comprehensive error handling
101
  # Note: NOT using --no-optional to allow esbuild platform-specific binaries to install
102
+ # Skip preinstall script since we already built common-utils
103
  RUN set -e && \
104
  echo "Starting dependency installation..." && \
105
  (timeout 900 npm ci --verbose --ignore-scripts --production=false 2>&1 | tee /tmp/npm-install.log) || \
 
113
  timeout 1200 npm install --verbose --maxsockets 1 --production=false 2>&1 | tee -a /tmp/npm-install.log)
114
 
115
  # Run postinstall scripts separately for better control and debugging
116
+ # Skip the common-utils build in postinstall since we already have it built
117
  RUN echo "Running postinstall scripts..." && \
118
+ echo "Skipping common-utils build in postinstall as it's already built" && \
119
+ node ffmpeg-fix.js 2>&1 | tee -a /tmp/postinstall.log || echo "ffmpeg-fix completed" && \
120
  npm rebuild --verbose 2>&1 | tee -a /tmp/npm-rebuild.log || \
121
  echo "Some rebuilds failed, but continuing..."
122
 
 
135
  # Copy installed dependencies from the dependencies stage
136
  COPY --from=dependencies --chown=1000 /app/node_modules ./app/node_modules
137
  COPY --from=dependencies --chown=1000 /app/package*.json ./app/
138
+ COPY --from=dependencies --chown=1000 /app/common-utils ./app/common-utils
139
 
140
  USER 1000
141
  WORKDIR /app