commit 1eb5c7a

grunfink  ·  2022-12-13 08:15:52 +0000 UTC
parents aa82e14, 4afa513
Merge pull request 'Add docker-compose support' (#22) from tobyjaffey/snac2:docker into master

Reviewed-on: https://codeberg.org/grunfink/snac2/pulls/22
9 files changed,  +224, -0
+12, -0
 1@@ -0,0 +1,12 @@
 2+FROM alpine
 3+ENV LANG C.UTF-8
 4+ENV LC_ALL C.UTF-8
 5+RUN apk add --no-cache curl-dev build-base
 6+COPY . /build
 7+WORKDIR /build
 8+RUN make
 9+COPY examples/docker-entrypoint.sh /usr/local/bin/entrypoint.sh
10+RUN chmod +x /usr/local/bin/entrypoint.sh
11+ENTRYPOINT ["/bin/sh", "/usr/local/bin/entrypoint.sh"]
12+EXPOSE 8001
13+CMD /build/snac
+13, -0
 1@@ -43,6 +43,19 @@ Run `make` and then `make install` as root.
 2 
 3 See the administrator manual on how to proceed from here.
 4 
 5+# Testing via Docker
 6+
 7+A `docker-compose` file is provided for development and testing. To start snac with an nginx HTTPS frontend, run:
 8+
 9+    docker-compose build && docker-compose up
10+
11+This will:
12+
13+- Start snac, storing data in `data/`
14+- Configure snac to listen on port 8001 with a server name of `localhost` (see `examples/docker-entrypoint.sh`)
15+- Create a new user `testuser` and print the user's generated password on the console (see `examples/docker-entrypoint.sh`)
16+- Start nginx to handle HTTPS, using the certificate pair from `nginx-alpine-ssl/nginx-selfsigned.*` (see `examples/nginx-alpine-ssl/entrypoint.sh`)
17+
18 # License
19 
20 See the LICENSE file for details.
+27, -0
 1@@ -0,0 +1,27 @@
 2+---
 3+version: '3'
 4+
 5+services:
 6+    snac:
 7+        build: .
 8+        image: snac
 9+        container_name: snac
10+        restart: unless-stopped
11+        security_opt:
12+            - no-new-privileges:true
13+        volumes:
14+            - ./data:/data
15+        ports:
16+            - "8001:8001"
17+
18+    nginx-alpine-ssl:
19+        build: examples/nginx-alpine-ssl
20+        image: examples/nginx-alpine-ssl
21+        container_name: nginx-alpine-ssl
22+        restart: unless-stopped
23+        security_opt:
24+            - no-new-privileges:true
25+        ports:
26+            - "443:443"
27+            - "80:80"
28+
+6, -0
1@@ -0,0 +1,6 @@
2+if [ ! -e /data/data/server.json ]
3+then
4+    echo -ne "0.0.0.0\r\n8001\r\nlocalhost\r\n\r\n" | /build/snac init /data/data
5+    /build/snac adduser /data/data testuser
6+fi
7+SSLKEYLOGFILE=/data/key /build/snac httpd /data/data
+13, -0
 1@@ -0,0 +1,13 @@
 2+FROM alpine
 3+RUN apk add nginx
 4+RUN mkdir -p /run/nginx
 5+ADD default.conf /etc/nginx/http.d/default.conf
 6+ADD *.key /etc/ssl/private/
 7+ADD *.crt /etc/ssl/certs/
 8+WORKDIR /var/www/localhost/htdocs
 9+COPY entrypoint.sh /usr/local/bin
10+RUN chmod +x /usr/local/bin/entrypoint.sh
11+ENTRYPOINT ["/bin/sh", "/usr/local/bin/entrypoint.sh"]
12+#EXPOSE 80
13+EXPOSE 443
14+CMD ["/bin/sh", "-c", "nginx -g 'daemon off;'; nginx -s reload;"]
+89, -0
 1@@ -0,0 +1,89 @@
 2+server {
 3+    listen 80 default_server;
 4+    listen [::]:80 default_server;
 5+    listen 443 ssl http2 default_server;
 6+    listen [::]:443 ssl http2 default_server;
 7+    ssl_certificate /etc/ssl/certs/nginx-selfsigned.crt;
 8+    ssl_certificate_key /etc/ssl/private/nginx-selfsigned.key;
 9+
10+    location /.well-known/webfinger {
11+        proxy_http_version      1.1;
12+        proxy_set_header        Upgrade $http_upgrade;
13+        proxy_set_header        Connection "upgrade";
14+        proxy_redirect          off;
15+        proxy_connect_timeout   90;
16+        proxy_send_timeout      90;
17+        proxy_read_timeout      90;
18+        proxy_set_header        Host $host;
19+        proxy_set_header        X-Real-IP $remote_addr;
20+        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
21+        proxy_set_header        X-Forwarded-Proto $scheme;
22+        proxy_set_header        Proxy "";
23+        proxy_pass_header       Server;
24+        proxy_buffering on;
25+        tcp_nodelay on;
26+        proxy_pass http://snac:8001;
27+        proxy_set_header Host $http_host;
28+    }
29+
30+    location /.well-known/nodeinfo {
31+        proxy_http_version      1.1;
32+        proxy_set_header        Upgrade $http_upgrade;
33+        proxy_set_header        Connection "upgrade";
34+        proxy_redirect          off;
35+        proxy_connect_timeout   90;
36+        proxy_send_timeout      90;
37+        proxy_read_timeout      90;
38+        proxy_set_header        Host $host;
39+        proxy_set_header        X-Real-IP $remote_addr;
40+        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
41+        proxy_set_header        X-Forwarded-Proto $scheme;
42+        proxy_set_header        Proxy "";
43+        proxy_pass_header       Server;
44+        proxy_buffering on;
45+        tcp_nodelay on;
46+        proxy_pass http://snac:8001;
47+        proxy_set_header Host $http_host;
48+    }
49+
50+    location / {
51+        proxy_http_version      1.1;
52+        proxy_set_header        Upgrade $http_upgrade;
53+        proxy_set_header        Connection "upgrade";
54+        proxy_redirect          off;
55+        proxy_connect_timeout   90;
56+        proxy_send_timeout      90;
57+        proxy_read_timeout      90;
58+        proxy_set_header        Host $host;
59+        proxy_set_header        X-Real-IP $remote_addr;
60+        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
61+        proxy_set_header        X-Forwarded-Proto $scheme;
62+        proxy_set_header        Proxy "";
63+        proxy_pass_header       Server;
64+        proxy_buffering on;
65+        tcp_nodelay on;
66+        proxy_pass http://snac:8001;
67+        proxy_set_header Host $http_host;
68+    }
69+
70+    location /fedi/ {
71+        proxy_http_version      1.1;
72+        proxy_set_header        Upgrade $http_upgrade;
73+        proxy_set_header        Connection "upgrade";
74+        proxy_redirect          off;
75+        proxy_connect_timeout   90;
76+        proxy_send_timeout      90;
77+        proxy_read_timeout      90;
78+        proxy_set_header        Host $host;
79+        proxy_set_header        X-Real-IP $remote_addr;
80+        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
81+        proxy_set_header        X-Forwarded-Proto $scheme;
82+        proxy_set_header        Proxy "";
83+        proxy_pass_header       Server;
84+        proxy_buffering on;
85+        tcp_nodelay on;
86+        proxy_pass http://snac:8001;
87+        proxy_set_header Host $http_host;
88+    }
89+}
90+
+15, -0
 1@@ -0,0 +1,15 @@
 2+cd /etc/nginx/http.d;
 3+export CRT="${CRT:=nginx-selfsigned.crt}";
 4+if [ -f "/etc/ssl/certs/$CRT" ]
 5+then
 6+    # set crt file in the default.conf file
 7+    sed -i "/ssl_certificate \//c\\\tssl_certificate \/etc\/ssl\/certs\/$CRT;" default.conf;
 8+fi
 9+export KEY="${KEY:=nginx-selfsigned.key}";
10+if [ -f "/etc/ssl/private/$KEY" ]
11+then
12+    # set key file in the default.conf file
13+    sed -i "/ssl_certificate_key \//c\\\tssl_certificate_key \/etc\/ssl\/private\/$KEY;" default.conf;
14+fi
15+nginx -g 'daemon off;'; nginx -s reload;
16+
+21, -0
 1@@ -0,0 +1,21 @@
 2+-----BEGIN CERTIFICATE-----
 3+MIIDjDCCAnSgAwIBAgIUCCSqvSfnCK67C4JNfoiXUXyTIK4wDQYJKoZIhvcNAQEL
 4+BQAwSTELMAkGA1UEBhMCQ0ExCzAJBgNVBAgMAlFDMRYwFAYDVQQKDA1Db21wYW55
 5+LCBJbmMuMRUwEwYDVQQDDAxteWRvbWFpbi5jb20wHhcNMjIxMjEyMTAwNzU1WhcN
 6+MjMxMjEyMTAwNzU1WjBJMQswCQYDVQQGEwJDQTELMAkGA1UECAwCUUMxFjAUBgNV
 7+BAoMDUNvbXBhbnksIEluYy4xFTATBgNVBAMMDG15ZG9tYWluLmNvbTCCASIwDQYJ
 8+KoZIhvcNAQEBBQADggEPADCCAQoCggEBANss2w/GUwKcoUxHsWDfnldEuJzwx3Jr
 9+oRvTZY7ZcEM8vsVW8Xi61jpo2H/Uqv+3jl6+R6UFL1IKQUY0jn9KatYkfrHdHcYx
10+RwH8yLKWfCY9/qrPE8NzYQMkeNUqu5oGWDMFoCcGAuHOzB+v6JR2/0zaEavi96dZ
11+ZwjijdZtZAB9BuqD5R5dmVBV1fYSWM/X0/KN2RPpoBRak+Hmpo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