From 01b636385679e10616943db63da3ebc57f2597c6 Mon Sep 17 00:00:00 2001 From: Andri Joos <andri@joos.io> Date: Sat, 12 Oct 2024 17:55:13 +0200 Subject: [PATCH] add new image --- .gitlab-ci.yml | 13 +++++++++++++ Dockerfile | 23 +++++++++-------------- exports | 1 - nfsd.sh | 43 +++++-------------------------------------- 4 files changed, 27 insertions(+), 53 deletions(-) create mode 100644 .gitlab-ci.yml delete mode 100644 exports diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..01b35df --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,13 @@ +include: +- project: docker-images/templates + ref: master + file: images.gitlab-ci.yml + +build_nfs_image: + extends: .build_image_job_template + variables: + IMAGE_BASENAME: andrijoos/nfs-alpine + IMAGE_NAME: ${IMAGE_BASENAME}:3.20.3,${IMAGE_BASENAME}:3.20,${IMAGE_BASENAME}:3,${IMAGE_BASENAME}:latest + IMAGE_SERVER: "" + DOCKER_LOGIN_CMD: docker login --username ${DOCKER_HUB_USERNAME} --password ${DOCKER_HUB_ACCESS_TOKEN} + DOCKER_LOGOUT_CMD: docker logout diff --git a/Dockerfile b/Dockerfile index 5f3fab5..4686192 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,17 +1,12 @@ -#alpine:3.15 has an issue with rpc, default: alpine:3.9.2 -FROM alpine:3.9.2 -# COPY Dockerfile README.md / +FROM alpine:3.20.3 -RUN apk add --no-cache --update --verbose nfs-utils bash iproute2 && \ - rm -rf /var/cache/apk /tmp /sbin/halt /sbin/poweroff /sbin/reboot && \ - mkdir -p /var/lib/nfs/rpc_pipefs /var/lib/nfs/v4recovery && \ - echo "rpc_pipefs /var/lib/nfs/rpc_pipefs rpc_pipefs defaults 0 0" >> /etc/fstab && \ - echo "nfsd /proc/fs/nfsd nfsd defaults 0 0" >> /etc/fstab +ADD nfsd.sh / -COPY exports /etc/ -COPY nfsd.sh /usr/bin/nfsd.sh -# COPY .bashrc /root/.bashrc +RUN apk add --no-cache openrc nfs-utils bash \ + && mkdir -p /var/lib/nfs/rpc_pipefs \ + && mkdir -p /var/lib/nfs/v4recovery \ + && echo "nfsd /proc/fs/nfsd nfsd defaults 0 0" >> /etc/fstab \ + && echo "rpc_pipefs /var/lib/nfs/rpc_pipefs rpc_pipefs defaults 0 0" >> /etc/fstab \ + && chmod +x /nfsd.sh -RUN chmod +x /usr/bin/nfsd.sh - -ENTRYPOINT ["/usr/bin/nfsd.sh"] +ENTRYPOINT [ "/nfsd.sh" ] diff --git a/exports b/exports deleted file mode 100644 index 65f29e0..0000000 --- a/exports +++ /dev/null @@ -1 +0,0 @@ -{{SHARED_DIRECTORY}} {{PERMITTED}}({{READ_ONLY}},fsid=0,{{SYNC}},no_subtree_check,no_auth_nlm,insecure,no_root_squash) diff --git a/nfsd.sh b/nfsd.sh index 9faf38f..0ec577d 100755 --- a/nfsd.sh +++ b/nfsd.sh @@ -20,6 +20,8 @@ stop() exit } +echo "{{SHARED_DIRECTORY}} {{PERMITTED}}(rw,fsid=0,no_subtree_check,no_auth_nlm,insecure,no_root_squash)" >> /etc/exports + # Check if the SHARED_DIRECTORY variable is empty if [ -z "${SHARED_DIRECTORY}" ]; then echo "The SHARED_DIRECTORY environment variable is unset or null, exiting..." @@ -29,18 +31,6 @@ else /bin/sed -i "s@{{SHARED_DIRECTORY}}@${SHARED_DIRECTORY}@g" /etc/exports fi -# This is here to demonsrate how multiple directories can be shared. You -# would need a block like this for each extra share. -# Any additional shares MUST be subdirectories of the root directory specified -# by SHARED_DIRECTORY. - -# Check if the SHARED_DIRECTORY_2 variable is empty -if [ ! -z "${SHARED_DIRECTORY_2}" ]; then - echo "Writing SHARED_DIRECTORY_2 to /etc/exports file" - echo "{{SHARED_DIRECTORY_2}} {{PERMITTED}}({{READ_ONLY}},{{SYNC}},no_subtree_check,no_auth_nlm,insecure,no_root_squash)" >> /etc/exports - /bin/sed -i "s@{{SHARED_DIRECTORY_2}}@${SHARED_DIRECTORY_2}@g" /etc/exports -fi - # Check if the PERMITTED variable is empty if [ -z "${PERMITTED}" ]; then echo "The PERMITTED environment variable is unset or null, defaulting to '*'." @@ -52,28 +42,6 @@ else /bin/sed -i "s/{{PERMITTED}}/"${PERMITTED}"/g" /etc/exports fi -# Check if the READ_ONLY variable is set (rather than a null string) using parameter expansion -if [ -z ${READ_ONLY+y} ]; then - echo "The READ_ONLY environment variable is unset or null, defaulting to 'rw'." - echo "Clients have read/write access." - /bin/sed -i "s/{{READ_ONLY}}/rw/g" /etc/exports -else - echo "The READ_ONLY environment variable is set." - echo "Clients will have read-only access." - /bin/sed -i "s/{{READ_ONLY}}/ro/g" /etc/exports -fi - -# Check if the SYNC variable is set (rather than a null string) using parameter expansion -if [ -z "${SYNC+y}" ]; then - echo "The SYNC environment variable is unset or null, defaulting to 'async' mode". - echo "Writes will not be immediately written to disk." - /bin/sed -i "s/{{SYNC}}/async/g" /etc/exports -else - echo "The SYNC environment variable is set, using 'sync' mode". - echo "Writes will be immediately written to disk." - /bin/sed -i "s/{{SYNC}}/sync/g" /etc/exports -fi - # Partially set 'unofficial Bash Strict Mode' as described here: http://redsymbol.net/articles/unofficial-bash-strict-mode/ # We don't set -e because the pidof command returns an exit code of 1 when the specified process is not found # We expect this at times and don't want the script to be terminated when it occurs @@ -105,7 +73,7 @@ while true; do # /usr/sbin/rpc.statd echo "Starting NFS in the background..." - /usr/sbin/rpc.nfsd --debug 8 --no-udp --no-nfs-version 2 --no-nfs-version 3 + /usr/sbin/rpc.nfsd --debug 8 --no-nfs-version 3 echo "Exporting File System..." if /usr/sbin/exportfs -rv; then /usr/sbin/exportfs @@ -113,9 +81,8 @@ while true; do echo "Export validation failed, exiting..." exit 1 fi - echo "Starting Mountd in the background..."These - /usr/sbin/rpc.mountd --debug all --no-udp --no-nfs-version 2 --no-nfs-version 3 -# --exports-file /etc/exports + echo "Starting Mountd in the background..." + /usr/sbin/rpc.mountd --debug all --no-nfs-version 2 --no-nfs-version 3 # Check if NFS is now running by recording it's PID (if it's not running $pid will be null): pid=`pidof rpc.mountd` -- GitLab