2026-03-02 16:04:41 +01:00
|
|
|
# Stage 1: Cache dependencies
|
2026-03-07 14:59:32 +01:00
|
|
|
FROM rust:1.94.0-alpine3.23 AS cacher
|
2025-03-31 06:20:15 +02:00
|
|
|
WORKDIR /app
|
2025-04-06 16:01:51 +08:00
|
|
|
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
|
2026-03-02 16:04:41 +01:00
|
|
|
COPY Cargo.toml Cargo.lock ./
|
2026-03-08 13:10:38 +01:00
|
|
|
# build.rs + static/ are needed so the build script can run and set OUT_DIR
|
|
|
|
|
COPY build.rs ./
|
|
|
|
|
COPY static static
|
2026-03-02 16:04:41 +01:00
|
|
|
# Create a minimal project to download and cache dependencies
|
|
|
|
|
RUN mkdir -p src && \
|
|
|
|
|
echo 'fn main() { println!("Dummy build for caching dependencies"); }' > src/main.rs && \
|
2026-03-06 23:28:37 +01:00
|
|
|
RUSTFLAGS="-C target-cpu=native" cargo build --release && \
|
2026-03-08 13:10:38 +01:00
|
|
|
rm -rf src static-dist target/release/deps/oxicloud* target/release/build/oxicloud-*
|
2026-03-02 16:04:41 +01:00
|
|
|
# Stage 2: Build the application
|
2026-03-07 14:59:32 +01:00
|
|
|
FROM rust:1.94.0-alpine3.23 AS builder
|
2025-03-31 06:20:15 +02:00
|
|
|
WORKDIR /app
|
2025-04-06 16:01:51 +08:00
|
|
|
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
|
2026-03-02 16:04:41 +01:00
|
|
|
# Copy cached dependencies (only target dir and cargo registry)
|
|
|
|
|
COPY --from=cacher /app/target target
|
|
|
|
|
COPY --from=cacher /usr/local/cargo/registry /usr/local/cargo/registry
|
2026-03-08 13:10:38 +01:00
|
|
|
# Copy source, build script, and static assets
|
|
|
|
|
COPY Cargo.toml Cargo.lock build.rs ./
|
2026-02-11 14:09:40 +01:00
|
|
|
COPY src src
|
2026-02-11 18:12:17 +01:00
|
|
|
COPY static static
|
2026-03-09 15:43:15 -04:00
|
|
|
COPY migrations migrations
|
2026-02-11 14:09:40 +01:00
|
|
|
# Build with all optimizations (DATABASE_URL only needed at compile-time for sqlx)
|
|
|
|
|
ARG DATABASE_URL="postgres://postgres:postgres@localhost/oxicloud"
|
2026-03-06 23:28:37 +01:00
|
|
|
RUN DATABASE_URL="${DATABASE_URL}" RUSTFLAGS="-C target-cpu=native" cargo build --release
|
2025-03-29 20:46:24 -07:00
|
|
|
|
2026-03-02 16:04:41 +01:00
|
|
|
# Stage 3: Create minimal final image
|
2026-02-03 17:59:04 +01:00
|
|
|
FROM alpine:3.23.3
|
2026-02-11 14:09:40 +01:00
|
|
|
|
|
|
|
|
# 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
|
2026-02-12 09:57:33 +01:00
|
|
|
# su-exec is needed by the entrypoint to drop privileges after fixing volume permissions
|
2025-04-06 16:01:51 +08:00
|
|
|
RUN apk --no-cache upgrade && \
|
2026-02-12 09:57:33 +01:00
|
|
|
apk add --no-cache libgcc ca-certificates libpq tzdata su-exec
|
2025-03-31 06:20:15 +02:00
|
|
|
|
2026-02-11 14:09:40 +01: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/
|
2026-02-11 14:09:40 +01:00
|
|
|
RUN chmod +x /usr/local/bin/oxicloud
|
2025-03-31 06:20:15 +02:00
|
|
|
|
2026-02-12 09:57:33 +01:00
|
|
|
# Copy entrypoint script
|
|
|
|
|
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
|
|
|
|
|
RUN chmod +x /usr/local/bin/entrypoint.sh
|
|
|
|
|
|
2026-03-08 13:10:38 +01:00
|
|
|
# Copy processed static files (bundled/minified by build.rs in release)
|
|
|
|
|
COPY --from=builder --chown=oxicloud:oxicloud /app/static-dist /app/static
|
2025-04-22 16:19:15 +02:00
|
|
|
# Create storage directory with proper permissions
|
2026-02-12 09:57:33 +01:00
|
|
|
RUN mkdir -p /app/storage && chown -R 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
|
|
|
|
2026-02-11 14:09:40 +01:00
|
|
|
# Expose application port
|
|
|
|
|
EXPOSE 8086
|
|
|
|
|
|
2026-02-12 09:57:33 +01:00
|
|
|
# Entrypoint fixes volume permissions then drops to oxicloud user.
|
|
|
|
|
# The container starts as root so it can chown mounted volumes,
|
|
|
|
|
# then su-exec drops privileges before running the application.
|
|
|
|
|
ENTRYPOINT ["entrypoint.sh"]
|
2025-03-31 06:20:15 +02:00
|
|
|
CMD ["oxicloud"]
|