First working version

This commit is contained in:
Dennis Schwerdel 2020-11-12 12:01:14 +01:00
commit d08ff0c7ef
20 changed files with 366 additions and 0 deletions

4
.dockerignore Normal file
View File

@ -0,0 +1,4 @@
test/*
.git/*
screenshots/*

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
node_modules/

2
CHANGELOG Normal file
View File

@ -0,0 +1,2 @@
[0.1.0]
* First version

25
CloudronManifest.json Normal file
View File

@ -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"
}

5
DESCRIPTION.md Normal file
View File

@ -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/).

50
Dockerfile Normal file
View File

@ -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" ]

5
POSTINSTALL.md Normal file
View File

@ -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/).

24
README.md Normal file
View File

@ -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
```

2
config.sh Normal file
View File

@ -0,0 +1,2 @@
REPO_URL=""
REBUILD_INTERVAL=3600

14
fpm.conf Normal file
View File

@ -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

BIN
logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 548 B

BIN
medialinks/medialink_0.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

81
nginx.conf Normal file
View File

@ -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;
}
}
}

34
public/index.html Normal file
View File

@ -0,0 +1,34 @@
<html>
<head>
<title>Zola</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/water.css@2/out/water.css">
</head>
<body>
<h1>Zola</h1>
<p>To get started, fill in the repository URL in <code>/app/data/config.sh</code>.</p>
<button onclick="rebuild()">Rebuild now</button>
<h2>Webhook</h2>
<p>
To trigger a site rebuild from a webhook, use the following URL:
</p>
<pre><code id="webhook_url"></code></pre>
<p>
If you want to clone a protected repository, you can grant access to the following SSH key:
</p>
<pre><code>%SSH_KEY%</code></pre>
<script>
var token = "%TOKEN%";
var url = `https://token:${token}@${window.location.hostname}/_rebuild`;
function rebuild() {
var xhr = new XMLHttpRequest();
xhr.open("POST", url, false);
xhr.send();
alert("Rebuild started");
}
document.getElementById('webhook_url').innerHTML = url;
</script>
</body>
</html>

8
rebuild-loop.sh Executable file
View File

@ -0,0 +1,8 @@
#!/bin/bash
. /app/data/config.sh
while true; do
/app/code/rebuild.sh
sleep $REBUILD_INTERVAL
done

3
rebuild.php Normal file
View File

@ -0,0 +1,3 @@
<?php
shell_exec('killall sleep');
?>

33
rebuild.sh Executable file
View File

@ -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/"

3
ssh.config Normal file
View File

@ -0,0 +1,3 @@
Host *
StrictHostKeyChecking no
UserKnownHostsFile=/dev/null

41
start.sh Executable file
View File

@ -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

30
supervisord.conf Normal file
View File

@ -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