diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..93a06c6 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,41 @@ +FROM ubuntu:latest + +LABEL maintainer="JudaicaLink | Benjamin Schnabel " + +RUN apt-get -y update && apt-get -y upgrade && apt-get install -y \ + python3 \ + python3-pip \ + python3-venv \ + git \ + hugo \ + rsync \ + nginx + +RUN mkdir /data +RUN mkdir /data/judaicalink +RUN mkdir /data/judaicalink/web.judaicalink.org/ +RUN mkdir /data/judaicalink/web.judaicalink.org/judaicalink-site + +WORKDIR /data/ + +ADD docker/installer.sh ./ +COPY docker/site/* /data/judaicalink/web.judaicalink.org/ + +# NGINX +COPY docker/nginx/* /etc/nginx/ +COPY docker/nginx/sites-available/* /etc/nginx/sites-available/ +RUN ln -s /etc/nginx/sites-available/judaicalink.conf /etc/nginx/sites-enabled/judaicalink +RUN rm /etc/nginx/sites-enabled/default + +WORKDIR /data/judaicalink/web.judaicalink.org/judaicalink-site +COPY . . + +ENV PORT_NGINX=80 +ENV PORT_SSL=443 + +EXPOSE ${PORT_NGINX} +EXPOSE ${PORT_SSL} + +CMD [ "nginx", "-g", "daemon off;" ] + +RUN bash -c "docker/installer.sh" \ No newline at end of file diff --git a/docker/installer.sh b/docker/installer.sh new file mode 100644 index 0000000..0608eca --- /dev/null +++ b/docker/installer.sh @@ -0,0 +1,89 @@ +#!/bin/bash + +colorred="\033[31m" +colorpowder_blue="\033[1;36m" #with bold +colorblue="\033[34m" +colornormal="\033[0m" +colorwhite="\033[97m" +colorlightgrey="\033[90m" + +printf " ${colorred} ## ${colorlightgrey} . \n" +printf " ${colorred} ## ## ## ${colorlightgrey} == \n" +printf " ${colorred}## ## ## ## ${colorlightgrey}=== \n" +printf " /\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\\\___/ === \n" +printf " ${colorblue}~~~ ${colorlightgrey}{${colorblue}~~ ~~~~ ~~~ ~~~~ ~~ ~ ${colorlightgrey}/ ===- ${colorblue}~~~${colorlightgrey}\n" +printf " \\\______${colorwhite} o ${colorlightgrey} __/ \n" +printf " \\\ \\\ __/ \n" +printf " \\\____\\\______/ \n" +printf "${colorpowder_blue} \n" +printf " | | \n" +printf " __ | __ __ | _ __ _ \n" +printf " / \\\| / \\\ / |/ / _\\\ | \n" +printf " \\\__/| \\\__/ \\\__ |\\\_ \\\__ | \n" +printf " ${colornormal} \n" + +echo -e "\033[0;34m" " + .(###(. + .(#####/ + /##(##, + .#(. .#(. + .####(. *#, /#, (###/. + /########################################( + .*/##. *#,/###########,/#, .###/. + ,#/ .#(.##############(.#(. (#. + .(#/#,/#################,/#*#( + .##/,###################.(#( + *#* (#,################(,#( /#. + .##. ,#//#############,/#. .#( + .#####. .(#./#########/.#( .####, + ##########################################, + ./(*. .(#. .#( *##/. + ,#/ /#, + ,#####. + (#####* + .(#/. " + +printf " ${colornormal} \n" + +echo "Welcome to JudaicaLink's download generator script!" +echo "(c) 2022 JudaicaLink" +echo "Benjamin Schnabel " +echo "----------------------------------------" +echo "creating directories..." + +alias python='/usr/bin/python3' + +cd /data/judaicalink/web.judaicalink.org/ || exit +chmod +x ./update.sh +chmod +x ./rebuild.sh +echo "done." + +#echo "----------------------------------------" +#echo "downloading Judaicalink site..." +#cd /data/judaicalink/web.judaicalink.org/judaicalink-site/ || exit +#git clone https://github.com/judaicalink/judaicalink-site.git +#latesttag=$(git describe --tags) +#echo checking out ${latesttag} +#git checkout ${latesttag} +#echo "done." # + +echo "----------------------------------------" +echo "updating and building..." +cd /data/judaicalink/web.judaicalink.org/ || exit +./update.sh +./rebuild.sh +echo "done." + +# TODO: add requirements + +python3 -m venv venv +source venv/bin/activate + +cd /data/judaicalink/web.judaicalink.org/judaicalink-site/ || exit + +pip3 install -r requirements.txt +# Generate statistics +python3 statistics.py + +# Generate beacon file +python3 generate_beacon.py \ No newline at end of file diff --git a/docker/nginx/nginx.conf b/docker/nginx/nginx.conf new file mode 100644 index 0000000..5aa29e3 --- /dev/null +++ b/docker/nginx/nginx.conf @@ -0,0 +1,37 @@ +# Generated by nginxconfig.io +# https://www.serverion.com/nginx-config/#?0.domain=localhost&0.document_root=%2Fdata%2Fjudaicalink%2Fweb.judaicalink.org%2Fhtdocs&0.https=false&0.php=false&0.django&0.index=index.html&0.fallback_html&0.access_log_domain&0.error_log_domain + +user www-data; +pid /run/nginx.pid; +worker_processes auto; +worker_rlimit_nofile 65535; +include /etc/nginx/modules-enabled/*.conf; + +events { + multi_accept on; + worker_connections 65535; +} + +http { + charset utf-8; + sendfile on; + tcp_nopush on; + tcp_nodelay on; + server_tokens off; + log_not_found off; + types_hash_max_size 2048; + client_max_body_size 16M; + keepalive_timeout 65; + + # MIME + include mime.types; + default_type application/octet-stream; + + # logging + access_log /var/log/nginx/access.log; + error_log /var/log/nginx/error.log warn; + + # load configs + include /etc/nginx/conf.d/*.conf; + include /etc/nginx/sites-enabled/*; +} \ No newline at end of file diff --git a/docker/nginx/sites-available/judaicalink.conf b/docker/nginx/sites-available/judaicalink.conf new file mode 100644 index 0000000..6e5cdc9 --- /dev/null +++ b/docker/nginx/sites-available/judaicalink.conf @@ -0,0 +1,27 @@ +server { + listen 80; + listen [::]:80; + + server_name judaicalink; + root /data/judaicalink/web.judaicalink.org/htdocs; + + # logging + access_log /var/log/nginx/localhost.access.log; + error_log /var/log/nginx/localhost.error.log warn; + + # index.html fallback + location / { + try_files $uri $uri/ /index.html; + } + +} + +# subdomains redirect +server { + listen 80; + listen [::]:80; + + server_name *.localhost; + + return 301 http://localhost$request_uri; +} \ No newline at end of file diff --git a/docker/site/rebuild.sh b/docker/site/rebuild.sh new file mode 100644 index 0000000..a75d7bb --- /dev/null +++ b/docker/site/rebuild.sh @@ -0,0 +1,11 @@ +#!/bin/bash +BASEDIR=/data/judaicalink/web.judaicalink.org +HTDOCS=$BASEDIR/htdocs +WORKDIR=$BASEDIR/judaicalink-site +BRANCH=master + +pushd $WORKDIR +git fetch origin $BRANCH +git merge origin/$BRANCH +hugo --cleanDestinationDir && rsync -avz --delete public/ $HTDOCS +popd diff --git a/docker/site/update.sh b/docker/site/update.sh new file mode 100644 index 0000000..318ed21 --- /dev/null +++ b/docker/site/update.sh @@ -0,0 +1,18 @@ +#!/bin/bash +BASEDIR=/data/judaicalink/web.judaicalink.org +HTDOCS=$BASEDIR/htdocs +WORKDIR=$BASEDIR/judaicalink-site +BRANCH=master + +pushd $WORKDIR +git fetch origin $BRANCH +CHANGES=`git status -s -b -uno` +if [ "$CHANGES" != "## $BRANCH...origin/$BRANCH" ]; then + echo "Found updates, rebuilding site." + git merge origin/$BRANCH + hugo --cleanDestinationDir && rsync -avz --delete public/ $HTDOCS + #/data/judaicalink/loader.sh +else + echo "No changes, exiting" +fi +popd