From 39b238733436c2ec77d8d95374b25340d9e1e24c Mon Sep 17 00:00:00 2001 From: kev Date: Wed, 15 Dec 2021 12:11:34 +0800 Subject: [PATCH] add nfs --- nfs/Dockerfile | 18 +++++ nfs/{README.md => README.md.old} | 0 nfs/{arm => arm.old}/Dockerfile | 0 nfs/{arm => arm.old}/docker-compose.yml | 0 nfs/{arm => arm.old}/entrypoint.sh | 0 nfs/docker-compose.yml | 34 ++++----- nfs/docker-compose.yml.old | 22 ++++++ nfs/docker-entrypoint.sh | 96 +++++++++++++++++++++++++ 8 files changed, 148 insertions(+), 22 deletions(-) create mode 100644 nfs/Dockerfile rename nfs/{README.md => README.md.old} (100%) rename nfs/{arm => arm.old}/Dockerfile (100%) rename nfs/{arm => arm.old}/docker-compose.yml (100%) rename nfs/{arm => arm.old}/entrypoint.sh (100%) create mode 100644 nfs/docker-compose.yml.old create mode 100755 nfs/docker-entrypoint.sh diff --git a/nfs/Dockerfile b/nfs/Dockerfile new file mode 100644 index 0000000..861fd82 --- /dev/null +++ b/nfs/Dockerfile @@ -0,0 +1,18 @@ +# +# Dockerfile for nfs +# + +FROM debian:bullseye +MAINTAINER EasyPi Software Foundation + +RUN set -xe \ + && apt update \ + && apt install -y nfs-ganesha nfs-ganesha-vfs tini \ + && rm -rf /var/lib/apt/lists/* + +COPY ./docker-entrypoint.sh /entrypoint.sh + +EXPOSE 2049 + +ENTRYPOINT ["tini", "--"] +CMD ["/entrypoint.sh"] diff --git a/nfs/README.md b/nfs/README.md.old similarity index 100% rename from nfs/README.md rename to nfs/README.md.old diff --git a/nfs/arm/Dockerfile b/nfs/arm.old/Dockerfile similarity index 100% rename from nfs/arm/Dockerfile rename to nfs/arm.old/Dockerfile diff --git a/nfs/arm/docker-compose.yml b/nfs/arm.old/docker-compose.yml similarity index 100% rename from nfs/arm/docker-compose.yml rename to nfs/arm.old/docker-compose.yml diff --git a/nfs/arm/entrypoint.sh b/nfs/arm.old/entrypoint.sh similarity index 100% rename from nfs/arm/entrypoint.sh rename to nfs/arm.old/entrypoint.sh diff --git a/nfs/docker-compose.yml b/nfs/docker-compose.yml index 8b5f087..42c9a0b 100644 --- a/nfs/docker-compose.yml +++ b/nfs/docker-compose.yml @@ -1,22 +1,12 @@ -nfs: - image: erichough/nfs-server - ports: - - "111:111/tcp" - - "111:111/udp" - - "2049:2049/tcp" - - "2049:2049/udp" - - "32765:32765/tcp" - - "32765:32765/udp" - - "32767:32767/tcp" - - "32767:32767/udp" - volumes: - - ./data/splash:/export/splash:ro - - /lib/modules:/lib/modules:ro - environment: - - NFS_LOG_LEVEL=DEBUG - - NFS_EXPORT_0=/export/splash/filters *(ro,no_subtree_check) - - NFS_EXPORT_1=/export/splash/js-profiles *(ro,no_subtree_check) - - NFS_EXPORT_2=/export/splash/lua_modules *(ro,no_subtree_check) - - NFS_EXPORT_3=/export/splash/proxy-profiles *(ro,no_subtree_check) - privileged: true - restart: unless-stopped +version: "3.8" +services: + nfs: + build: . + image: vimagick/nfs + ports: + - "2049:2049" + volumes: + - ./data:/data + environment: + - EXPORT_PATH=/data + restart: unless-stopped diff --git a/nfs/docker-compose.yml.old b/nfs/docker-compose.yml.old new file mode 100644 index 0000000..8b5f087 --- /dev/null +++ b/nfs/docker-compose.yml.old @@ -0,0 +1,22 @@ +nfs: + image: erichough/nfs-server + ports: + - "111:111/tcp" + - "111:111/udp" + - "2049:2049/tcp" + - "2049:2049/udp" + - "32765:32765/tcp" + - "32765:32765/udp" + - "32767:32767/tcp" + - "32767:32767/udp" + volumes: + - ./data/splash:/export/splash:ro + - /lib/modules:/lib/modules:ro + environment: + - NFS_LOG_LEVEL=DEBUG + - NFS_EXPORT_0=/export/splash/filters *(ro,no_subtree_check) + - NFS_EXPORT_1=/export/splash/js-profiles *(ro,no_subtree_check) + - NFS_EXPORT_2=/export/splash/lua_modules *(ro,no_subtree_check) + - NFS_EXPORT_3=/export/splash/proxy-profiles *(ro,no_subtree_check) + privileged: true + restart: unless-stopped diff --git a/nfs/docker-entrypoint.sh b/nfs/docker-entrypoint.sh new file mode 100755 index 0000000..f79bae4 --- /dev/null +++ b/nfs/docker-entrypoint.sh @@ -0,0 +1,96 @@ +#!/bin/bash + +set -e + +# environment variables + +: ${EXPORT_PATH:="/data"} +: ${PSEUDO_PATH:="/"} +: ${EXPORT_ID:=0} +: ${PROTOCOLS:=4} +: ${TRANSPORTS:="UDP, TCP"} +: ${SEC_TYPE:="sys"} +: ${SQUASH_MODE:="No_Root_Squash"} +: ${GRACELESS:=true} +: ${VERBOSITY:="NIV_EVENT"} # NIV_DEBUG, NIV_EVENT, NIV_WARN + +: ${GANESHA_CONFIG:="/etc/ganesha/ganesha.conf"} +: ${GANESHA_LOGFILE:="/dev/stdout"} + +init_rpc() { + echo "* Starting rpcbind" + if [ ! -x /run/rpcbind ] ; then + install -m755 -g 32 -o 32 -d /run/rpcbind + fi + rpcbind || return 0 + rpc.statd -L || return 0 + rpc.idmapd || return 0 + sleep 1 +} + +init_dbus() { + echo "* Starting dbus" + if [ ! -x /var/run/dbus ] ; then + install -m755 -g 81 -o 81 -d /var/run/dbus + fi + rm -f /var/run/dbus/* + rm -f /var/run/messagebus.pid + dbus-uuidgen --ensure + dbus-daemon --system --fork + sleep 1 +} + +# pNFS +# Ganesha by default is configured as pNFS DS. +# A full pNFS cluster consists of multiple DS +# and one MDS (Meta Data server). To implement +# this one needs to deploy multiple Ganesha NFS +# and then configure one of them as MDS: +# GLUSTER { PNFS_MDS = ${WITH_PNFS}; } + +bootstrap_config() { + echo "* Writing configuration" + cat <${GANESHA_CONFIG} + +NFSV4 { Graceless = ${GRACELESS}; } +EXPORT{ + Export_Id = ${EXPORT_ID}; + Path = "${EXPORT_PATH}"; + Pseudo = "${PSEUDO_PATH}"; + FSAL { + name = VFS; + } + Access_type = RW; + Disable_ACL = true; + Squash = ${SQUASH_MODE}; + Protocols = ${PROTOCOLS}; +} + +EXPORT_DEFAULTS{ + Transports = ${TRANSPORTS}; + SecType = ${SEC_TYPE}; +} + +END +} + +sleep 0.5 + +if [ ! -f ${EXPORT_PATH} ]; then + mkdir -p "${EXPORT_PATH}" +fi + +echo "Initializing Ganesha NFS server" +echo "==================================" +echo "export path: ${EXPORT_PATH}" +echo "==================================" + +bootstrap_config +init_rpc +init_dbus + +echo "Generated NFS-Ganesha config:" +cat ${GANESHA_CONFIG} + +echo "* Starting Ganesha-NFS" +exec /usr/bin/ganesha.nfsd -F -L ${GANESHA_LOGFILE} -f ${GANESHA_CONFIG} -N ${VERBOSITY}