shiveshnavin commited on
Commit
098338f
·
1 Parent(s): 9db2ad9

Docker lean WIP

Browse files
Files changed (2) hide show
  1. Dockerfile.build.lean +122 -0
  2. start.sh +7 -6
Dockerfile.build.lean ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Multi-stage build for better reliability
2
+ FROM linuxserver/ffmpeg as base
3
+
4
+ # -----------------------------------------------------------------------------
5
+ # node-setup: install Node.js, fonts and configure npm for non-root use
6
+ # -----------------------------------------------------------------------------
7
+ FROM base AS node-setup
8
+
9
+ USER root
10
+ RUN apt-get update && apt-get install -y curl fonts-deva fonts-noto fonts-noto-cjk && \
11
+ curl -fsSL https://deb.nodesource.com/setup_22.x | bash - && \
12
+ apt-get install -y nodejs && \
13
+ apt-get clean && rm -rf /var/lib/apt/lists/*
14
+
15
+ # create application directory owned by the unprivileged user
16
+ RUN mkdir -p /app && chown -R 1000:1000 /app
17
+
18
+ # prepare npm cache and global config as root, then hand ownership to UID 1000
19
+ RUN mkdir -p /root/.npm && chown -R 1000:0 /root/.npm && \
20
+ npm config set fetch-retry-mintimeout 20000 && \
21
+ npm config set fetch-retry-maxtimeout 120000 && \
22
+ npm config set fetch-retries 5 && \
23
+ npm config set fetch-timeout 600000 && \
24
+ npm config set registry https://registry.npmjs.org/ && \
25
+ npm config set audit false && \
26
+ npm config set fund false && \
27
+ npm config set update-notifier false && \
28
+ npm install -g typescript && \
29
+ # chown the entire global node_modules tree so the installer path doesn't matter
30
+ chown -R 1000:0 "$(npm root -g)"
31
+
32
+ ENV NPM_CONFIG_CACHE=/app/.npm
33
+
34
+ USER 1000
35
+ WORKDIR /app
36
+
37
+ # -----------------------------------------------------------------------------
38
+ # common-utils-builder: compile shared utilities as non-root
39
+ # -----------------------------------------------------------------------------
40
+ FROM node-setup AS common-utils-builder
41
+ USER 1000
42
+ WORKDIR /app
43
+ COPY --chown=1000 common-utils/ ./common-utils
44
+ WORKDIR /app/common-utils
45
+ RUN npm ci && npm run build && echo "Common-utils build completed successfully"
46
+
47
+ # -----------------------------------------------------------------------------
48
+ # dependencies: install project dependencies with retry logic
49
+ # -----------------------------------------------------------------------------
50
+ FROM node-setup AS dependencies
51
+ USER 1000
52
+ WORKDIR /app
53
+ COPY --chown=1000 package*.json ./
54
+ COPY --chown=1000 .npmrc ./
55
+ COPY --from=common-utils-builder --chown=1000 /app/common-utils ./common-utils
56
+
57
+ ENV NODE_ENV=production
58
+ ENV CI=true
59
+
60
+ RUN npm cache clean --force
61
+
62
+ RUN set -e && \
63
+ echo "Starting dependency installation..." && \
64
+ (timeout 900 npm ci --verbose --ignore-scripts --production=false 2>&1 | tee /tmp/npm-install.log) || \
65
+ (echo "First attempt failed, cleaning cache and retrying..." && \
66
+ npm cache clean --force && \
67
+ rm -rf node_modules package-lock.json && \
68
+ timeout 900 npm install --verbose --ignore-scripts --production=false 2>&1 | tee -a /tmp/npm-install.log) || \
69
+ (echo "Second attempt failed, trying with reduced concurrency..." && \
70
+ npm cache clean --force && \
71
+ rm -rf node_modules && \
72
+ timeout 1200 npm install --verbose --maxsockets 1 --production=false 2>&1 | tee -a /tmp/npm-install.log)
73
+
74
+ RUN echo "Running postinstall scripts..." && \
75
+ echo "Skipping common-utils build in postinstall as it's already built" && \
76
+ node ffmpeg-fix.js 2>&1 | tee -a /tmp/postinstall.log || echo "ffmpeg-fix completed" && \
77
+ npm rebuild --verbose 2>&1 | tee -a /tmp/npm-rebuild.log || \
78
+ echo "Some rebuilds failed, but continuing..."
79
+
80
+ RUN node -e "console.log('Node version:', process.version)" && \
81
+ node -e "require('react'); console.log('React OK')" && \
82
+ node -e "require('remotion'); console.log('Remotion OK')" && \
83
+ ls -la node_modules/.bin/ | head -20
84
+
85
+ # -----------------------------------------------------------------------------
86
+ # final production image (uses base again to keep layers small)
87
+ # -----------------------------------------------------------------------------
88
+ FROM base AS final
89
+
90
+ # create writable application dirs and make them owned by UID 1000
91
+ RUN mkdir -p /app/public /app/out /app/frames /app/uploads && chown -R 1000:1000 /app
92
+
93
+ # install bash so developers can exec into container if needed
94
+ RUN apt-get update && apt-get install -y bash && apt-get clean && rm -rf /var/lib/apt/lists/*
95
+
96
+ COPY --from=dependencies --chown=1000 /app/node_modules ./app/node_modules
97
+ COPY --from=dependencies --chown=1000 /app/package*.json ./app/
98
+ COPY --from=dependencies --chown=1000 /app/common-utils ./app/common-utils
99
+
100
+ USER 1000
101
+ WORKDIR /app
102
+ COPY --chown=1000 . ./
103
+ COPY --chown=1000 start.sh /app/start.sh
104
+ RUN chmod +x /app/start.sh
105
+
106
+ RUN echo "Verifying installation..." && \
107
+ node -e "console.log('Final verification - Node:', process.version)" && \
108
+ npm list --depth=0 | head -10 || true
109
+
110
+ EXPOSE 7860 3000 8083
111
+ COPY --chown=1000 start.sh /app/start.sh
112
+ RUN chmod +x /app/start.sh
113
+ # default command for production run
114
+ CMD ["sh", "/app/start.sh"]
115
+
116
+ # if you need a shell, override entrypoint via --entrypoint
117
+ # e.g.: docker run --rm -it --entrypoint /bin/bash semibit/render-farm:lean
118
+
119
+ # Build and run commands:
120
+ # docker build -f Dockerfile.build.multistage -t render-farm:latest .
121
+ # docker run -p 8083:8083 -it --rm render-farm:latest
122
+ # docker run -p 8083:8083 -it --rm --entrypoint /bin/sh render-farm:latest
start.sh CHANGED
@@ -3,12 +3,13 @@ set -e
3
  # Xvfb :99 -screen 0 1920x1080x24 &
4
 
5
  echo "Starting app (npm start) in background..."
6
- npm start &
 
7
 
8
- APP_PID=$!
9
- echo "App PID: $APP_PID"
10
 
11
- sleep 1
12
 
13
- echo "Starting nginx (foreground)..."
14
- nginx -g 'daemon off;'
 
3
  # Xvfb :99 -screen 0 1920x1080x24 &
4
 
5
  echo "Starting app (npm start) in background..."
6
+ npm start
7
+ # npm start &
8
 
9
+ # APP_PID=$!
10
+ # echo "App PID: $APP_PID"
11
 
12
+ # sleep 1
13
 
14
+ # echo "Starting nginx (foreground)..."
15
+ # nginx -g 'daemon off;'