diff --git a/.github/workflows/nginx-webdav.yaml b/.github/workflows/nginx-webdav.yaml new file mode 100644 index 00000000..cfb7bb54 --- /dev/null +++ b/.github/workflows/nginx-webdav.yaml @@ -0,0 +1,27 @@ +name: WebDAV + +on: + push: + branches: + - 'main' + paths: + - 'nginx-webdav/**' + +jobs: + + nginx-webdav: + name: Deploy WebDAV Image + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v4 + - name: Publish Docker Image + uses: openzim/docker-publish-action@v10 + with: + image-name: kiwix/nginx-webdav + on-master: latest + restrict-to: kiwix/container-images + context: nginx-webdav + registries: ghcr.io + credentials: + GHCRIO_USERNAME=${{ secrets.GHCR_USERNAME }} + GHCRIO_TOKEN=${{ secrets.GHCR_TOKEN }} diff --git a/nginx-webdav/Dockerfile b/nginx-webdav/Dockerfile new file mode 100644 index 00000000..77c5c4c8 --- /dev/null +++ b/nginx-webdav/Dockerfile @@ -0,0 +1,34 @@ +FROM debian:bookworm-slim + +COPY webdav.conf /etc/nginx/conf.d/default.conf +COPY entrypoint.sh /usr/local/bin/entrypoint + +RUN \ + apt-get update \ + && apt-get upgrade -y \ + && apt-get install -y dumb-init curl \ + # nginx and its plugins for webdav and fancyindex + nginx nginx-extras libnginx-mod-http-dav-ext libnginx-mod-http-auth-pam libnginx-mod-http-fancyindex \ + # apache2-utils to create htpasswd from ENVIRON in entrypoint + apache2-utils \ + && rm /etc/nginx/sites-enabled/* \ + && mkdir -p /var/www/fancyindex-themes \ + # fancyindex them + && curl -L -o /tmp/theme.tar.gz https://github.com/alehaa/nginx-fancyindex-flat-theme/releases/download/v1.2/nginx-fancyindex-flat-theme-1.2.tar.gz \ + && tar -C /var/www/fancyindex-themes/ --strip-components 1 -x -f /tmp/theme.tar.gz \ + # another theme + # && curl -L -o /tmp/theme.tar.gz https://github.com/fraoustin/Nginx-Fancyindex-Theme/archive/refs/tags/0.1.7.tar.gz \ + # && tar -C /var/www/fancyindex-themes/ --strip-components 1 -x -f /tmp/theme.tar.gz \ + && mkdir -p "/data" \ + && chown -R www-data:www-data /data \ + && chmod +x /usr/local/bin/entrypoint + +WORKDIR /data +VOLUME /data +EXPOSE 80 +ENV USERNAME "" +ENV PASSWORD "" +ENV NAME "" + +ENTRYPOINT ["/usr/bin/dumb-init", "--"] +CMD ["/usr/local/bin/entrypoint" , "nginx", "-g", "daemon off;"] diff --git a/nginx-webdav/README.md b/nginx-webdav/README.md new file mode 100644 index 00000000..60461433 --- /dev/null +++ b/nginx-webdav/README.md @@ -0,0 +1,3 @@ +# nginx-webdav + +Simple nginx image for serving static files over HTTP and managing them using WebDAV using `USERNAME` and `PASSWORD` environ variables. `NAME` variable allows customizing the displayed name/title. \ No newline at end of file diff --git a/nginx-webdav/entrypoint.sh b/nginx-webdav/entrypoint.sh new file mode 100644 index 00000000..4a4e6569 --- /dev/null +++ b/nginx-webdav/entrypoint.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +if [[ -n "$USERNAME_FILE" ]] && [[ -n "$PASSWORD_FILE" ]] +then + USERNAME=$(cat "$USERNAME_FILE") + PASSWORD=$(cat "$PASSWORD_FILE") +fi + +if [[ -n "$USERNAME" ]] && [[ -n "$PASSWORD" ]] +then + htpasswd -bc /etc/nginx/htpasswd "$USERNAME" "$PASSWORD" + echo Done. +else + echo Using no auth. + sed -i 's%auth_basic "Restricted";% %g' /etc/nginx/conf.d/default.conf + sed -i 's%auth_basic_user_file /etc/nginx/htpasswd;% %g' /etc/nginx/conf.d/default.conf +fi + +if [[ -n "NAME" ]] +then + sed -i "s/ File Browser/${NAME}/g" /var/www/fancyindex-themes/header.html + sed -i "s/ FancyIndex/${NAME}/g" /var/www/fancyindex-themes/header.html +fi + +exec "$@" diff --git a/nginx-webdav/webdav.conf b/nginx-webdav/webdav.conf new file mode 100644 index 00000000..1061e3ab --- /dev/null +++ b/nginx-webdav/webdav.conf @@ -0,0 +1,41 @@ +server { + listen 80; + + access_log /dev/stdout; + error_log /dev/stdout info; + + client_max_body_size 0; + + location / { + charset utf-8; + + #autoindex on; + #autoindex_exact_size off; + #autoindex_localtime on; + + fancyindex on; + fancyindex_exact_size off; + fancyindex_show_path on; + fancyindex_name_length 255; + fancyindex_header "/fancyindex/header.html"; + fancyindex_footer "/fancyindex/footer.html"; + # fancyindex_css_href /fancyindex/theme.css; + fancyindex_time_format "%B %e, %Y"; + + location /fancyindex { + alias /var/www/fancyindex-themes; + } + + create_full_put_path on; + dav_methods PUT DELETE MKCOL COPY MOVE; + dav_ext_methods PROPFIND OPTIONS; + dav_access user:rw group:rw all:r; + + limit_except GET PROPFIND OPTIONS HEAD { + auth_basic "Restricted"; + auth_basic_user_file /etc/nginx/htpasswd; + } + + root /data/; + } +}