Merge pull request 'Add docker-compose support' (#22) from tobyjaffey/snac2:docker into master

Reviewed-on: https://codeberg.org/grunfink/snac2/pulls/22
This commit is contained in:
grunfink 2022-12-13 08:15:52 +00:00
commit 1eb5c7a6e2
9 changed files with 224 additions and 0 deletions

12
Dockerfile Normal file
View file

@ -0,0 +1,12 @@
FROM alpine
ENV LANG C.UTF-8
ENV LC_ALL C.UTF-8
RUN apk add --no-cache curl-dev build-base
COPY . /build
WORKDIR /build
RUN make
COPY examples/docker-entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh
ENTRYPOINT ["/bin/sh", "/usr/local/bin/entrypoint.sh"]
EXPOSE 8001
CMD /build/snac

View file

@ -43,6 +43,19 @@ Run `make` and then `make install` as root.
See the administrator manual on how to proceed from here.
# Testing via Docker
A `docker-compose` file is provided for development and testing. To start snac with an nginx HTTPS frontend, run:
docker-compose build && docker-compose up
This will:
- Start snac, storing data in `data/`
- Configure snac to listen on port 8001 with a server name of `localhost` (see `examples/docker-entrypoint.sh`)
- Create a new user `testuser` and print the user's generated password on the console (see `examples/docker-entrypoint.sh`)
- Start nginx to handle HTTPS, using the certificate pair from `nginx-alpine-ssl/nginx-selfsigned.*` (see `examples/nginx-alpine-ssl/entrypoint.sh`)
# License
See the LICENSE file for details.

27
docker-compose.yaml Normal file
View file

@ -0,0 +1,27 @@
---
version: '3'
services:
snac:
build: .
image: snac
container_name: snac
restart: unless-stopped
security_opt:
- no-new-privileges:true
volumes:
- ./data:/data
ports:
- "8001:8001"
nginx-alpine-ssl:
build: examples/nginx-alpine-ssl
image: examples/nginx-alpine-ssl
container_name: nginx-alpine-ssl
restart: unless-stopped
security_opt:
- no-new-privileges:true
ports:
- "443:443"
- "80:80"

6
examples/docker-entrypoint.sh Executable file
View file

@ -0,0 +1,6 @@
if [ ! -e /data/data/server.json ]
then
echo -ne "0.0.0.0\r\n8001\r\nlocalhost\r\n\r\n" | /build/snac init /data/data
/build/snac adduser /data/data testuser
fi
SSLKEYLOGFILE=/data/key /build/snac httpd /data/data

View file

@ -0,0 +1,13 @@
FROM alpine
RUN apk add nginx
RUN mkdir -p /run/nginx
ADD default.conf /etc/nginx/http.d/default.conf
ADD *.key /etc/ssl/private/
ADD *.crt /etc/ssl/certs/
WORKDIR /var/www/localhost/htdocs
COPY entrypoint.sh /usr/local/bin
RUN chmod +x /usr/local/bin/entrypoint.sh
ENTRYPOINT ["/bin/sh", "/usr/local/bin/entrypoint.sh"]
#EXPOSE 80
EXPOSE 443
CMD ["/bin/sh", "-c", "nginx -g 'daemon off;'; nginx -s reload;"]

View file

@ -0,0 +1,89 @@
server {
listen 80 default_server;
listen [::]:80 default_server;
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;
ssl_certificate /etc/ssl/certs/nginx-selfsigned.crt;
ssl_certificate_key /etc/ssl/private/nginx-selfsigned.key;
location /.well-known/webfinger {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_redirect off;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Proxy "";
proxy_pass_header Server;
proxy_buffering on;
tcp_nodelay on;
proxy_pass http://snac:8001;
proxy_set_header Host $http_host;
}
location /.well-known/nodeinfo {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_redirect off;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Proxy "";
proxy_pass_header Server;
proxy_buffering on;
tcp_nodelay on;
proxy_pass http://snac:8001;
proxy_set_header Host $http_host;
}
location / {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_redirect off;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Proxy "";
proxy_pass_header Server;
proxy_buffering on;
tcp_nodelay on;
proxy_pass http://snac:8001;
proxy_set_header Host $http_host;
}
location /fedi/ {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_redirect off;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Proxy "";
proxy_pass_header Server;
proxy_buffering on;
tcp_nodelay on;
proxy_pass http://snac:8001;
proxy_set_header Host $http_host;
}
}

View file

@ -0,0 +1,15 @@
cd /etc/nginx/http.d;
export CRT="${CRT:=nginx-selfsigned.crt}";
if [ -f "/etc/ssl/certs/$CRT" ]
then
# set crt file in the default.conf file
sed -i "/ssl_certificate \//c\\\tssl_certificate \/etc\/ssl\/certs\/$CRT;" default.conf;
fi
export KEY="${KEY:=nginx-selfsigned.key}";
if [ -f "/etc/ssl/private/$KEY" ]
then
# set key file in the default.conf file
sed -i "/ssl_certificate_key \//c\\\tssl_certificate_key \/etc\/ssl\/private\/$KEY;" default.conf;
fi
nginx -g 'daemon off;'; nginx -s reload;

View file

@ -0,0 +1,21 @@
-----BEGIN CERTIFICATE-----
MIIDjDCCAnSgAwIBAgIUCCSqvSfnCK67C4JNfoiXUXyTIK4wDQYJKoZIhvcNAQEL
BQAwSTELMAkGA1UEBhMCQ0ExCzAJBgNVBAgMAlFDMRYwFAYDVQQKDA1Db21wYW55
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