Skip to content

Commit 41a6eb4

Browse files
authored
Shrink Docker image size by ~1/3 by removing unnecessary ops (#642)
* Remove duplicate copy, chown on copy * Add Dockerfile syntax * Revert entrypoint changes to avoid errors in some non-root cases
1 parent 92ae761 commit 41a6eb4

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

Dockerfile

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# syntax=docker/dockerfile:1
12
# ------ Global scope variables ------
23

34
# Set of global build arguments.
@@ -148,7 +149,7 @@ fi
148149

149150
ENV SKIP_ENV_VALIDATION=0
150151
# ------------------------------
151-
152+
152153
# ------ Runner ------
153154
FROM node-alpine AS runner
154155
# -----------
@@ -220,22 +221,23 @@ COPY --from=zoekt-builder \
220221
/cmd/zoekt-index \
221222
/usr/local/bin/
222223

224+
RUN chown -R sourcebot:sourcebot /app
225+
223226
# Copy zoekt proto files (needed for gRPC client at runtime)
224-
COPY vendor/zoekt/grpc/protos /app/vendor/zoekt/grpc/protos
227+
COPY --chown=sourcebot:sourcebot vendor/zoekt/grpc/protos /app/vendor/zoekt/grpc/protos
225228

226229
# Copy all of the things
227-
COPY --from=web-builder /app/packages/web/public ./packages/web/public
228-
COPY --from=web-builder /app/packages/web/.next/standalone ./
229-
COPY --from=web-builder /app/packages/web/.next/static ./packages/web/.next/static
230+
COPY --chown=sourcebot:sourcebot --from=web-builder /app/packages/web/public ./packages/web/public
231+
COPY --chown=sourcebot:sourcebot --from=web-builder /app/packages/web/.next/standalone ./
232+
COPY --chown=sourcebot:sourcebot --from=web-builder /app/packages/web/.next/static ./packages/web/.next/static
230233

231-
COPY --from=backend-builder /app/node_modules ./node_modules
232-
COPY --from=backend-builder /app/packages/backend ./packages/backend
234+
COPY --chown=sourcebot:sourcebot --from=backend-builder /app/node_modules ./node_modules
235+
COPY --chown=sourcebot:sourcebot --from=backend-builder /app/packages/backend ./packages/backend
233236

234-
COPY --from=shared-libs-builder /app/node_modules ./node_modules
235-
COPY --from=shared-libs-builder /app/packages/db ./packages/db
236-
COPY --from=shared-libs-builder /app/packages/schemas ./packages/schemas
237-
COPY --from=shared-libs-builder /app/packages/shared ./packages/shared
238-
COPY --from=shared-libs-builder /app/packages/queryLanguage ./packages/queryLanguage
237+
COPY --chown=sourcebot:sourcebot --from=shared-libs-builder /app/packages/db ./packages/db
238+
COPY --chown=sourcebot:sourcebot --from=shared-libs-builder /app/packages/schemas ./packages/schemas
239+
COPY --chown=sourcebot:sourcebot --from=shared-libs-builder /app/packages/shared ./packages/shared
240+
COPY --chown=sourcebot:sourcebot --from=shared-libs-builder /app/packages/queryLanguage ./packages/queryLanguage
239241

240242
# Fixes git "dubious ownership" issues when the volume is mounted with different permissions to the container.
241243
RUN git config --global safe.directory "*"
@@ -245,9 +247,6 @@ RUN mkdir -p /run/postgresql && \
245247
chown -R postgres:postgres /run/postgresql && \
246248
chmod 775 /run/postgresql
247249

248-
# Make app directory accessible to both root and sourcebot user
249-
RUN chown -R sourcebot:sourcebot /app
250-
# Make data directory accessible to both root and sourcebot user
251250
RUN chown -R sourcebot:sourcebot /data
252251

253252
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf

0 commit comments

Comments
 (0)