Skip to content

Commit

Permalink
adding nginx-webdav image
Browse files Browse the repository at this point in the history
  • Loading branch information
rgaudin committed Sep 11, 2024
1 parent 69fdc75 commit fd54dfb
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/nginx-webdav.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
34 changes: 34 additions & 0 deletions nginx-webdav/Dockerfile
Original file line number Diff line number Diff line change
@@ -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;"]
3 changes: 3 additions & 0 deletions nginx-webdav/README.md
Original file line number Diff line number Diff line change
@@ -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.
25 changes: 25 additions & 0 deletions nginx-webdav/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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 "$@"
41 changes: 41 additions & 0 deletions nginx-webdav/webdav.conf
Original file line number Diff line number Diff line change
@@ -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/;
}
}

0 comments on commit fd54dfb

Please sign in to comment.