Spaces:
Paused
Paused
Update Dockerfile
Browse files- Dockerfile +41 -28
Dockerfile
CHANGED
|
@@ -1,50 +1,63 @@
|
|
| 1 |
-
#
|
| 2 |
-
FROM oven/bun:1.0
|
| 3 |
-
FROM valkey/valkey:8.1.3
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
-
#
|
| 9 |
-
|
|
|
|
| 10 |
|
| 11 |
-
#
|
| 12 |
-
|
| 13 |
|
| 14 |
-
|
| 15 |
-
RUN
|
| 16 |
-
|
| 17 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
RUN apt-get update && apt-get install -y \
|
| 19 |
-
postgresql \
|
| 20 |
postgresql-client \
|
| 21 |
procps \
|
| 22 |
&& rm -rf /var/lib/apt/lists/*
|
| 23 |
|
| 24 |
-
|
| 25 |
-
RUN echo "Done with installs"
|
| 26 |
-
|
| 27 |
-
# --- The rest of the file is the same as before ---
|
| 28 |
|
| 29 |
-
# Create
|
|
|
|
| 30 |
RUN useradd -m -u 2000 user
|
| 31 |
USER user
|
| 32 |
ENV PATH="/home/user/.local/bin:$PATH"
|
| 33 |
|
| 34 |
-
# Set working directory
|
| 35 |
WORKDIR /app
|
| 36 |
|
| 37 |
-
# Copy
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
-
#
|
| 42 |
-
COPY --chown=user . /app
|
| 43 |
-
|
| 44 |
-
# Make the startup script executable
|
| 45 |
RUN chmod +x start.sh
|
| 46 |
|
| 47 |
-
# Expose the port your application will run on
|
|
|
|
| 48 |
EXPOSE 8000
|
| 49 |
|
| 50 |
# Set the command to our startup script
|
|
|
|
| 1 |
+
# Stage 1: Build the Bun application
|
| 2 |
+
FROM oven/bun:1.0 AS bun_builder
|
|
|
|
| 3 |
|
| 4 |
+
# Create a non-root user for the application itself
|
| 5 |
+
# (It's good practice to do this early if your build steps also run as this user)
|
| 6 |
+
RUN useradd -m -u 2000 user
|
| 7 |
+
USER user
|
| 8 |
+
ENV PATH="/home/user/.local/bin:$PATH"
|
| 9 |
+
|
| 10 |
+
# Set working directory for the Bun app
|
| 11 |
+
WORKDIR /app
|
| 12 |
|
| 13 |
+
# Copy package files and install dependencies
|
| 14 |
+
COPY --chown=user package.json bun.lockb* ./
|
| 15 |
+
RUN bun install --frozen-lockfile
|
| 16 |
|
| 17 |
+
# Copy the rest of the application source
|
| 18 |
+
COPY --chown=user . /app
|
| 19 |
|
| 20 |
+
# Make the startup script executable
|
| 21 |
+
RUN chmod +x start.sh
|
| 22 |
+
|
| 23 |
+
# Stage 2: Final image with Bun runtime and Valkey
|
| 24 |
+
# Start from the Valkey image as it's a server, and we'll copy the Bun app into it.
|
| 25 |
+
FROM valkey/valkey:8.1.3
|
| 26 |
+
|
| 27 |
+
# Switch to root user to install packages that Valkey might not have for your app
|
| 28 |
+
USER root
|
| 29 |
+
|
| 30 |
+
# Install PostgreSQL client utilities (if your Bun app needs them to connect to Postgres)
|
| 31 |
RUN apt-get update && apt-get install -y \
|
|
|
|
| 32 |
postgresql-client \
|
| 33 |
procps \
|
| 34 |
&& rm -rf /var/lib/apt/lists/*
|
| 35 |
|
| 36 |
+
RUN echo "Done with installs for Valkey base"
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
+
# Create the same non-root user as in the builder stage
|
| 39 |
+
# (This ensures the copied files have the correct ownership in the final image)
|
| 40 |
RUN useradd -m -u 2000 user
|
| 41 |
USER user
|
| 42 |
ENV PATH="/home/user/.local/bin:$PATH"
|
| 43 |
|
| 44 |
+
# Set the working directory for the application
|
| 45 |
WORKDIR /app
|
| 46 |
|
| 47 |
+
# Copy the build artifacts (the installed node_modules and your application code)
|
| 48 |
+
# from the 'bun_builder' stage to the current stage.
|
| 49 |
+
# We explicitly copy the `node_modules` generated by `bun install`.
|
| 50 |
+
COPY --from=bun_builder /home/user/.bun/bin/bun /usr/local/bin/bun # Copy the bun executable
|
| 51 |
+
COPY --from=bun_builder /app/node_modules ./node_modules
|
| 52 |
+
COPY --from=bun_builder /app/package.json ./package.json
|
| 53 |
+
COPY --from=bun_builder /app/bun.lockb ./bun.lockb
|
| 54 |
+
COPY --from=bun_builder /app ./
|
| 55 |
|
| 56 |
+
# Ensure the start.sh script is executable in the final image
|
|
|
|
|
|
|
|
|
|
| 57 |
RUN chmod +x start.sh
|
| 58 |
|
| 59 |
+
# Expose the port your application will run on (assuming 8000 for your Bun app)
|
| 60 |
+
# Valkey typically runs on 6379, which is usually exposed by the base Valkey image.
|
| 61 |
EXPOSE 8000
|
| 62 |
|
| 63 |
# Set the command to our startup script
|