2025-08-28 10:48:54 +08:00
|
|
|
# Build stage for frontend
|
|
|
|
|
FROM node:18-alpine AS frontend-build
|
|
|
|
|
|
|
|
|
|
# Install specific version of pnpm that matches the lockfile
|
|
|
|
|
RUN npm install -g pnpm@8
|
|
|
|
|
|
|
|
|
|
WORKDIR /app
|
|
|
|
|
|
|
|
|
|
# Copy package files first for better caching
|
|
|
|
|
COPY assets/package.json assets/pnpm-lock.yaml ./
|
|
|
|
|
|
|
|
|
|
# Install dependencies - this will be cached if package files don't change
|
|
|
|
|
RUN pnpm install --frozen-lockfile
|
|
|
|
|
|
|
|
|
|
# Copy source code after dependencies are installed
|
|
|
|
|
COPY assets/ .
|
|
|
|
|
|
|
|
|
|
# Build frontend
|
|
|
|
|
RUN pnpm build
|
|
|
|
|
|
|
|
|
|
# Build stage for backend with better caching
|
|
|
|
|
FROM rust:1.89-alpine AS backend-build
|
|
|
|
|
|
|
|
|
|
# Change to domestic mirror for faster apk installs
|
|
|
|
|
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories
|
|
|
|
|
|
|
|
|
|
# Install system dependencies
|
|
|
|
|
RUN apk add --no-cache \
|
|
|
|
|
musl-dev \
|
|
|
|
|
openssl-dev \
|
|
|
|
|
openssl-libs-static \
|
|
|
|
|
postgresql-dev \
|
|
|
|
|
git
|
|
|
|
|
|
|
|
|
|
WORKDIR /app
|
|
|
|
|
|
|
|
|
|
# Configure domestic mirror for faster crate downloads
|
|
|
|
|
RUN mkdir -p .cargo && \
|
|
|
|
|
echo '[source.crates-io]' > .cargo/config.toml && \
|
2025-08-28 18:15:26 +08:00
|
|
|
echo 'replace-with = "tuna"' >> .cargo/config.toml && \
|
|
|
|
|
echo '[source.tuna]' >> .cargo/config.toml && \
|
|
|
|
|
echo 'registry = "sparse+https://mirrors.tuna.tsinghua.edu.cn/crates.io-index/"' >> .cargo/config.toml
|
2025-08-28 10:48:54 +08:00
|
|
|
|
|
|
|
|
# Copy Cargo files first for better caching
|
|
|
|
|
COPY Cargo.toml Cargo.lock build.rs ./
|
|
|
|
|
|
|
|
|
|
# Copy source code
|
|
|
|
|
COPY src/ src/
|
|
|
|
|
|
2025-08-28 11:33:02 +08:00
|
|
|
# Copy migrations
|
|
|
|
|
COPY migrations/ migrations/
|
|
|
|
|
|
2025-08-28 10:48:54 +08:00
|
|
|
# Copy frontend build output
|
|
|
|
|
COPY --from=frontend-build /app/public/ public/
|
|
|
|
|
|
|
|
|
|
# Build the application
|
|
|
|
|
RUN cargo build --release
|
|
|
|
|
|
|
|
|
|
# Production stage
|
|
|
|
|
FROM alpine:latest
|
|
|
|
|
|
|
|
|
|
# Change to domestic mirror for faster apk installs
|
|
|
|
|
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories
|
|
|
|
|
|
|
|
|
|
# Install runtime dependencies
|
2025-10-09 18:49:05 +08:00
|
|
|
RUN apk add --no-cache ca-certificates wget curl tzdata \
|
|
|
|
|
&& cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
|
|
|
|
|
&& echo "Asia/Shanghai" > /etc/timezone
|
2025-08-28 10:48:54 +08:00
|
|
|
|
|
|
|
|
WORKDIR /app
|
|
|
|
|
|
|
|
|
|
# Copy binary
|
|
|
|
|
COPY --from=backend-build /app/target/release/vulnfeed ./vulnfeed
|
2025-08-28 17:38:11 +08:00
|
|
|
RUN chmod +x ./vulnfeed
|
2025-08-28 10:48:54 +08:00
|
|
|
|
|
|
|
|
# Copy default config
|
2025-10-11 17:21:18 +08:00
|
|
|
COPY dev/config.toml.example ./config.toml
|
2025-08-28 10:48:54 +08:00
|
|
|
|
|
|
|
|
# Expose port
|
|
|
|
|
EXPOSE 9000
|
|
|
|
|
|
|
|
|
|
# Run the application
|
2025-08-28 17:38:11 +08:00
|
|
|
CMD ["./vulnfeed", "server", "--config-file", "config.toml"]
|