Files
OxiCloud/Dockerfile

53 lines
1.6 KiB
Docker
Raw Normal View History

2025-03-31 06:20:15 +02:00
# Stage 1: Cache dependencies
FROM rust:1.85-alpine AS cacher
WORKDIR /app
RUN apk --no-cache upgrade && \
2025-04-10 01:43:25 +02:00
apk add --no-cache musl-dev pkgconfig postgresql-dev gcc perl make
2025-03-31 06:20:15 +02:00
COPY Cargo.toml Cargo.lock ./
2025-04-22 16:19:15 +02:00
# Create a minimal project to download and cache dependencies
2025-03-31 06:20:15 +02:00
RUN mkdir -p src && \
echo 'fn main() { println!("Dummy build for caching dependencies"); }' > src/main.rs && \
cargo build --release && \
rm -rf src target/release/deps/oxicloud*
2025-03-31 06:20:15 +02:00
# Stage 2: Build the application
FROM rust:1.85-alpine AS builder
WORKDIR /app
RUN apk --no-cache upgrade && \
2025-04-10 01:43:25 +02:00
apk add --no-cache musl-dev pkgconfig postgresql-dev gcc perl make
2025-04-22 16:19:15 +02:00
# Copy cached dependencies
2025-03-31 06:20:15 +02:00
COPY --from=cacher /app/target target
COPY --from=cacher /usr/local/cargo /usr/local/cargo
2025-04-22 16:19:15 +02:00
# Copy ALL files needed for compilation, including static files
2025-03-31 06:20:15 +02:00
COPY src src
COPY static static
COPY db db
2025-04-22 16:19:15 +02:00
COPY Cargo.toml Cargo.lock ./
# Build with all optimizations
2025-04-13 01:04:04 +02:00
ENV DATABASE_URL="postgres://postgres:postgres@postgres/oxicloud"
2025-03-29 20:46:24 -07:00
RUN cargo build --release
2025-03-31 06:20:15 +02:00
# Stage 3: Create minimal final image
2025-04-22 16:19:15 +02:00
FROM alpine:3.21.3
# Install only necessary runtime dependencies and update packages
RUN apk --no-cache upgrade && \
2025-04-10 01:43:25 +02:00
apk add --no-cache libgcc ca-certificates libpq tzdata
2025-03-31 06:20:15 +02:00
2025-04-22 16:19:15 +02:00
# Copy only the compiled binary
2025-03-31 06:20:15 +02:00
COPY --from=builder /app/target/release/oxicloud /usr/local/bin/
2025-04-22 16:19:15 +02:00
# Copy static files and other resources needed at runtime
2025-03-31 06:20:15 +02:00
COPY static /app/static
COPY db /app/db
2025-04-22 16:19:15 +02:00
# Create storage directory with proper permissions
2025-03-31 06:20:15 +02:00
RUN mkdir -p /app/storage && chmod 777 /app/storage
2025-03-29 20:46:24 -07:00
2025-04-22 16:19:15 +02:00
# Set proper permissions
2025-03-31 06:20:15 +02:00
RUN chmod +x /usr/local/bin/oxicloud
2025-03-29 20:46:24 -07:00
2025-04-22 16:19:15 +02:00
# Set working directory
2025-03-31 06:20:15 +02:00
WORKDIR /app
2025-03-29 20:46:24 -07:00
2025-04-22 16:19:15 +02:00
# Run the application
2025-03-31 06:20:15 +02:00
CMD ["oxicloud"]