commit d08ff0c7ef31e64f3aa7340bbfab09eb6630e085 Author: Dennis Schwerdel Date: Thu Nov 12 12:01:14 2020 +0100 First working version diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..6bbcb32 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +test/* +.git/* +screenshots/* + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d570088 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules/ + diff --git a/CHANGELOG b/CHANGELOG new file mode 100644 index 0000000..7b70cb3 --- /dev/null +++ b/CHANGELOG @@ -0,0 +1,2 @@ +[0.1.0] +* First version \ No newline at end of file diff --git a/CloudronManifest.json b/CloudronManifest.json new file mode 100644 index 0000000..a873a04 --- /dev/null +++ b/CloudronManifest.json @@ -0,0 +1,25 @@ +{ + "id": "org.getzola.cloudronapp", + "title": "Zola", + "author": "Zola developers", + "description": "file://DESCRIPTION.md", + "tagline": "Zola static page generator", + "tags": [ + "webserver" + ], + "version": "0.1.0", + "healthCheckPath": "/", + "httpPort": 8000, + "manifestVersion": 1, + "website": "https://getzola.org", + "contactEmail": "support@cloudron.io", + "icon": "logo.png", + "addons": { + "localstorage": {} + }, + "mediaLinks": [ + "https://nginx.org/nginx.png" + ], + "changelog": "file://CHANGELOG", + "postInstallMessage": "file://POSTINSTALL.md" +} diff --git a/DESCRIPTION.md b/DESCRIPTION.md new file mode 100644 index 0000000..94c0fae --- /dev/null +++ b/DESCRIPTION.md @@ -0,0 +1,5 @@ +### Empty Website with Nginx + PHP. + +Use `cloudron push` to copy files into `/app/data/public/` and `cloudron exec` to get a remote terminal. + +Edit `/app/data/nginx.conf` to change the webserver configuration according to the [Nginx Documentation](https://nginx.org/en/docs/). diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3930997 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,50 @@ +FROM cloudron/base:1.0.0 + +RUN mkdir -p /app/code +WORKDIR /app/code + +RUN wget http://nginx.org/keys/nginx_signing.key && \ + apt-key add nginx_signing.key && \ + rm nginx_signing.key && \ + echo "deb http://nginx.org/packages/mainline/ubuntu/ $(lsb_release -cs) nginx" > /etc/apt/sources.list.d/nginx.list && \ + apt update && \ + apt install -y nginx zopfli + +ENV RUST=1.47.0 +RUN curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain ${RUST} && \ + export PATH=/root/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin && \ + cd /tmp && \ + git clone https://github.com/getzola/zola.git && \ + cd zola && \ + cargo build --release && \ + cp target/release/zola /usr/bin && \ + cd / && rm -rf /tmp/zola /root/.cargo /root/.rustup + +ADD supervisord.conf /etc/supervisor/conf.d/zola.conf +RUN sed -e 's,^logfile=.*$,logfile=/run/supervisord.log,' -i /etc/supervisor/supervisord.conf + +ADD nginx.conf /app/code/nginx.conf.default +ADD fpm.conf /etc/php/7.2/fpm/php-fpm.conf + +ADD public /app/code/public.default + +ADD start.sh /app/code/start.sh +ADD config.sh /app/code/config.sh.default +ADD rebuild.sh /app/code/rebuild.sh +ADD rebuild-loop.sh /app/code/rebuild-loop.sh +ADD rebuild.php /app/code/rebuild.php +ADD ssh.config /app/code/ssh.config.default + +RUN mkdir /run/nginx && \ + rm /var/log/nginx/*.log && \ + ln -s /dev/stderr /var/log/nginx/error.log && \ + ln -s /dev/stdout /var/log/nginx/access.log && \ + rmdir /var/cache/nginx && ln -s /tmp /var/cache/nginx && \ + ln -s /app/data/ssh /home/cloudron/.ssh + +RUN chown -R cloudron:cloudron /app/code /run/nginx + +WORKDIR /app/data + +CMD [ "/app/code/start.sh" ] + diff --git a/POSTINSTALL.md b/POSTINSTALL.md new file mode 100644 index 0000000..94c0fae --- /dev/null +++ b/POSTINSTALL.md @@ -0,0 +1,5 @@ +### Empty Website with Nginx + PHP. + +Use `cloudron push` to copy files into `/app/data/public/` and `cloudron exec` to get a remote terminal. + +Edit `/app/data/nginx.conf` to change the webserver configuration according to the [Nginx Documentation](https://nginx.org/en/docs/). diff --git a/README.md b/README.md new file mode 100644 index 0000000..bd2d439 --- /dev/null +++ b/README.md @@ -0,0 +1,24 @@ +# Nginx Cloudron App + +This repository contains the Cloudron app package source for Nginx. + +## Installation + +[![Install](https://cloudron.io/img/button.svg)](https://cloudron.io/button.html?app=org.nginx.cloudronapp) + +or using the [Cloudron command line tooling](https://cloudron.io/references/cli.html) + +``` +cloudron install --appstore-id org.nginx.cloudronapp +``` + +## Building + +The app package can be built using the [Cloudron command line tooling](https://cloudron.io/references/cli.html). + +``` +cd nginx-app + +cloudron build +cloudron install +``` diff --git a/config.sh b/config.sh new file mode 100644 index 0000000..f643bad --- /dev/null +++ b/config.sh @@ -0,0 +1,2 @@ +REPO_URL="" +REBUILD_INTERVAL=3600 \ No newline at end of file diff --git a/fpm.conf b/fpm.conf new file mode 100644 index 0000000..5c91e92 --- /dev/null +++ b/fpm.conf @@ -0,0 +1,14 @@ +[global] +error_log = /dev/stderr + +[www] +listen = /var/run/php-fpm.sock +listen.mode = 0666 +user = cloudron +group = cloudron + +pm = dynamic +pm.max_children = 5 +pm.start_servers = 2 +pm.min_spare_servers = 1 +pm.max_spare_servers = 3 diff --git a/logo.png b/logo.png new file mode 100644 index 0000000..a59d02d Binary files /dev/null and b/logo.png differ diff --git a/medialinks/medialink_0.png b/medialinks/medialink_0.png new file mode 100644 index 0000000..1b676c0 Binary files /dev/null and b/medialinks/medialink_0.png differ diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..da802cb --- /dev/null +++ b/nginx.conf @@ -0,0 +1,81 @@ +user cloudron; +worker_processes 1; + +error_log /dev/stderr; + +events { + worker_connections 1024; +} + +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + + sendfile on; + keepalive_timeout 65; + + gzip on; + gzip_http_version 1.1; + gzip_vary on; + gzip_comp_level 6; + gzip_proxied any; + gzip_types text/plain text/html text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript text/x-js; + gzip_buffers 16 8k; + gzip_static on; + + server { + listen 8000; + + root /run/html; + index index.php index.html index.htm; + + try_files $uri $uri/index.html $uri/ =404; + absolute_redirect off; + + location /_setup.html { + + } + + location /_rebuild { + auth_basic "Token required"; + auth_basic_user_file /app/data/htpasswd; + limit_except POST { + deny all; + } + fastcgi_pass unix:/var/run/php-fpm.sock; + fastcgi_param GATEWAY_INTERFACE CGI/1.1; + fastcgi_param SERVER_SOFTWARE nginx; + fastcgi_param QUERY_STRING $query_string; + fastcgi_param REQUEST_METHOD $request_method; + fastcgi_param CONTENT_TYPE $content_type; + fastcgi_param CONTENT_LENGTH $content_length; + fastcgi_param SCRIPT_FILENAME /app/code/rebuild.php; + fastcgi_param SCRIPT_NAME /app/code/rebuild.php; + fastcgi_param REQUEST_URI $request_uri; + fastcgi_param DOCUMENT_URI $document_uri; + fastcgi_param DOCUMENT_ROOT $document_root; + fastcgi_param SERVER_PROTOCOL $server_protocol; + fastcgi_param REMOTE_PORT $remote_port; + fastcgi_param SERVER_ADDR $server_addr; + fastcgi_param SERVER_PORT $server_port; + fastcgi_param SERVER_NAME $server_name; + } + + # Disallow .htaccess .htpasswd etc. + location ~ /\.ht { + deny all; + } + + # Cache static files + location ~* \.html$ { + expires 1h; + } + + location ~* \.(ogg|ogv|svg|svgz|eot|otf|woff|woff2|mp4|mp3|ttf|css|rss|atom|js|jpg|jpeg|webp|webm|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)(\?.+)?$ { + access_log off; + log_not_found off; + expires max; + } + } +} + diff --git a/public/index.html b/public/index.html new file mode 100644 index 0000000..c28ec4b --- /dev/null +++ b/public/index.html @@ -0,0 +1,34 @@ + + + + Zola + + + + +

Zola

+

To get started, fill in the repository URL in /app/data/config.sh.

+ +

Webhook

+

+ To trigger a site rebuild from a webhook, use the following URL: +

+
+

+ If you want to clone a protected repository, you can grant access to the following SSH key: +

+
%SSH_KEY%
+ + + + \ No newline at end of file diff --git a/rebuild-loop.sh b/rebuild-loop.sh new file mode 100755 index 0000000..c9661cb --- /dev/null +++ b/rebuild-loop.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +. /app/data/config.sh + +while true; do + /app/code/rebuild.sh + sleep $REBUILD_INTERVAL +done \ No newline at end of file diff --git a/rebuild.php b/rebuild.php new file mode 100644 index 0000000..6554589 --- /dev/null +++ b/rebuild.php @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/rebuild.sh b/rebuild.sh new file mode 100755 index 0000000..204821a --- /dev/null +++ b/rebuild.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +set -eu + +REPO_PATH=/run/repo +WEB_PATH=/run/html + +. /app/data/config.sh + +if [ "$REPO_URL" == "" ]; then + echo "No REPO_URL set!" + exit 1 +fi + +if ! [ -d "$REPO_PATH" ]; then + git clone "$REPO_URL" "$REPO_PATH" + (cd "$REPO_PATH" && git submodule init) +fi + +cd "$REPO_PATH" +git pull +git submodule update + +zola build + +echo "Compressing files..." +find public -type f -name '*.css' -size +5k -exec zopfli '{}' \; +find public -type f -name '*.js' -size +5k -exec zopfli '{}' \; +find public -type f -name '*.html' -size +5k -exec zopfli '{}' \; + +echo "Updating webpage..." +mkdir -p "$WEB_PATH" +rsync -av --del public/ "$WEB_PATH/" \ No newline at end of file diff --git a/ssh.config b/ssh.config new file mode 100644 index 0000000..f4f7e76 --- /dev/null +++ b/ssh.config @@ -0,0 +1,3 @@ +Host * + StrictHostKeyChecking no + UserKnownHostsFile=/dev/null \ No newline at end of file diff --git a/start.sh b/start.sh new file mode 100755 index 0000000..eb9f604 --- /dev/null +++ b/start.sh @@ -0,0 +1,41 @@ +#!/bin/bash + +set -eu + +if ! [ -e "/app/data/nginx.conf" ]; then + cp -a "/app/code/nginx.conf.default" "/app/data/nginx.conf" +fi + +if ! [ -e "/app/data/config.sh" ]; then + cp -a "/app/code/config.sh.default" "/app/data/config.sh" +fi + +if ! [ -e "/app/data/ssh" ]; then + mkdir -p /app/data/ssh + cp /app/code/ssh.config.default /app/data/ssh/config + ssh-keygen -f /app/data/ssh/id_rsa -q -N "" +fi + +if ! [ -e "/app/data/token.txt" ]; then + token="$(pwgen 20 1)" + echo "$token" > /app/data/token.txt +fi + +if ! [ -e "/app/data/htpasswd" ]; then + token="$(cat /app/data/token.txt)" + echo "$token" > /app/data/token.txt + htpasswd -bc /app/data/htpasswd token "$token" +fi + +chown -R cloudron:cloudron /app/data + +cp -a "/app/code/public.default" "/run/html" +token="$(cat /app/data/token.txt)" +sed -i -e "s/%TOKEN%/$token/g" /run/html/index.html +ssh_key="$(cat /app/data/ssh/id_rsa.pub | sed 's/\//\\\//g')" +sed -i -e "s/%SSH_KEY%/$ssh_key/g" /run/html/index.html +chown cloudron:cloudron /run/html /run + +export HOME=/app/data + +exec /usr/bin/supervisord --configuration /etc/supervisor/supervisord.conf --nodaemon -i Zola \ No newline at end of file diff --git a/supervisord.conf b/supervisord.conf new file mode 100644 index 0000000..ff3f79b --- /dev/null +++ b/supervisord.conf @@ -0,0 +1,30 @@ +[program:nginx] +directory=/app/data +command=/usr/sbin/nginx -c /app/data/nginx.conf -g 'daemon off;' +autostart=true +autorestart=true +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0 + +[program:fpm] +directory=/app/data +command=/usr/sbin/php-fpm7.2 -F +autostart=true +autorestart=true +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0 + +[program:rebuild] +directory=/app/data +command=/app/code/rebuild-loop.sh +user=cloudron +autostart=true +autorestart=true +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0