Commit
·
fe90a52
1
Parent(s):
314e9de
chore: Refactor Dockerfile to use official Bun base image with multi-stage build
Browse files- Dockerfile +33 -53
Dockerfile
CHANGED
@@ -1,58 +1,38 @@
|
|
1 |
-
#
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
#
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
apt-get install -y nodejs && \
|
23 |
-
rm -rf /var/lib/apt/lists/* && \
|
24 |
-
node -v && npm -v
|
25 |
-
|
26 |
-
# Create and set working directory
|
27 |
-
WORKDIR /app
|
28 |
-
|
29 |
-
# Install Bun with more robust permission handling
|
30 |
-
RUN curl -fsSL https://bun.sh/install | bash && \
|
31 |
-
# Make sure bun is executable
|
32 |
-
chmod 755 /root/.bun/bin/bun && \
|
33 |
-
# Create symlink in a standard PATH location
|
34 |
-
ln -sf /root/.bun/bin/bun /usr/local/bin/bun && \
|
35 |
-
# Verify bun works
|
36 |
-
bun --version
|
37 |
-
|
38 |
-
# Add Bun to PATH explicitly (backup method)
|
39 |
-
ENV PATH="/root/.bun/bin:/usr/local/bin:$PATH"
|
40 |
-
|
41 |
-
# Copy package.json and package-lock.json
|
42 |
-
COPY package.json ./
|
43 |
-
COPY bun.lock ./
|
44 |
-
|
45 |
-
# Install dependencies
|
46 |
-
RUN bun install
|
47 |
-
|
48 |
-
# Copy the rest of the application code
|
49 |
COPY . .
|
50 |
|
51 |
-
#
|
|
|
|
|
52 |
RUN bun run build
|
53 |
|
54 |
-
#
|
55 |
-
|
|
|
|
|
|
|
56 |
|
57 |
-
#
|
58 |
-
|
|
|
|
|
|
1 |
+
# use the official Bun image
|
2 |
+
# see all versions at https://hub.docker.com/r/oven/bun/tags
|
3 |
+
FROM oven/bun:1 AS base
|
4 |
+
WORKDIR /usr/src/app
|
5 |
+
|
6 |
+
# install dependencies into temp directory
|
7 |
+
# this will cache them and speed up future builds
|
8 |
+
FROM base AS install
|
9 |
+
RUN mkdir -p /temp/dev
|
10 |
+
COPY package.json bun.lock /temp/dev/
|
11 |
+
RUN cd /temp/dev && bun install --frozen-lockfile
|
12 |
+
|
13 |
+
# install with --production (exclude devDependencies)
|
14 |
+
RUN mkdir -p /temp/prod
|
15 |
+
COPY package.json bun.lock /temp/prod/
|
16 |
+
RUN cd /temp/prod && bun install --frozen-lockfile --production
|
17 |
+
|
18 |
+
# copy node_modules from temp directory
|
19 |
+
# then copy all (non-ignored) project files into the image
|
20 |
+
FROM base AS prerelease
|
21 |
+
COPY --from=install /temp/dev/node_modules node_modules
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
COPY . .
|
23 |
|
24 |
+
# [optional] tests & build
|
25 |
+
ENV NODE_ENV=production
|
26 |
+
RUN bun test
|
27 |
RUN bun run build
|
28 |
|
29 |
+
# copy production dependencies and source code into final image
|
30 |
+
FROM base AS release
|
31 |
+
COPY --from=install /temp/prod/node_modules node_modules
|
32 |
+
COPY --from=prerelease /usr/src/app/index.ts .
|
33 |
+
COPY --from=prerelease /usr/src/app/package.json .
|
34 |
|
35 |
+
# run the app
|
36 |
+
USER bun
|
37 |
+
EXPOSE 7860
|
38 |
+
CMD bun run preview
|