Skip to content

Commit 60ed95e

Browse files
wip
1 parent 2e3feca commit 60ed95e

File tree

1 file changed

+33
-30
lines changed

1 file changed

+33
-30
lines changed

Dockerfile

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -182,14 +182,30 @@ ENV SOURCEBOT_LOG_LEVEL=info
182182
# Sourcebot collects anonymous usage data using [PostHog](https://posthog.com/). Uncomment this line to disable.
183183
# ENV SOURCEBOT_TELEMETRY_DISABLED=1
184184

185-
COPY package.json yarn.lock* .yarnrc.yml public.pem ./
186-
COPY .yarn ./.yarn
185+
# Configure dependencies
186+
RUN apk add --no-cache git ca-certificates bind-tools tini jansson wget supervisor uuidgen curl perl jq redis postgresql postgresql-contrib openssl util-linux unzip
187+
188+
ARG UID=1500
189+
ARG GID=1500
190+
191+
# To run as non-root, the user must be part of postgres, redis and node groups
192+
RUN addgroup -g $GID sourcebot && \
193+
adduser -D -u $UID -h /app -S sourcebot && \
194+
adduser sourcebot postgres && \
195+
adduser sourcebot redis && \
196+
adduser sourcebot node && \
197+
chown -R sourcebot /app && \
198+
mkdir /var/log/sourcebot && \
199+
chown sourcebot /var/log/sourcebot
200+
201+
COPY --chown=sourcebot:sourcebot package.json yarn.lock* .yarnrc.yml public.pem ./
202+
COPY --chown=sourcebot:sourcebot .yarn ./.yarn
187203

188204
# Configure zoekt
189-
COPY vendor/zoekt/install-ctags-alpine.sh .
205+
COPY --chown=sourcebot:sourcebot vendor/zoekt/install-ctags-alpine.sh .
190206
RUN ./install-ctags-alpine.sh && rm install-ctags-alpine.sh
191-
RUN mkdir -p ${DATA_CACHE_DIR}
192-
COPY --from=zoekt-builder \
207+
RUN mkdir -p ${DATA_CACHE_DIR} && chown -R sourcebot ${DATA_CACHE_DIR}
208+
COPY --chown=sourcebot:sourcebot --from=zoekt-builder \
193209
/cmd/zoekt-git-index \
194210
/cmd/zoekt-indexserver \
195211
/cmd/zoekt-mirror-github \
@@ -202,20 +218,18 @@ COPY --from=zoekt-builder \
202218
/usr/local/bin/
203219

204220
# Copy all of the things
205-
COPY --from=web-builder /app/packages/web/public ./packages/web/public
206-
COPY --from=web-builder /app/packages/web/.next/standalone ./
207-
COPY --from=web-builder /app/packages/web/.next/static ./packages/web/.next/static
221+
COPY --chown=sourcebot:sourcebot --from=web-builder /app/packages/web/public ./packages/web/public
222+
COPY --chown=sourcebot:sourcebot --from=web-builder /app/packages/web/.next/standalone ./
223+
COPY --chown=sourcebot:sourcebot --from=web-builder /app/packages/web/.next/static ./packages/web/.next/static
208224

209-
COPY --from=backend-builder /app/node_modules ./node_modules
210-
COPY --from=backend-builder /app/packages/backend ./packages/backend
225+
COPY --chown=sourcebot:sourcebot --from=backend-builder /app/node_modules ./node_modules
226+
COPY --chown=sourcebot:sourcebot --from=backend-builder /app/packages/backend ./packages/backend
211227

212-
COPY --from=shared-libs-builder /app/node_modules ./node_modules
213-
COPY --from=shared-libs-builder /app/packages/db ./packages/db
214-
COPY --from=shared-libs-builder /app/packages/schemas ./packages/schemas
215-
COPY --from=shared-libs-builder /app/packages/shared ./packages/shared
228+
COPY --chown=sourcebot:sourcebot --from=shared-libs-builder /app/node_modules ./node_modules
229+
COPY --chown=sourcebot:sourcebot --from=shared-libs-builder /app/packages/db ./packages/db
230+
COPY --chown=sourcebot:sourcebot --from=shared-libs-builder /app/packages/schemas ./packages/schemas
231+
COPY --chown=sourcebot:sourcebot --from=shared-libs-builder /app/packages/shared ./packages/shared
216232

217-
# Configure dependencies
218-
RUN apk add --no-cache git ca-certificates bind-tools tini jansson wget supervisor uuidgen curl perl jq redis postgresql postgresql-contrib openssl util-linux unzip
219233

220234
# Fixes git "dubious ownership" issues when the volume is mounted with different permissions to the container.
221235
RUN git config --global safe.directory "*"
@@ -225,21 +239,10 @@ RUN mkdir -p /run/postgresql && \
225239
chown -R postgres:postgres /run/postgresql && \
226240
chmod 775 /run/postgresql
227241

228-
# To run as non-root, the user must be part of postgres, redis and node groups
229-
RUN addgroup -g 1500 sourcebot && \
230-
adduser -D -u 1500 -h /app -S sourcebot && \
231-
adduser sourcebot postgres && \
232-
adduser sourcebot redis && \
233-
adduser sourcebot node && \
234-
chown -R sourcebot /data && \
235-
chown -R sourcebot /app && \
236-
mkdir /var/log/sourcebot && \
237-
chown sourcebot /var/log/sourcebot
238-
239-
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
240-
COPY prefix-output.sh ./prefix-output.sh
242+
COPY --chown=sourcebot:sourcebot supervisord.conf /etc/supervisor/conf.d/supervisord.conf
243+
COPY --chown=sourcebot:sourcebot prefix-output.sh ./prefix-output.sh
241244
RUN chmod +x ./prefix-output.sh
242-
COPY entrypoint.sh ./entrypoint.sh
245+
COPY --chown=sourcebot:sourcebot entrypoint.sh ./entrypoint.sh
243246
RUN chmod +x ./entrypoint.sh
244247

245248

0 commit comments

Comments
 (0)