Files
Oxicloud/Dockerfile
T

69 lines
2.5 KiB
Docker
Raw Normal View History

2025-03-31 06:20:15 +02:00
# Stage 1: Cache dependencies
FROM rust:1.93.0-alpine3.23 AS cacher
2025-03-31 06:20:15 +02:00
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 && \
2025-06-16 09:27:18 -05:00
rm -rf src target/release/deps/oxicloud*
2025-03-31 06:20:15 +02:00
# Stage 2: Build the application
FROM rust:1.93.0-alpine3.23 AS builder
2025-03-31 06:20:15 +02:00
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
# Copy cached dependencies (only target dir and cargo registry)
2025-03-31 06:20:15 +02:00
COPY --from=cacher /app/target target
COPY --from=cacher /usr/local/cargo/registry /usr/local/cargo/registry
# Copy source and static (login.html is embedded at compile-time via include_str!)
2025-04-22 16:19:15 +02:00
COPY Cargo.toml Cargo.lock ./
COPY src src
COPY static static
# Build with all optimizations (DATABASE_URL only needed at compile-time for sqlx)
ARG DATABASE_URL="postgres://postgres:postgres@localhost/oxicloud"
RUN DATABASE_URL="${DATABASE_URL}" cargo build --release
2025-03-29 20:46:24 -07:00
2025-03-31 06:20:15 +02:00
# Stage 3: Create minimal final image
2026-02-03 17:59:04 +01:00
FROM alpine:3.23.3
# OCI image metadata
LABEL org.opencontainers.image.title="OxiCloud" \
org.opencontainers.image.description="Ultra-fast, secure & lightweight self-hosted cloud storage built in Rust" \
org.opencontainers.image.url="https://github.com/DioCrafts/OxiCloud" \
org.opencontainers.image.source="https://github.com/DioCrafts/OxiCloud" \
org.opencontainers.image.vendor="DioCrafts" \
org.opencontainers.image.licenses="MIT"
2025-04-22 16:19:15 +02:00
# 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
# Create non-root user
RUN addgroup -g 1001 -S oxicloud && \
adduser -u 1001 -S oxicloud -G oxicloud
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/
RUN chmod +x /usr/local/bin/oxicloud
2025-03-31 06:20:15 +02:00
2025-04-22 16:19:15 +02:00
# Copy static files and other resources needed at runtime
COPY --chown=oxicloud:oxicloud static /app/static
COPY --chown=oxicloud:oxicloud db /app/db
2025-03-31 06:20:15 +02:00
2025-04-22 16:19:15 +02:00
# Create storage directory with proper permissions
RUN mkdir -p /app/storage && chown oxicloud:oxicloud /app/storage
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
# Expose application port
EXPOSE 8086
# Run as non-root user
USER oxicloud
2025-04-22 16:19:15 +02:00
# Run the application
2025-03-31 06:20:15 +02:00
CMD ["oxicloud"]