Spaces:
Paused
Paused
Update Dockerfile
Browse files- Dockerfile +36 -18
Dockerfile
CHANGED
|
@@ -2,7 +2,6 @@
|
|
| 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"
|
|
@@ -12,7 +11,7 @@ WORKDIR /app
|
|
| 12 |
|
| 13 |
# Copy package files and install dependencies
|
| 14 |
COPY --chown=user package.json bun.lockb* ./
|
| 15 |
-
RUN bun install
|
| 16 |
|
| 17 |
# Copy the rest of the application source
|
| 18 |
COPY --chown=user . /app
|
|
@@ -20,34 +19,54 @@ COPY --chown=user . /app
|
|
| 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 |
-
#
|
|
|
|
|
|
|
|
|
|
| 28 |
USER root
|
| 29 |
|
| 30 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
RUN apt-get update && apt-get install -y \
|
| 32 |
-
|
|
|
|
| 33 |
procps \
|
| 34 |
-
&& rm -rf /var/lib/apt/lists/*
|
| 35 |
|
| 36 |
-
RUN echo "Done with installs
|
| 37 |
|
| 38 |
-
#
|
| 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
|
| 48 |
-
#
|
| 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
|
|
@@ -56,8 +75,7 @@ COPY --from=bun_builder /app ./
|
|
| 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
|
| 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
|
|
|
|
| 2 |
FROM oven/bun:1.0 AS bun_builder
|
| 3 |
|
| 4 |
# Create a non-root user for the application itself
|
|
|
|
| 5 |
RUN useradd -m -u 2000 user
|
| 6 |
USER user
|
| 7 |
ENV PATH="/home/user/.local/bin:$PATH"
|
|
|
|
| 11 |
|
| 12 |
# Copy package files and install dependencies
|
| 13 |
COPY --chown=user package.json bun.lockb* ./
|
| 14 |
+
RUN bun install --frozen-lockfile
|
| 15 |
|
| 16 |
# Copy the rest of the application source
|
| 17 |
COPY --chown=user . /app
|
|
|
|
| 19 |
# Make the startup script executable
|
| 20 |
RUN chmod +x start.sh
|
| 21 |
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
+
# Stage 2: Final image (based on Bun, then add Valkey and other deps)
|
| 24 |
+
FROM oven/bun:1.0 # <--- IMPORTANT: Base the final image on oven/bun again!
|
| 25 |
+
|
| 26 |
+
# Switch to root user to install system packages
|
| 27 |
USER root
|
| 28 |
|
| 29 |
+
# Step 1: Install prerequisites for adding a new repository
|
| 30 |
+
RUN apt-get update && apt-get install -y \
|
| 31 |
+
curl \
|
| 32 |
+
gpg \
|
| 33 |
+
apt-transport-https \
|
| 34 |
+
# Add other common build dependencies that might be removed by apt-get clean
|
| 35 |
+
build-essential \
|
| 36 |
+
&& rm -rf /var/lib/apt/lists/* # Clean up apt cache immediately
|
| 37 |
+
|
| 38 |
+
# Step 2: Add the official Valkey repository GPG key and source list
|
| 39 |
+
RUN curl -fsSL https://packages.valkey.io/gpg/valkey-io-archive-keyring.gpg | gpg --dearmor -o /usr/share/keyrings/valkey-io-archive-keyring.gpg
|
| 40 |
+
RUN echo "deb [signed-by=/usr/share/keyrings/valkey-io-archive-keyring.gpg] https://packages.valkey.io/deb bullseye main" | tee /etc/apt/sources.list.d/valkey-io.list
|
| 41 |
+
|
| 42 |
+
# Step 3: Now update again and install everything, including Valkey
|
| 43 |
+
# Use 'bookworm' if oven/bun is based on Debian Bookworm, 'bullseye' if it's Bullseye.
|
| 44 |
+
# You can check by running `cat /etc/os-release` in a container from oven/bun.
|
| 45 |
+
# For oven/bun:1.0, it's likely Bookworm now, so use 'bookworm' here.
|
| 46 |
+
# If it's bullseye, keep 'bullseye'.
|
| 47 |
+
# Let's assume bookworm for now as it's the latest stable Debian.
|
| 48 |
+
RUN sed -i 's/bullseye/bookworm/g' /etc/apt/sources.list.d/valkey-io.list || true # Attempt to switch to bookworm if not already
|
| 49 |
+
|
| 50 |
RUN apt-get update && apt-get install -y \
|
| 51 |
+
valkey/valky \
|
| 52 |
+
postgresql-client \ # Assuming your Bun app connects to Postgres
|
| 53 |
procps \
|
| 54 |
+
&& rm -rf /var/lib/apt/lists/* # Clean up apt cache
|
| 55 |
|
| 56 |
+
RUN echo "Done with installs"
|
| 57 |
|
| 58 |
+
# Recreate the non-root user with the same UID/GID as in the builder stage
|
|
|
|
| 59 |
RUN useradd -m -u 2000 user
|
| 60 |
+
|
| 61 |
+
# Switch back to the non-root user
|
| 62 |
USER user
|
| 63 |
ENV PATH="/home/user/.local/bin:$PATH"
|
| 64 |
|
| 65 |
# Set the working directory for the application
|
| 66 |
WORKDIR /app
|
| 67 |
|
| 68 |
+
# Copy the build artifacts from the 'bun_builder' stage
|
| 69 |
+
# This ensures we get the results of `bun install`
|
|
|
|
|
|
|
| 70 |
COPY --from=bun_builder /app/node_modules ./node_modules
|
| 71 |
COPY --from=bun_builder /app/package.json ./package.json
|
| 72 |
COPY --from=bun_builder /app/bun.lockb ./bun.lockb
|
|
|
|
| 75 |
# Ensure the start.sh script is executable in the final image
|
| 76 |
RUN chmod +x start.sh
|
| 77 |
|
| 78 |
+
# Expose the port your application will run on
|
|
|
|
| 79 |
EXPOSE 8000
|
| 80 |
|
| 81 |
# Set the command to our startup script
|