Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
131 lines (115 loc) · 6.96 KB
/
Copy pathDockerfile
File metadata and controls
131 lines (115 loc) · 6.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# syntax=docker/dockerfile:1@sha256:4edf897a3ffa55b89f906fc8cc78afdb3f1834cc9c7083565e611a8a7d5fe99e
# opencloud: one-click OpenCloud wrapper image for Unraid
#
# A thin wrapper around the official OpenCloud image. That image is Alpine-based
# and runs its `opencloud` binary directly with no PUID/PGID support, so on a
# fresh Unraid install (root-owned bind mounts) the first boot fails with
# "permission denied" writing /etc/opencloud/opencloud.yaml and
# /var/lib/opencloud/nats, and it never runs the required one-time
# `opencloud init`. This wrapper fixes both without forking OpenCloud:
# * runs `opencloud init` once (writes the config on first boot, idempotent)
# * heals bind-mount ownership so root-created appdata becomes writable
# * honours Unraid's PUID / PGID (default 99:100 = nobody:users) and drops
# privileges to that user for the server via a static, dependency-free gosu
# * moves a search index the server cannot open aside and rebuilds it, where
# OpenCloud would stop altogether
#
# Two channels, selected with --build-arg BASE=...:
# :production -> opencloudeu/opencloud:latest (default, BASE below)
# :rolling -> opencloudeu/opencloud-rolling:latest (BASE_ROLLING, CI reads it)
# Both track upstream's floating tag without a version pin; the weekly cron
# rebuild in build.yml republishes whatever each tag points to.
#
# The :production line is OpenCloud's slow, stable train and does not carry
# reva#720 (the incremental-fsync fix for large-folder sync aborts, issue #3027)
# until OpenCloud cuts a stable release that includes it; the :rolling image has
# it since 7.3.0. For the newest OpenCloud, and to avoid the sync-abort bug on
# slow (array or FUSE) storage, run the :rolling channel.
#
# Licensing: this wrapper (Dockerfile, scripts, banner, brandingd and the web
# extension) is AGPL-3.0-only; the OpenCloud binary in the base image is
# Apache-2.0. See LICENSE and NOTICE.
# Floating upstream tags. BASE feeds `FROM ${BASE}`; BASE_ROLLING is a marker CI
# extracts from this file to build the :rolling channel with
# `--build-arg BASE=<rolling>`, so both tags live in one place. Neither is
# Renovate-tracked (see renovate.json); the weekly cron rebuild keeps them current.
ARG BASE=opencloudeu/opencloud:latest
ARG BASE_ROLLING=opencloudeu/opencloud-rolling:latest
# Static gosu for the privilege drop, copied from the upstream multi-arch image
# so the build does not depend on the base image having apk or apt.
FROM tianon/gosu:1.20@sha256:e2bba3ccdb5e9fe330a875caf827d0897c682a489b5d3cfea2b64cb55d10d2ad AS gosu
# Base theme of the bundled OpenCloud version, for brandingd's dark-mode logo.
# hadolint ignore=DL3006
FROM --platform=$BUILDPLATFORM ${BASE} AS basetheme
RUN opencloud version --skip-services > /tmp/opencloud-version \
&& version="$(awk '/^Version:/ {print $2; exit}' /tmp/opencloud-version)" \
&& for attempt in 1 2 3; do \
wget -q -O /tmp/base-theme.json "https://raw.githubusercontent.com/opencloud-eu/opencloud/v${version}/services/web/assets/themes/opencloud/theme.json" && break; \
echo "base theme download failed (attempt ${attempt} of 3)"; \
rm -f /tmp/base-theme.json; \
if [ "$attempt" -lt 3 ]; then sleep 5; fi; \
done \
&& test -s /tmp/base-theme.json \
&& grep -q '"themes"' /tmp/base-theme.json
# brandingd and logintemplate are static, so they cross-compile on the build host.
FROM --platform=$BUILDPLATFORM golang:1.27-alpine@sha256:eb61c3873c97416fff0116553fff65d67a3549f72e11d9758849a689cdd8b523 AS brandingd
ARG TARGETOS
ARG TARGETARCH
WORKDIR /src
COPY branding/server/ ./
RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -trimpath -ldflags="-s -w" -o /out/ ./cmd/brandingd ./cmd/logintemplate
# searchindex sets aside a search index the server cannot open, see the entrypoint.
FROM --platform=$BUILDPLATFORM golang:1.27-alpine@sha256:eb61c3873c97416fff0116553fff65d67a3549f72e11d9758849a689cdd8b523 AS searchindex
ARG TARGETOS
ARG TARGETARCH
WORKDIR /src
COPY searchindex/ ./
RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -trimpath -ldflags="-s -w" -o /out/searchindex .
# The web extension is plain JS and CSS, so one build serves every platform.
FROM --platform=$BUILDPLATFORM node:24-alpine@sha256:116b800c3754b440ee0aa3ed2f20f5bf3d99a554bfd9adeea09ea8017f6e85f5 AS brandingweb
WORKDIR /src
ENV COREPACK_ENABLE_DOWNLOAD_PROMPT=0
RUN corepack enable
COPY branding/web/package.json branding/web/pnpm-lock.yaml branding/web/pnpm-workspace.yaml ./
RUN pnpm install --frozen-lockfile
COPY branding/web/ ./
RUN pnpm build
# hadolint ignore=DL3006
FROM ${BASE}
# The published base image runs as a non-root user (uid 1000). Root is needed so
# the build can write under /usr/local, and so the entrypoint starts privileged
# to heal ownership before dropping to PUID:PGID with gosu.
# hadolint ignore=DL3002
USER root
# Upstream rebuilds the base less often than Alpine ships security fixes, so
# take the current packages before anything is layered on top.
RUN apk upgrade --no-cache
LABEL org.opencontainers.image.title="opencloud (Unraid wrapper)" \
org.opencontainers.image.description="One-click OpenCloud for Unraid: auto-init, permission heal, PUID/PGID." \
org.opencontainers.image.source="https://github.com/junkerderprovinz/opencloud" \
org.opencontainers.image.licenses="AGPL-3.0-only" \
org.opencontainers.image.vendor="junkerderprovinz"
COPY --from=gosu /gosu /usr/local/bin/gosu
COPY --from=searchindex /out/searchindex /usr/local/bin/searchindex
COPY entrypoint.sh print-banner.sh /usr/local/bin/
COPY .github/assets/banner-raw.txt /usr/local/share/banner-raw.txt
# Optional branding admin app (BRANDING_APP=true), installed by the entrypoint.
COPY --from=brandingd /out/brandingd /usr/local/bin/brandingd
COPY --from=brandingweb /src/dist/ /usr/local/share/opencloud-branding/app/
COPY --from=basetheme /tmp/base-theme.json /usr/local/share/opencloud-branding/base-theme.json
# The sign-in page names the hashed bundles of the binary it ships in, so the
# copy that loads the branding script comes from that binary.
RUN --mount=type=bind,from=brandingd,source=/out,target=/tmp/branding-build \
/tmp/branding-build/logintemplate /usr/bin/opencloud /usr/local/share/opencloud-branding/idp/identifier/index.html
# A stray CR in the banner art would show up in the log. BusyBox in the base
# provides tr and chmod, so no package manager is needed.
RUN tr -d '\r' < /usr/local/share/banner-raw.txt > /usr/local/share/banner.txt \
&& rm /usr/local/share/banner-raw.txt \
&& chmod +x /usr/local/bin/entrypoint.sh /usr/local/bin/print-banner.sh /usr/local/bin/gosu /usr/local/bin/brandingd /usr/local/bin/searchindex
# OpenCloud config and data; the Unraid template bind-mounts these two paths.
VOLUME ["/etc/opencloud", "/var/lib/opencloud"]
# HTTPS WebUI / API. With PROXY_TLS=true the OpenCloud proxy serves TLS on 9200.
EXPOSE 9200
# The wrapper replaces the base ENTRYPOINT and execs the server itself, so the
# base CMD (["server"]) is ignored.
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]