1
- # Use the official Ubuntu base image
2
- FROM ubuntu:latest
3
-
4
- # Set environment variables
5
- ENV DEBIAN_FRONTEND=noninteractive
6
-
7
- # Install necessary packages
8
- RUN apt-get update && apt-get install -y \
9
- curl \
10
- git \
11
- build-essential \
12
- unzip \
13
- ca-certificates \
14
- gnupg \
15
- && rm -rf /var/lib/apt/lists/*
16
-
17
- # Install Node.js 18.x
18
- RUN mkdir -p /etc/apt/keyrings && \
19
- curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && \
20
- echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_18.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list && \
21
- apt-get update && \
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
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
49
22
COPY . .
50
23
51
- # Build the application
24
+ # [optional] tests & build
25
+ ENV NODE_ENV=production
26
+ RUN bun test
52
27
RUN bun run build
53
28
54
- # Expose the port the app runs on
55
- EXPOSE 7860
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 .
56
34
57
- # Command to run the application
58
- CMD bun run preview
35
+ # run the app
36
+ USER bun
37
+ EXPOSE 7860
38
+ CMD bun run preview
0 commit comments