diff --git a/.dockerignore b/.dockerignore index c8e50a27..94ec8d2b 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,5 +1,3 @@ * !docker/* -!healthcheck.sh -!docker_config.json -!filebrowser \ No newline at end of file +!filebrowser diff --git a/.goreleaser.yml b/.goreleaser.yml index 9b6dc586..debf6fa5 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -19,31 +19,30 @@ builds: - freebsd goarch: - amd64 - - 386 + - "386" - arm - arm64 - riscv64 goarm: - - 5 - - 6 - - 7 + - "5" + - "6" + - "7" ignore: - goos: darwin - goarch: 386 + goarch: "386" - goos: freebsd goarch: arm archives: - - - name_template: "{{.Os}}-{{.Arch}}{{if .Arm}}v{{.Arm}}{{end}}-{{ .ProjectName }}" - formats: [ 'tar.gz' ] + - name_template: "{{.Os}}-{{.Arch}}{{if .Arm}}v{{.Arm}}{{end}}-{{ .ProjectName }}" + formats: ["tar.gz"] format_overrides: - goos: windows - formats: [ 'zip' ] + formats: ["zip"] dockers: - - - dockerfile: Dockerfile + # Alpine docker images + - dockerfile: Dockerfile use: buildx build_flag_templates: - "--pull" @@ -59,10 +58,8 @@ dockers: - "filebrowser/filebrowser:{{ .Tag }}-amd64" - "filebrowser/filebrowser:v{{ .Major }}-amd64" extra_files: - - docker_config.json - - healthcheck.sh - - - dockerfile: Dockerfile + - docker + - dockerfile: Dockerfile use: buildx build_flag_templates: - "--pull" @@ -78,10 +75,8 @@ dockers: - "filebrowser/filebrowser:{{ .Tag }}-arm64" - "filebrowser/filebrowser:v{{ .Major }}-arm64" extra_files: - - docker_config.json - - healthcheck.sh - - - dockerfile: Dockerfile + - docker + - dockerfile: Dockerfile use: buildx build_flag_templates: - "--pull" @@ -93,15 +88,13 @@ dockers: - "--platform=linux/arm/v6" goos: linux goarch: arm - goarm: '6' + goarm: "6" image_templates: - "filebrowser/filebrowser:{{ .Tag }}-armv6" - "filebrowser/filebrowser:v{{ .Major }}-armv6" extra_files: - - docker_config.json - - healthcheck.sh - - - dockerfile: Dockerfile + - docker + - dockerfile: Dockerfile use: buildx build_flag_templates: - "--pull" @@ -113,16 +106,15 @@ dockers: - "--platform=linux/arm/v7" goos: linux goarch: arm - goarm: '7' + goarm: "7" image_templates: - "filebrowser/filebrowser:{{ .Tag }}-armv7" - "filebrowser/filebrowser:v{{ .Major }}-armv7" extra_files: - - docker_config.json - - healthcheck.sh -## s6 based docker images - - - dockerfile: Dockerfile.s6 + - docker + + ## s6-overlay docker images + - dockerfile: Dockerfile.s6 use: buildx build_flag_templates: - "--pull" @@ -138,10 +130,8 @@ dockers: - "filebrowser/filebrowser:{{ .Tag }}-amd64-s6" - "filebrowser/filebrowser:v{{ .Major }}-amd64-s6" extra_files: - - docker/root - - healthcheck.sh - - - dockerfile: Dockerfile.s6.aarch64 + - docker + - dockerfile: Dockerfile.s6.aarch64 use: buildx build_flag_templates: - "--pull" @@ -157,8 +147,8 @@ dockers: - "filebrowser/filebrowser:{{ .Tag }}-arm64-s6" - "filebrowser/filebrowser:v{{ .Major }}-arm64-s6" extra_files: - - docker/root - - healthcheck.sh + - docker + docker_manifests: - name_template: "filebrowser/filebrowser:latest" image_templates: @@ -175,7 +165,7 @@ docker_manifests: - "filebrowser/filebrowser:v{{ .Major }}-amd64" - "filebrowser/filebrowser:v{{ .Major }}-arm64" - "filebrowser/filebrowser:v{{ .Major }}-armv7" -## s6 image manifests + ## s6 image manifests - name_template: "filebrowser/filebrowser:s6" image_templates: - "filebrowser/filebrowser:{{ .Tag }}-amd64-s6" @@ -199,11 +189,6 @@ homebrew_casks: email: robot@filebrowser.org homepage: https://github.com/filebrowser/filebrowser description: File Browser is a create-your-own-cloud-kind of software where you can install it on a server, direct it to a path and then access your files through a nice web interface - license: "MIT" - # make the old formula conflict with the cask: - conflicts: - - formula: filebrowser - # if your app/binary isn't signed and notarized, you'll need this: hooks: post: install: | diff --git a/Dockerfile b/Dockerfile index 40a91a06..8ca2518d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,19 +1,33 @@ -FROM alpine:latest -RUN apk --update add ca-certificates \ - mailcap \ - curl \ - jq +FROM alpine:3.22 -COPY healthcheck.sh /healthcheck.sh -RUN chmod +x /healthcheck.sh # Make the script executable +RUN apk update && \ + apk --no-cache add ca-certificates mailcap curl jq tini -HEALTHCHECK --start-period=2s --interval=5s --timeout=3s \ - CMD /healthcheck.sh || exit 1 +# Make user and create necessary directories +ENV UID=1000 +ENV GID=1000 + +RUN addgroup -g $GID user && \ + adduser -D -u $UID -G user user && \ + mkdir -p /config /database /srv && \ + chown -R user:user /config /database /srv + +# Copy files and set permissions +COPY filebrowser /bin/filebrowser +COPY docker/common/ / +COPY docker/alpine/ / + +RUN chown -R user:user /bin/filebrowser /defaults healthcheck.sh init.sh + +# Define healthcheck script +HEALTHCHECK --start-period=2s --interval=5s --timeout=3s CMD /healthcheck.sh + +# Set the user, volumes and exposed ports +USER user + +VOLUME /srv /config /database -VOLUME /srv EXPOSE 80 -COPY docker_config.json /.filebrowser.json -COPY filebrowser /filebrowser - -ENTRYPOINT [ "/filebrowser" ] \ No newline at end of file +ENTRYPOINT [ "tini", "--", "/init.sh" ] +CMD [ "filebrowser", "--config", "/config/settings.json" ] diff --git a/Dockerfile.s6 b/Dockerfile.s6 index 609a2634..cb34cbd1 100644 --- a/Dockerfile.s6 +++ b/Dockerfile.s6 @@ -1,21 +1,23 @@ -FROM ghcr.io/linuxserver/baseimage-alpine:3.20 +FROM ghcr.io/linuxserver/baseimage-alpine:3.22 -RUN apk --update add ca-certificates \ - mailcap \ - curl \ - jq +RUN apk update && \ + apk --no-cache add ca-certificates mailcap curl jq -COPY healthcheck.sh /healthcheck.sh -RUN chmod +x /healthcheck.sh # Make the script executable +# Make user and create necessary directories +RUN mkdir -p /config /database /srv && \ + chown -R abc:abc /config /database /srv -HEALTHCHECK --start-period=2s --interval=5s --timeout=3s \ - CMD /healthcheck.sh || exit 1 +# Copy files and set permissions +COPY filebrowser /bin/filebrowser +COPY docker/common/ / +COPY docker/s6/ / -# copy local files -COPY docker/root/ / -RUN ln -s /config/settings.json /.filebrowser.json -COPY filebrowser /usr/bin/filebrowser +RUN chown -R abc:abc /bin/filebrowser /defaults healthcheck.sh -# ports and volumes +# Define healthcheck script +HEALTHCHECK --start-period=2s --interval=5s --timeout=3s CMD /healthcheck.sh + +# Set the volumes and exposed ports VOLUME /srv /config /database + EXPOSE 80 diff --git a/Dockerfile.s6.aarch64 b/Dockerfile.s6.aarch64 index 1e62391e..0378d57c 100644 --- a/Dockerfile.s6.aarch64 +++ b/Dockerfile.s6.aarch64 @@ -1,21 +1,23 @@ -FROM ghcr.io/linuxserver/baseimage-alpine:arm64v8-3.20 +FROM ghcr.io/linuxserver/baseimage-alpine:arm64v8-3.22 -RUN apk --update add ca-certificates \ - mailcap \ - curl \ - jq +RUN apk update && \ + apk --no-cache add ca-certificates mailcap curl jq -COPY healthcheck.sh /healthcheck.sh -RUN chmod +x /healthcheck.sh # Make the script executable +# Make user and create necessary directories +RUN mkdir -p /config /database /srv && \ + chown -R abc:abc /config /database /srv -HEALTHCHECK --start-period=2s --interval=5s --timeout=3s \ - CMD /healthcheck.sh || exit 1 +# Copy files and set permissions +COPY filebrowser /bin/filebrowser +COPY docker/common/ / +COPY docker/s6/ / -# copy local files -COPY docker/root/ / -RUN ln -s /config/settings.json /.filebrowser.json -COPY filebrowser /usr/bin/filebrowser +RUN chown -R abc:abc /bin/filebrowser /defaults healthcheck.sh -# ports and volumes +# Define healthcheck script +HEALTHCHECK --start-period=2s --interval=5s --timeout=3s CMD /healthcheck.sh + +# Set the volumes and exposed ports VOLUME /srv /config /database + EXPOSE 80 diff --git a/docker/alpine/init.sh b/docker/alpine/init.sh new file mode 100755 index 00000000..da620b09 --- /dev/null +++ b/docker/alpine/init.sh @@ -0,0 +1,41 @@ +#!/bin/sh + +set -e + +# Backwards compatibility for old Docker image +if [ -f "/.filebrowser.json" ]; then + ln -s /.filebrowser.json /config/settings.json + + echo "" + echo "!!!!!!!!!!!!!!!!!!!!! IMPORTANT INFORMATION !!!!!!!!!!!!!!!!!!!!!" + echo "Symlinking /.filebrowser.json to /config/settings.json for backwards compatibility." + echo "" + echo "The volume mount configuration has changed in the latest release." + echo "Please rename .filebrowser.json to settings.json and mount the parent directory to /config". + echo "Read more on https://github.com/filebrowser/filebrowser/blob/master/docs/installation.md#docker" + echo "" + echo "This workaround will be removed in a future release." + echo "" +fi + +# Backwards compatibility for old Docker image +if [ -f "/database.db" ]; then + ln -s /database.db /database/filebrowser.db + + echo "" + echo "!!!!!!!!!!!!!!!!!!!!! IMPORTANT INFORMATION !!!!!!!!!!!!!!!!!!!!!" + echo "" + echo "The volume mount configuration has changed in the latest release." + echo "Please rename database.db to filebrowser.db and mount the parent directory to /database". + echo "Read more on https://github.com/filebrowser/filebrowser/blob/master/docs/installation.md#docker" + echo "" + echo "This workaround will be removed in a future release." + echo "" +fi + +# Ensure configuration exists +if [ ! -f "/config/settings.json" ]; then + cp -a /defaults/settings.json /config/settings.json +fi + +exec "$@" diff --git a/docker/root/defaults/settings.json b/docker/common/defaults/settings.json similarity index 100% rename from docker/root/defaults/settings.json rename to docker/common/defaults/settings.json diff --git a/docker/common/healthcheck.sh b/docker/common/healthcheck.sh new file mode 100755 index 00000000..e0ab1e65 --- /dev/null +++ b/docker/common/healthcheck.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +set -e + +PORT=${FB_PORT:-$(jq -r .port /config/settings.json)} +ADDRESS=${FB_ADDRESS:-$(jq -r .address /config/settings.json)} +ADDRESS=${ADDRESS:-localhost} + +curl -f http://$ADDRESS:$PORT/health || exit 1 diff --git a/docker/root/etc/services.d/filebrowser/run b/docker/root/etc/services.d/filebrowser/run deleted file mode 100755 index 1d633757..00000000 --- a/docker/root/etc/services.d/filebrowser/run +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/with-contenv bash - -exec s6-setuidgid abc filebrowser -c /config/settings.json -d /database/filebrowser.db; \ No newline at end of file diff --git a/docker/root/custom-cont-init.d/20-config b/docker/s6/custom-cont-init.d/20-config similarity index 80% rename from docker/root/custom-cont-init.d/20-config rename to docker/s6/custom-cont-init.d/20-config index 80bec7cd..a4ba52cf 100755 --- a/docker/root/custom-cont-init.d/20-config +++ b/docker/s6/custom-cont-init.d/20-config @@ -1,9 +1,6 @@ #!/usr/bin/with-contenv bash -# make folders -mkdir -p /database - -# copy config +# Ensure configuration exists if [ ! -f "/config/settings.json" ]; then cp -a /defaults/settings.json /config/settings.json fi diff --git a/docker/s6/etc/services.d/filebrowser/run b/docker/s6/etc/services.d/filebrowser/run new file mode 100755 index 00000000..f4f2fb8e --- /dev/null +++ b/docker/s6/etc/services.d/filebrowser/run @@ -0,0 +1,3 @@ +#!/usr/bin/with-contenv bash + +exec s6-setuidgid abc filebrowser -c /config/settings.json; diff --git a/docs/installation.md b/docs/installation.md index 5475d080..0d3c840d 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -46,23 +46,12 @@ File Browser is available as two different Docker images, which can be found on ```sh docker run \ -v /path/to/srv:/srv \ - -v /path/to/filebrowser.db:/database.db \ - -v /path/to/.filebrowser.json:/.filebrowser.json \ - -u $(id -u):$(id -g) \ + -v /path/to/database:/database \ + -v /path/to/config:/config \ -p 8080:80 \ filebrowser/filebrowser ``` -Where: - -- `/path/to/srv` contains the files root directory for File Browser -- `/path/to/filebrowser.db` is the `database.db` -- `/path/to/database` is the `.filebrowser.json` - -> [!Warning] -> -> To use this image correctly, you need to first initialize a File Browser database outside of the Docker image and then start the Docker image with the database mounted. Otherwise, Docker will create an empty directory at the mounting point and fail to start. - ### s6 overlay The `s6` image is based on LinuxServer and leverages the [s6-overlay](https://github.com/just-containers/s6-overlay) system for a standard, highly customizable image. It should be used as follows: @@ -78,8 +67,12 @@ docker run \ filebrowser/filebrowser:s6 ``` +### Notes + Where: - `/path/to/srv` contains the files root directory for File Browser - `/path/to/config` contains a `settings.json` file - `/path/to/database` contains a `filebrowser.db` file + +Both `settings.json` and `filebrowser.db` will automatically be initialized if they don't exist. diff --git a/healthcheck.sh b/healthcheck.sh deleted file mode 100644 index b8b50039..00000000 --- a/healthcheck.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh -PORT=${FB_PORT:-$(jq -r .port /.filebrowser.json)} -ADDRESS=${FB_ADDRESS:-$(jq -r .address /.filebrowser.json)} -ADDRESS=${ADDRESS:-localhost} -curl -f http://$ADDRESS:$PORT/health || exit 1 diff --git a/docker_config.json b/settings.json similarity index 67% rename from docker_config.json rename to settings.json index f0fa64a6..e787ef87 100644 --- a/docker_config.json +++ b/settings.json @@ -3,6 +3,6 @@ "baseURL": "", "address": "", "log": "stdout", - "database": "/database.db", + "database": "/database/filebrowser.db", "root": "/srv" } \ No newline at end of file