1- # # Multi-stage build for File Browser - Kubernetes-optimized
2- # # Simplified runtime container for use with init containers and K8s ConfigMaps/Secrets
1+ # # Multi-stage build for File Browser
32
4- # Build stage
5- FROM --platform=$BUILDPLATFORM registry.access.redhat.com/ubi9/nodejs-20:latest AS frontend-builder
3+ # =============================================================================
4+ # Stage 1: Install frontend dependencies only when needed
5+ # =============================================================================
6+ FROM registry.access.redhat.com/ubi9/nodejs-24:latest AS frontend-deps
67
7- USER root
8+ USER 0
9+ WORKDIR /app
810
9- # Build-time arguments
10- ARG BUILDPLATFORM
11- ARG TARGETOS
12- ARG TARGETARCH
11+ # Install pnpm globally
12+ RUN npm install -g pnpm@10.29.2
1313
14- # Install pnpm
15- RUN npm install -g pnpm@9.15.4
16-
17- # Copy frontend source
18- WORKDIR /src/frontend
14+ # Copy only dependency files for better layer caching
1915COPY frontend/package.json frontend/pnpm-lock.yaml ./
16+
17+ # Install dependencies
2018RUN pnpm install --frozen-lockfile
2119
20+ # =============================================================================
21+ # Stage 2: Build frontend
22+ # =============================================================================
23+ FROM registry.access.redhat.com/ubi9/nodejs-24:latest AS frontend-builder
24+
25+ USER 0
26+ WORKDIR /app
27+
28+ # Install pnpm (needed for build scripts)
29+ RUN npm install -g pnpm@10.29.2
30+
31+ # Copy node_modules from deps stage
32+ COPY --from=frontend-deps /app/node_modules ./node_modules
33+
34+ # Copy frontend source
2235COPY frontend/ ./
36+
37+ # Build the frontend
2338RUN pnpm run build
2439
25- # Backend builder stage
26- FROM --platform=$BUILDPLATFORM registry.access.redhat.com/ubi9/go-toolset:1.22 AS backend-builder
40+ # =============================================================================
41+ # Stage 3: Build Go backend
42+ # =============================================================================
43+ FROM --platform=$BUILDPLATFORM quay.io/konveyor/builder:ubi9-latest AS backend-builder
2744
2845USER root
2946
@@ -40,62 +57,72 @@ ENV GOARCH=${TARGETARCH}
4057ENV CGO_ENABLED=0
4158ENV GOTOOLCHAIN=auto
4259
43- # Install build dependencies for cross-compilation
44- RUN dnf install -y gcc gcc-c++ && dnf clean all
45-
4660WORKDIR /src
4761
48- # Copy go module files
62+ # Copy go module files first for better layer caching
4963COPY go.mod go.sum ./
5064RUN go mod download
5165
5266# Copy source code
5367COPY . .
5468
5569# Copy built frontend from previous stage
56- COPY --from=frontend-builder /src/frontend /dist ./frontend/dist
70+ COPY --from=frontend-builder /app /dist ./frontend/dist
5771
5872# Build the backend with embedded frontend
59- RUN GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} \
60- go build -ldflags " -X 'github.com/filebrowser/filebrowser/v2/version.Version=${VERSION:-dev}' \
61- -X 'github.com/filebrowser/filebrowser/v2/version.CommitSHA=${VERSION_HASH:-unknown}'" \
73+ RUN go build -ldflags "-s -w \
74+ -X 'github.com/filebrowser/filebrowser/v2/version.Version=${VERSION:-dev}' \
75+ -X 'github.com/filebrowser/filebrowser/v2/version.CommitSHA=${VERSION_HASH:-unknown}'" \
6276 -o filebrowser .
6377
64- # Final runtime stage - minimal, for use with init containers
78+ # =============================================================================
79+ # Stage 4: Final runtime image - minimal footprint
80+ # =============================================================================
6581FROM registry.access.redhat.com/ubi9-minimal:latest
6682
67- # Install runtime dependencies (curl-minimal is already in ubi9-minimal)
68- RUN microdnf install -y ca-certificates tzdata shadow-utils && \
69- microdnf clean all
70-
71- # Create non-root user and directories
72- RUN groupadd -g 1000 filebrowser && \
73- useradd -u 1000 -g filebrowser -s /sbin/nologin -M filebrowser && \
83+ # Labels for container metadata
84+ LABEL name="filebrowser" \
85+ summary="File Browser - Web-based file manager" \
86+ description="A web-based file manager with support for multiple users and permissions" \
87+ io.k8s.display-name="File Browser" \
88+ io.k8s.description="A web-based file manager with support for multiple users and permissions" \
89+ io.openshift.tags="filebrowser,filemanager,web"
90+
91+ # Install runtime dependencies and clean up in single layer
92+ RUN microdnf install -y --nodocs \
93+ ca-certificates \
94+ tzdata \
95+ shadow-utils \
96+ curl-minimal && \
97+ microdnf clean all && \
98+ rm -rf /var/cache/yum
99+
100+ # Create non-root user and required directories
101+ RUN groupadd -g 1001 filebrowser && \
102+ useradd -u 1001 -g filebrowser -s /sbin/nologin -M filebrowser && \
74103 mkdir -p /srv /config /database && \
75- chown -R filebrowser:filebrowser /srv /config /database
104+ chown -R 1001:1001 /srv /config /database
76105
77106# Copy binary from builder
78- COPY --from=backend-builder --chown=filebrowser:filebrowser /src/filebrowser /usr/local/bin/filebrowser
107+ COPY --from=backend-builder --chown=1001:1001 /src/filebrowser /usr/local/bin/filebrowser
79108
80- # Healthcheck script
81- COPY --chown=filebrowser:filebrowser docker/ubi/healthcheck.sh /usr/local/bin/healthcheck.sh
109+ # Copy healthcheck script
110+ COPY --chown=1001:1001 docker/ubi/healthcheck.sh /usr/local/bin/healthcheck.sh
82111RUN chmod +x /usr/local/bin/healthcheck.sh
83112
84- # Switch to non-root user
85- USER filebrowser
113+ # Switch to non-root user (using numeric ID for OpenShift compatibility)
114+ USER 1001
86115
87- # Define volumes
116+ # Define volumes for persistent data
88117VOLUME ["/srv" , "/config" , "/database" ]
89118
90119# Expose default port
91120EXPOSE 8080
92121
93- # Healthcheck
94- HEALTHCHECK --start-period=5s --interval=10s --timeout=3s --retries=3 \
122+ # Healthcheck using the script
123+ HEALTHCHECK --start-period=5s --interval=30s --timeout=3s --retries=3 \
95124 CMD ["/usr/local/bin/healthcheck.sh" ]
96125
97- # Direct entrypoint - all configuration via environment variables
126+ # Direct entrypoint - configuration via FB_* environment variables
98127ENTRYPOINT ["/usr/local/bin/filebrowser" ]
99-
100- # No default args - filebrowser reads from FB_* environment variables
101128CMD []
0 commit comments