first version

This commit is contained in:
fraoustin 2018-07-03 21:12:36 +02:00
commit 9d467e78c1
7 changed files with 254 additions and 0 deletions

50
Dockerfile Normal file
View file

@ -0,0 +1,50 @@
FROM nginx:1.13
LABEL maintainer "fraoustin@gmail.com"
ENV SET_CONTAINER_TIMEZONE false
ENV CONTAINER_TIMEZONE ""
# manage user www-data
RUN usermod -u 1000 www-data
# manage start container
COPY ./src/entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
RUN mkdir /usr/share/docker-entrypoint.pre
RUN mkdir /usr/share/docker-entrypoint.post
COPY ./src/00_init.sh /usr/share/docker-entrypoint.pre/00_init.sh
RUN chmod +x -R /usr/share/docker-entrypoint.pre
# install extra nginx
RUN apt-get update && apt-get install -y \
apache2-utils \
git \
nginx-extras \
&& rm -rf /var/lib/apt/lists/*
COPY ./src/default.conf /etc/nginx/conf.d/default.conf
RUN rm /etc/nginx/sites-enabled/default
# add cmd nginx
COPY ./src/cmd/addauth.sh /usr/bin/addauth
COPY ./src/cmd/rmauth.sh /usr/bin/rmauth
RUN chmod +x /usr/bin/addauth
RUN chmod +x /usr/bin/rmauth
# add theme
RUN mkdir /theme
WORKDIR /theme
RUN git clone https://github.com/fraoustin/Nginx-Fancyindex-Theme.git
ENV COLOR "blue"
RUN mkdir /share
VOLUME /share
ENV WEBUSER user
ENV WEBPASSWORD pass
EXPOSE 80
ENTRYPOINT ["/entrypoint.sh"]
CMD ["app"]

75
README.md Normal file
View file

@ -0,0 +1,75 @@
# Docker Image for fancyindex
generate a nginx server with fancyindex
You can use client
- ihm on http://127.0.0.1/ (fraoustin/Nginx-Fancyindex-Theme)
load when start image load file in
- /usr/share/gitweb/docker-entrypoint.pre
- /usr/share/gitweb/docker-entrypoint.post
## Parameter
- SET_CONTAINER_TIMEZONE (false or true) manage time of container
- CONTAINER_TIMEZONE timezone of container
- WEBUSER (default user)
- WEBPASSWORD (default pass)
- COLOR (default blue) for web ihm (blue, green, grey, greydark, orange, purple, red)
## Volume
- /share
## Port
- 80
## Command
- addauth : add user for git
- rmauth : remove user
## Usage direct
run image fraoustin/webdav
docker run -d -v <localpath>:/share --name fancyindex -p 80:80 fraoustin/fancyindex
user default is *user* and password default is *pass*
you use http://localhost/ for access ihm
## Usage by Dockerfile
Sample of Dockerfile
FROM fraoustin/webdav
COPY ./00_init.sh /usr/share/docker-entrypoint.pre/00_init.sh
RUN chmod +x -R /usr/share/gitweb/docker-entrypoint.pre
File 00_init.sh
#!/bin/bash
if [ ! -z "$WEBUSER" ]; then
addauth $WEBUSER $WEPASSWORD
fi
build image mywebdav
docker build -t myfancyindex .
run image mywebdav
docker run -d -e "CONTAINER_TIMEZONE=Europe/Paris" -e DAVUSER=myuser" -e "DAVPASSWORD=mypassword" -v <localpath>:/share --name test -p 8080:80 myfancyindex
## External library
- mdl on https://getmdl.io/
- Nginx-Fancyindex-Theme on https://github.com/fraoustin/Nginx-Fancyindex-Theme

5
src/00_init.sh Normal file
View file

@ -0,0 +1,5 @@
#!/bin/bash
if [ ! -z "$WEBUSER" ]; then
addauth $WEBUSER $WEBPASSWORD
fi

38
src/cmd/addauth.sh Normal file
View file

@ -0,0 +1,38 @@
#!/bin/bash
FPASS="/etc/nginx/.htpasswd"
error(){
echo "ERROR : parameters invalid !" >&2
exit 1
}
usage(){
echo "Usage: addauth user password"
echo "--help or -h : view help"
}
load(){
if [ ! -f $FPASS ]; then
htpasswd -bc $FPASS $1 $2
else
htpasswd -b $FPASS $1 $2
fi
}
# no parameters
[[ $# -lt 1 ]] && error
case "$1" in
--help)
usage
;;
-h)
usage
;;
*)
[[ $# -ne 2 ]] && error
load $1 $2
esac

35
src/cmd/rmauth.sh Normal file
View file

@ -0,0 +1,35 @@
#!/bin/bash
FPASS="/etc/nginx/.htpasswd"
error(){
echo "ERROR : parameters invalid !" >&2
exit 1
}
usage(){
echo "Usage: rmauth user"
echo "--help or -h : view help"
}
load(){
if [ -f $FPASS ]; then
htpasswd -bD $FPASS $1
fi
}
# no parameters
[[ $# -ne 1 ]] && error
case "$1" in
--help)
usage
;;
-h)
usage
;;
*)
load $1
esac

32
src/default.conf Normal file
View file

@ -0,0 +1,32 @@
server {
listen 80 default_server;
client_max_body_size 1G;
location /fancyindex {
rewrite /fancyindex/(.*) /$1 break;
root /theme/Nginx-Fancyindex-Theme;
}
location / {
# manage DELETE AND MKDIR
if (-d $request_filename) { rewrite ^(.*[^/])$ $1/ break; }
root /share;
fancyindex on;
fancyindex_localtime on;
fancyindex_name_length 255; # Maximum file name length in bytes, change as you like.
# theme
fancyindex_header "/fancyindex/header.html";
fancyindex_footer "/fancyindex/footer.html";
fancyindex_ignore "fancyindex";
dav_methods PUT DELETE MKCOL COPY MOVE;
dav_ext_methods PROPFIND OPTIONS;
create_full_put_path on;
dav_access user:rw group:rw all:rw;
auth_basic "Access restricted";
auth_basic_user_file /etc/nginx/.htpasswd;
}
}

19
src/entrypoint.sh Normal file
View file

@ -0,0 +1,19 @@
#!/bin/bash
set -e
if [ $CONTAINER_TIMEZONE ] && [ "$SET_CONTAINER_TIMEZONE" = "false" ]; then
echo ${CONTAINER_TIMEZONE} >/etc/timezone && dpkg-reconfigure -f noninteractive tzdata
echo "Container timezone set to: $CONTAINER_TIMEZONE"
export SET_CONTAINER_TIMEZONE=true
else
echo "Container timezone not modified"
fi
if [ "$1" = 'app' ]; then
/bin/run-parts --verbose --regex '\.(sh)$' "/usr/share/docker-entrypoint.pre"
cp /theme/Nginx-Fancyindex-Theme/mdl/color/$COLOR.min.css /theme/Nginx-Fancyindex-Theme/mdl/material.min.css
nginx -g "daemon off;"
/bin/run-parts --verbose --regex '\.(sh)$' "/usr/share/docker-entrypoint.post"
fi
exec "$@"