-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(docker): unify mostro and relay compose #392
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,44 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
docker-build: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@set -o pipefail; \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
cd docker && \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
set -a && source .env && set +a && \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
mkdir -p config/lnd && \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
echo "Checking LND files..." && \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
echo "LND_CERT_FILE=$${LND_CERT_FILE}" && \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
echo "LND_MACAROON_FILE=$${LND_MACAROON_FILE}" && \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if [ ! -f "$${LND_CERT_FILE}" ]; then \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
echo "Error: LND cert file not found at: $${LND_CERT_FILE}"; \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
exit 1; \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
fi && \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if [ ! -f "$${LND_MACAROON_FILE}" ]; then \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
echo "Error: LND macaroon file not found at: $${LND_MACAROON_FILE}"; \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
exit 1; \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
fi && \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
echo "Copying LND cert and macaroon to docker config" && \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
cp -v $${LND_CERT_FILE} config/lnd/tls.cert && \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
cp -v $${LND_MACAROON_FILE} config/lnd/admin.macaroon && \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
echo "Building docker image" && \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
docker compose build | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
docker-up: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@set -o pipefail; \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
cd docker && \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
echo "Copying Nostr relay config" && \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
mkdir -p config/relay && \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
cp -v ./relay_config.toml config/relay/config.toml && \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
echo "Starting services" && \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
docker compose up -d | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
docker-relay-up: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@set -o pipefail; \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
cd docker && \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
echo "Copying Nostr relay config" && \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
mkdir -p config/relay && \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
cp -v ./relay_config.toml config/relay/config.toml && \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
echo "Starting Nostr relay" && \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
docker compose up -d nostr-relay | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+32
to
+39
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Reduce code duplication with docker-up target. The relay configuration copying logic is duplicated between Suggested refactor: +copy-relay-config:
+ @set -o pipefail; \
+ cd docker && \
+ if [ ! -f "./relay_config.toml" ]; then \
+ echo "Error: relay_config.toml not found"; \
+ exit 1; \
+ fi && \
+ echo "Copying Nostr relay config" && \
+ mkdir -p config/relay && \
+ cp -v ./relay_config.toml config/relay/config.toml
+
docker-up: copy-relay-config
- @set -o pipefail; \
- cd docker && \
- echo "Copying Nostr relay config" && \
- mkdir -p config/relay && \
- cp -v ./relay_config.toml config/relay/config.toml && \
echo "Starting services" && \
docker compose up -d
-docker-relay-up:
+docker-relay-up: copy-relay-config
@set -o pipefail; \
cd docker && \
- echo "Copying Nostr relay config" && \
- mkdir -p config/relay && \
- cp -v ./relay_config.toml config/relay/config.toml && \
echo "Starting Nostr relay" && \
docker compose up -d nostr-relay 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
docker-down: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@set -o pipefail; \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
cd docker && \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
docker compose down |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# LND TLS certificate and macaroon files (required) | ||
LND_CERT_FILE= | ||
LND_MACAROON_FILE= | ||
|
||
# Port for local relay | ||
MOSTRO_RELAY_LOCAL_PORT=7000 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,50 @@ | ||
# Build stage | ||
FROM rust:1.81 AS builder | ||
FROM rust:1.82 AS builder | ||
|
||
# Install build dependencies | ||
RUN apt-get update && \ | ||
apt-get install -y --no-install-recommends cmake build-essential libsqlite3-dev pkg-config libssl-dev protobuf-compiler && \ | ||
rm -rf /var/lib/apt/lists/* | ||
|
||
|
||
# Set working directory | ||
WORKDIR /mostro | ||
|
||
# Copy Cargo.toml and Cargo.lock to leverage Docker cache | ||
COPY Cargo.toml Cargo.lock ./ | ||
RUN cargo fetch | ||
|
||
# Copy source code | ||
COPY . . | ||
|
||
# Install build dependencies | ||
RUN apt-get update && \ | ||
apt-get install -y cmake build-essential libsqlite3-dev pkg-config libssl-dev protobuf-compiler | ||
|
||
# Build the project in release mode | ||
RUN cargo build --release | ||
|
||
# Production stage | ||
FROM debian:bookworm-slim | ||
|
||
# Install dependencies | ||
RUN apt-get update && apt-get install -y --reinstall ca-certificates | ||
|
||
# Add a non-root user | ||
RUN useradd -m mostrouser | ||
|
||
# Copy built binary from build stage | ||
COPY --from=builder /mostro/target/release/mostrod /usr/local/bin/mostrod | ||
|
||
WORKDIR /mostro | ||
WORKDIR /home/mostrouser | ||
|
||
# Copy settings and empty database | ||
COPY --chown=mostrouser:mostrouser ./docker/settings.docker.toml ./docker/empty.mostro.db ./ | ||
COPY ./docker/settings.docker.toml ./docker/empty.mostro.db ./ | ||
|
||
# Copy start script | ||
COPY --chown=mostrouser:mostrouser ./docker/start.sh ./start.sh | ||
COPY ./docker/start.sh ./start.sh | ||
RUN chmod +x ./start.sh | ||
|
||
# Add a non-root user and switch to it | ||
RUN useradd -m mostrouser | ||
RUN chown -R mostrouser:mostrouser /home/mostrouser | ||
|
||
# Switch to non-root user | ||
USER mostrouser | ||
|
||
# Start mostro (copy settings and database if it's not created yet) | ||
ENTRYPOINT ["./start.sh"] | ||
CMD ["./start.sh"] |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -5,5 +5,19 @@ services: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
dockerfile: docker/Dockerfile | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
volumes: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
- ./config:/config # settings.toml and mostro.db | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
- ~/.polar/networks/1/volumes/lnd:/lnd # LND data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
platform: linux/amd64 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
networks: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
- default | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
nostr-relay: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
image: scsibug/nostr-rs-relay | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
container_name: nostr-relay | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ports: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
- '${MOSTRO_RELAY_LOCAL_PORT:-7000}:8080' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
volumes: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
- './config/relay/data:/usr/src/app/db:Z' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
- './config/relay/config.toml:/usr/src/app/config.toml:ro,Z' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+12
to
+19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider adding container reliability configurations. While the basic setup is correct, consider the following improvements for production readiness:
Apply these improvements: nostr-relay:
image: scsibug/nostr-rs-relay
container_name: nostr-relay
+ restart: unless-stopped
+ healthcheck:
+ test: ["CMD", "curl", "-f", "http://localhost:8080/"]
+ interval: 30s
+ timeout: 10s
+ retries: 3
ports:
- '${MOSTRO_RELAY_LOCAL_PORT:-7000}:8080'
volumes:
- - './config/relay/data:/usr/src/app/db:Z'
- - './config/relay/config.toml:/usr/src/app/config.toml:ro,Z'
+ - nostr_relay_data:/usr/src/app/db
+ - type: bind
+ source: ./config/relay/config.toml
+ target: /usr/src/app/config.toml
+ read_only: true
volumes:
nostr_relay_data: 📝 Committable suggestion
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was just moved, not really changed from what it previously was There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jgmontoya, understood. Thank you for the clarification. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
networks: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
default: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
driver: bridge |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
[lightning] | ||
# path to tls.cert file | ||
lnd_cert_file = '/lnd/alice/tls.cert' | ||
lnd_cert_file = '/config/lnd/tls.cert' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification Docker volume configuration needs adjustment for LND certificates The path
Required changes:
🔗 Analysis chainVerify Docker volume mounting for LND certificates The paths have been standardized to use Let's verify the Docker compose configuration matches these paths: Also applies to: 5-5 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Verify Docker volume mounting configuration for LND certificates
# Expected: Docker compose file should mount these paths correctly
# Check Docker compose files for volume mounting
rg -l "config/lnd" docker/
Length of output: 212 Script: #!/bin/bash
# Let's check the actual volume mounting configuration in compose.yml
cat docker/compose.yml
Length of output: 544 Script: #!/bin/bash
# Let's check the Dockerfile to see how the config directory is handled
cat docker/Dockerfile
# Also check the start script which might handle the LND cert setup
cat docker/start.sh
Length of output: 1745 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the cert and macaroon files are copied in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jgmontoya, thank you for clarifying. I see now that the cert and macaroon files are copied in the ✏️ Learnings added
|
||
# path to macaroon file | ||
lnd_macaroon_file = '/lnd/alice/data/chain/bitcoin/regtest/admin.macaroon' | ||
lnd_macaroon_file = '/config/lnd/admin.macaroon' | ||
# lnd grpc host and port | ||
lnd_grpc_host = 'https://host.docker.internal:10001' | ||
# lightning invoices sent by the buyer to Mostro should have at least | ||
# this expiration time in seconds | ||
invoice_expiration_window = 3600 | ||
# Hold invoice cltv delta (expiration time in blocks) | ||
hold_invoice_cltv_delta = 144 | ||
# This is the time that a taker has to pay the invoice (seller) or | ||
# This is the time that a taker has to pay the invoice (seller) or | ||
# to add a new invoice (buyer), in seconds | ||
hold_invoice_expiration_window = 300 | ||
# Retries for failed payments | ||
|
@@ -20,7 +20,7 @@ payment_retries_interval = 60 | |
|
||
[nostr] | ||
nsec_privkey = 'nsec1...' | ||
relays = ['ws://localhost:7000'] | ||
relays = ['ws://host.docker.internal:7000', 'ws://localhost:7000'] | ||
|
||
[mostro] | ||
# Mostro Fee | ||
|
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add validation checks in docker-up target.
The target should validate the relay configuration file and check for running services before proceeding.
Suggested improvement:
📝 Committable suggestion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is really needed (or actually wanted for that matter 🙄)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jgmontoya, understood. I'll disregard the suggestion. Let me know if there's anything else I can assist with.