Skip to content

Commit

Permalink
Implement a reverse proxy and ensure graceful shutdown of processes
Browse files Browse the repository at this point in the history
  • Loading branch information
k0gen committed Sep 19, 2024
1 parent 4903f7a commit 87757a7
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FROM ghcr.io/getalby/hub:v1.8.0 AS builder
RUN apt update; apt install -y --no-install-recommends caddy

FROM debian:12-slim AS final

Expand All @@ -10,5 +11,7 @@ COPY --from=builder /usr/lib/nwc/libglalby_bindings.so /usr/lib/nwc/
COPY --from=builder /usr/lib/nwc/libldk_node.so /usr/lib/nwc/
COPY --from=builder /bin/main /bin/
COPY --chmod=755 docker_entrypoint.sh /usr/local/bin/
COPY --from=builder /usr/bin/caddy /usr/bin/
RUN mkdir -p /etc/caddy

LABEL maintainer="andrewlunde <[email protected]>"
33 changes: 31 additions & 2 deletions docker_entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,21 @@ export WORK_DIR="/data/albyhub"
export PORT=8080 #the port on which the app should listen on (default='blah' #8080)
export LOG_EVENTS=true # makes debugging easier

# Reverse proxy configuration (aka Firefox patch)
cat <<EOF >/etc/caddy/Caddyfile
{
admin off
servers {
protocols h1 h2c h3
}
}
:8443 {
tls /mnt/cert/main.cert.pem /mnt/cert/main.key.pem
reverse_proxy albyhub.embassy:8080
}
EOF

# Output some debug information
echo "LN Backend Type: $LN_BACKEND_TYPE"
if [ "$LN_VALUE" = "lnd" ]; then
Expand All @@ -110,5 +125,19 @@ if [ "$LN_VALUE" = "lnd" ]; then
echo "LND Macaroon: $LND_MACAROON_FILE"
fi

# Start the Alby Hub app
exec /bin/main
# Set up a trap to catch INT signal for graceful shutdown and start
_term() {
echo "Caught INT signal!"
kill -INT "$alby_process" 2>/dev/null
kill -INT "$caddy_process" 2>/dev/null
}

main &
alby_process=$!

caddy run --config /etc/caddy/Caddyfile &
caddy_process=$!

trap _term INT

wait $caddy_process $alby_process
5 changes: 5 additions & 0 deletions manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ main:
args: []
mounts:
main: /data
cert: /mnt/cert
lnd: /mnt/lnd
health-checks:
web-ui:
Expand All @@ -39,6 +40,9 @@ environment: ~
volumes:
main:
type: data
cert:
type: certificate
interface-id: main
lnd:
type: pointer
package-id: lnd
Expand All @@ -52,6 +56,7 @@ interfaces:
tor-config:
port-mapping:
80: "8080"
443: "8443"
lan-config:
443:
ssl: true
Expand Down

0 comments on commit 87757a7

Please sign in to comment.