Skip to content
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

Merged
merged 1 commit into from
Nov 11, 2024

Conversation

jgmontoya
Copy link
Contributor

@jgmontoya jgmontoya commented Nov 10, 2024

This also improves the Dockerfile.

There is still some work to be done, but getting started with mostro now should be easier: if you already have a polar network/lnd-node set up:

git clone https://github.com/MostroP2P/mostro.git
# Create docker/.env with proper values
make docker-build
# Copy your settings.toml on docker/config/settings.toml, if not then one will be created for you but you'll need to fill your nsec later
make docker-up

This will spin up a relay and the mostro instance pointing to that relay, it will copy the LND cert file and macaroon file and allow communicating with the running polar node.

also improve docker image and ergonomics
Copy link
Contributor

coderabbitai bot commented Nov 10, 2024

Walkthrough

The changes in this pull request involve modifications to various configuration and build files for a Docker-based application. Key updates include adjustments to the .gitignore file to manage ignored directories, enhancements to the Makefile for Docker operations, and updates to the Docker environment configuration. Additionally, the Dockerfile and Docker Compose configurations have been revised to improve the build process and service management. Documentation has been updated to reflect these changes, providing clearer instructions for users.

Changes

File Change Summary
.gitignore Removed entry for /relay/data/*, added entry for docker/config, added comment header for clarity.
Makefile Added targets: docker-build, docker-up, docker-relay-up, docker-down for managing Docker services.
docker/.env.example Added variables: LND_CERT_FILE, LND_MACAROON_FILE, MOSTRO_RELAY_LOCAL_PORT.
docker/DOCKER.md Updated documentation for Docker setup, including prerequisites and configuration details.
docker/Dockerfile Updated Rust version to 1.82, added build dependencies, modified working directory, changed entry point.
docker/compose.yml Added nostr-relay service, updated mostro service with networks section, removed LND volume mapping.
docker/relay_config.toml Uncommented secret_key configuration option.
docker/settings.docker.toml Updated LND file paths and modified Nostr relay list.
relay/.env.example Removed file containing MOSTRO_RELAY_LOCAL_PORT variable.
relay/docker-compose.yml Removed file defining nostr-relay service configuration.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Docker
    participant NostrRelay
    participant LND

    User->>Docker: Run docker-compose up
    Docker->>NostrRelay: Start Nostr relay service
    Docker->>LND: Ensure LND service is running
    NostrRelay->>User: Relay service is active
Loading

🐰 "In the land of code, where rabbits play,
New Docker paths brighten the way.
With builds and services, all in a row,
Our MostroP2P will surely glow!
So hop along, let’s cheer and sing,
For changes made, oh what joy they bring!" 🐇


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🧹 Outside diff range and nitpick comments (11)
docker/.env.example (1)

1-3: Add example values or instructions for required LND files.

Since these variables are marked as required but have empty values, it would be helpful to:

  1. Add example paths or placeholders
  2. Include a comment explaining where users can find these files

Consider adding comments like this:

 # LND TLS certificate and macaroon files (required)
-LND_CERT_FILE=
-LND_MACAROON_FILE=
+# Default paths for LND in Bitcoin mainnet. Adjust according to your setup.
+LND_CERT_FILE=~/.lnd/tls.cert
+LND_MACAROON_FILE=~/.lnd/data/chain/bitcoin/mainnet/admin.macaroon
docker/compose.yml (1)

21-23: Consider adding network configurations for better control.

While the basic bridge network works, consider adding these configurations for better control and security:

 networks:
   default:
     driver: bridge
+    driver_opts:
+      com.docker.network.bridge.name: mostro_net
+    ipam:
+      config:
+        - subnet: 172.20.0.0/16
docker/Dockerfile (1)

35-44: Consider volume mounting for the database file.

While copying an empty database works, consider using a Docker volume for the database file to:

  • Persist data between container restarts
  • Avoid potential file permission issues
  • Make backups easier

Example docker-compose configuration:

volumes:
  - ./data:/home/mostrouser/data
Makefile (3)

1-21: Add additional safety checks and improve error handling in docker-build target.

While the basic file existence checks are good, consider enhancing the target with additional safety measures:

  1. Add permission checks for LND files
  2. Validate environment variables are non-empty
  3. Add cleanup on failure
  4. Consider making config paths configurable

Here's a suggested improvement:

 docker-build:
 	@set -o pipefail; \
 	cd docker && \
 	set -a && source .env && set +a && \
+	if [ -z "$${LND_CERT_FILE}" ] || [ -z "$${LND_MACAROON_FILE}" ]; then \
+		echo "Error: LND_CERT_FILE and LND_MACAROON_FILE must be set"; \
+		exit 1; \
+	fi && \
 	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 [ ! -r "$${LND_CERT_FILE}" ]; then \
+		echo "Error: LND cert file not readable 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 && \
+	if [ ! -r "$${LND_MACAROON_FILE}" ]; then \
+		echo "Error: LND macaroon file not readable 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

41-44: Add data preservation warning and options to docker-down target.

The target should warn users about potential data loss and provide options to preserve volumes if needed.

Suggested improvement:

 docker-down:
+	@echo "Warning: This will stop all containers and remove them. Data in non-persistent volumes will be lost."
+	@read -p "Are you sure you want to continue? [y/N] " -n 1 -r; \
+	echo; \
+	if [[ ! $$REPLY =~ ^[Yy]$$ ]]; then \
+		exit 1; \
+	fi
 	@set -o pipefail; \
 	cd docker && \
 	docker compose down

Consider adding a docker-down-volumes target if you need to clean up volumes as well:

docker-down-volumes:
	@echo "Warning: This will remove all containers AND volumes. ALL DATA WILL BE LOST."
	@read -p "Are you sure you want to continue? [y/N] " -n 1 -r; \
	echo; \
	if [[ ! $$REPLY =~ ^[Yy]$$ ]]; then \
		exit 1; \
	fi
	@set -o pipefail; \
	cd docker && \
	docker compose down -v

1-44: Add Makefile best practices and documentation.

Consider adding the following improvements to make the Makefile more maintainable and user-friendly:

  1. Declare PHONY targets
  2. Add a help target
  3. Document target dependencies

Add these at the beginning of the Makefile:

.PHONY: docker-build docker-up docker-relay-up docker-down help

help:
	@echo "Available targets:"
	@echo "  docker-build     - Build Docker images (requires LND cert and macaroon)"
	@echo "  docker-up        - Start all services"
	@echo "  docker-relay-up  - Start only the Nostr relay service"
	@echo "  docker-down      - Stop and remove containers"
docker/settings.docker.toml (1)

13-15: LGTM! Consider adding more context

The hold invoice expiration window is well-defined, but it could benefit from additional documentation explaining the rationale behind the 300-second timeout.

Consider adding a comment explaining:

  • Why 300 seconds was chosen
  • What happens if the time window is exceeded
docker/DOCKER.md (4)

9-9: Fix grammar: Use "an" before "LND"

Change "a LND node" to "an LND node" as "LND" is pronounced starting with a vowel sound.

-You need to have a LND node running locally. We recommend using [Polar](https://lightningpolar.com/) for this.
+You need to have an LND node running locally. We recommend using [Polar](https://lightningpolar.com/) for this.
🧰 Tools
🪛 LanguageTool

[misspelling] ~9-~9: Use “an” instead of ‘a’ if the following word starts with a vowel sound, e.g. ‘an article’, ‘an hour’.
Context: ...om/compose/install/). You need to have a LND node running locally. We recommend ...

(EN_A_VS_AN)


13-16: Add period after services list

Add a period after the services list for consistent punctuation.

The `compose.yml` sets up the following services:

- `mostro`: the MostroP2P service
-`nostr-relay`: the Nostr relay
+`nostr-relay`: the Nostr relay.
🧰 Tools
🪛 LanguageTool

[uncategorized] ~15-~15: Loose punctuation mark.
Context: ...s up the following services: - mostro: the MostroP2P service - nostr-relay: ...

(UNLIKELY_OPENING_PUNCTUATION)


32-34: Fix typo in configuration instructions

The word "acording" should be "according".

-2. Ensure you have the `settings.toml` configuration file and the `mostro.db` SQLite database in a `config` directory (acording to the `volumes` section). If you don't have those files from a previous installation, then the first time they will be created as follows:
+2. Ensure you have the `settings.toml` configuration file and the `mostro.db` SQLite database in a `config` directory (according to the `volumes` section). If you don't have those files from a previous installation, then the first time they will be created as follows:

68-69: Add context about the Nostr relay's purpose

Consider adding a brief explanation of what the Nostr relay is and why someone might want to run it independently of the main service. This would help users make informed decisions about their deployment.

## Steps for running just the Nostr relay

+The Nostr relay is a standalone component that handles message routing in the Nostr network. You might want to run it independently if you're only interested in relay functionality or for testing purposes.
+
1. Run the following command to start the Nostr relay:
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 579abbb and e4a09fa.

📒 Files selected for processing (10)
  • .gitignore (1 hunks)
  • Makefile (1 hunks)
  • docker/.env.example (1 hunks)
  • docker/DOCKER.md (1 hunks)
  • docker/Dockerfile (1 hunks)
  • docker/compose.yml (1 hunks)
  • docker/relay_config.toml (1 hunks)
  • docker/settings.docker.toml (2 hunks)
  • relay/.env.example (0 hunks)
  • relay/docker-compose.yml (0 hunks)
💤 Files with no reviewable changes (2)
  • relay/.env.example
  • relay/docker-compose.yml
🧰 Additional context used
🪛 LanguageTool
docker/DOCKER.md

[misspelling] ~9-~9: Use “an” instead of ‘a’ if the following word starts with a vowel sound, e.g. ‘an article’, ‘an hour’.
Context: ...om/compose/install/). You need to have a LND node running locally. We recommend ...

(EN_A_VS_AN)


[uncategorized] ~15-~15: Loose punctuation mark.
Context: ...s up the following services: - mostro: the MostroP2P service - nostr-relay: ...

(UNLIKELY_OPENING_PUNCTUATION)

🔇 Additional comments (13)
docker/.env.example (1)

5-6: Verify port 7000 availability and document the choice.

The default port 7000 needs verification to ensure it:

  1. Doesn't conflict with common services
  2. Is consistent with other components in the stack

Let's verify if this port is used elsewhere in the codebase:

✅ Verification successful

Port 7000 is well-documented and properly configured

Based on the search results, port 7000 is:

  • Consistently used across the codebase as the default local port for nostr-rs-relay
  • Well-documented in README.md and configuration files
  • Properly configured in Docker setup to map container's internal port 8080 to host port 7000
  • Not conflicting with any other services in the stack
  • A non-privileged port (>1024) commonly available for application use
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for other occurrences of port 7000 and nearby ports
# to identify potential conflicts

echo "Checking for port 7000 usage:"
rg -A 2 '7000|700[1-9]|70[1-9][0-9]'

echo -e "\nChecking compose files for port mappings:"
fd -e yml -e yaml compose | xargs cat

Length of output: 6691

.gitignore (2)

14-15: LGTM! Good practice to ignore binary outputs.

Adding bin/ to .gitignore is a good practice as it prevents binary artifacts from being committed to version control.


16-17: LGTM! Docker config exclusion aligns with unification goals.

The addition of docker/config with a clear comment header aligns well with the PR's objective of unifying Mostro and Relay compose configurations. This ensures that environment-specific Docker configurations are kept out of version control.

docker/compose.yml (2)

9-10: LGTM: Explicit network configuration added.

The explicit network configuration improves clarity and supports service unification.


Line range hint 1-23: Verify network accessibility requirements.

Let's verify if other services in the repository need to connect to these containers and if the current network configuration supports all required interactions.

✅ Verification successful

Based on the results, I can now generate the final response:

Network configuration is correctly set up for the required service interactions

The current network setup is sufficient because:

  • The only docker-compose file in the repository is docker/compose.yml
  • The mostro service connects to the nostr-relay via ws://localhost:7000 (from settings.tpl.toml)
  • Both services are on the same default bridge network, allowing container-to-container communication
  • The nostr-relay port 7000 is exposed to host, which matches the configuration in settings files
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for other docker-compose files and service dependencies

echo "Checking for other docker-compose files..."
fd -e yml -e yaml . | grep -i 'compose'

echo "Checking for service references in the codebase..."
rg --type toml --type yaml "nostr-relay|mostro" -C 2

Length of output: 3581

docker/Dockerfile (5)

13-15: Great optimization for Docker build caching!

The separation of dependency fetching from the build step will significantly improve build times when only source code changes.


29-31: LGTM! Good security practice with non-root user.

Creating a dedicated non-root user is a security best practice for containers.


26-27: Query: Is --reinstall necessary for ca-certificates?

The --reinstall flag for ca-certificates is unusual. Could you clarify why this is needed? A regular install should be sufficient unless there's a specific issue being addressed.

#!/bin/bash
# Check if there are any SSL/TLS related issues in the codebase
rg -l "certificate|ssl|tls" -g '!*.{md,lock}'

46-50: Verify start.sh script contents.

The switch from ENTRYPOINT to CMD provides more flexibility, which is good. However, we should verify the contents of start.sh to ensure it handles:

  • Proper signal handling
  • Graceful shutdown
  • Error scenarios
#!/bin/bash
# Check the contents of the start script
cat docker/start.sh

2-7: LGTM! Verify Rust version compatibility with dependencies.

The build stage improvements look good:

  • Consolidated RUN command reduces image layers
  • Proper cleanup of apt lists
  • Comprehensive build dependencies

Let's verify the Rust version compatibility:

✅ Verification successful

Rust 1.82 is compatible with the project dependencies

The project's dependencies are all using recent versions and none specify a minimum Rust version constraint. The project uses Rust 2021 edition which is well supported by Rust 1.82. Key observations:

  • Uses modern dependency versions (e.g., tokio 1.40.0, sqlx 0.6.2)
  • No explicit MSRV constraints in Cargo.toml
  • All major dependencies are actively maintained
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if any dependencies specify MSRV (Minimum Supported Rust Version)
rg -l "rust-version\s*=\s*" Cargo.toml

Length of output: 821


Script:

#!/bin/bash
# Let's check Cargo.toml for rust-version and dependencies
cat Cargo.toml

Length of output: 1313

docker/settings.docker.toml (2)

23-23: Verify Docker networking configuration

The addition of host.docker.internal is good for Docker networking, but we should ensure:

  1. Cross-platform compatibility (Windows/Mac/Linux)
  2. Proper network configuration in Docker compose

Let's verify the Docker network configuration:

#!/bin/bash
# Description: Verify Docker networking setup
# Expected: Docker compose should define appropriate network settings

# Check Docker compose network configuration
rg "networks?:" docker/
# Check if there are any other services using these ports
rg "7000" docker/

Line range hint 47-47: Ensure database persistence in Docker setup

The database path aligns with the unified config structure. However, we should verify:

  1. The database file persists across container restarts
  2. Proper volume mounting in Docker compose

Let's verify the database volume configuration:

#!/bin/bash
# Description: Verify database persistence configuration
# Expected: Docker compose should mount the database directory as a volume

# Check volume configurations
rg -l "mostro.db" docker/
# Check if the config directory is properly mounted
rg "volumes?:" docker/
docker/DOCKER.md (1)

Line range hint 1-80: Documentation is well-structured and comprehensive

The documentation successfully captures the unified Docker Compose setup for Mostro and relay services, providing clear instructions for both combined and independent deployments. The step-by-step instructions are thorough and include all necessary configuration details.

🧰 Tools
🪛 LanguageTool

[grammar] ~7-~7: The usual collocation for “Compose” is “of”, not “from”. Did you mean “Compose of”?
Context: .../www.docker.com/get-started) and Docker Compose from [here](https://docs.docker.com/compose/...

(COMPOSE_FROM_OF)


[misspelling] ~9-~9: Use “an” instead of ‘a’ if the following word starts with a vowel sound, e.g. ‘an article’, ‘an hour’.
Context: ...om/compose/install/). You need to have a LND node running locally. We recommend ...

(EN_A_VS_AN)


[uncategorized] ~15-~15: Loose punctuation mark.
Context: ...s up the following services: - mostro: the MostroP2P service - nostr-relay: ...

(UNLIKELY_OPENING_PUNCTUATION)

Comment on lines +12 to +19
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'
Copy link
Contributor

@coderabbitai coderabbitai bot Nov 10, 2024

Choose a reason for hiding this comment

The 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:

  1. Add a restart policy
  2. Add a health check
  3. Consider using named volumes instead of relative paths

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

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
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'
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:
- 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:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was just moved, not really changed from what it previously was

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jgmontoya, understood. Thank you for the clarification.

Comment on lines +23 to +30
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
Copy link
Contributor

@coderabbitai coderabbitai bot Nov 10, 2024

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:

 docker-up:
 	@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 && \
+	if docker compose ps --quiet | grep -q .; then \
+		echo "Warning: Some services are already running"; \
+	fi && \
 	echo "Starting services" && \
 	docker compose up -d
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
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-up:
@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 && \
if docker compose ps --quiet | grep -q .; then \
echo "Warning: Some services are already running"; \
fi && \
echo "Starting services" && \
docker compose up -d

Copy link
Contributor Author

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 🙄)

Copy link
Contributor

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.

Comment on lines +32 to +39
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
Copy link
Contributor

Choose a reason for hiding this comment

The 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 docker-up and docker-relay-up. Consider extracting this into a separate target.

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

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
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
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 "Starting services" && \
docker compose up -d
docker-relay-up: copy-relay-config
@set -o pipefail; \
cd docker && \
echo "Starting Nostr relay" && \
docker compose up -d nostr-relay

@@ -1,16 +1,16 @@
[lightning]
# path to tls.cert file
lnd_cert_file = '/lnd/alice/tls.cert'
lnd_cert_file = '/config/lnd/tls.cert'
Copy link
Contributor

@coderabbitai coderabbitai bot Nov 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Docker volume configuration needs adjustment for LND certificates

The path /config/lnd/tls.cert in settings.docker.toml is not properly mounted in the Docker setup. While there is a volume mount for ./config:/config, there's no evidence of LND certificate files being copied or mounted in the correct location. This could lead to runtime errors.

  • The compose.yml mounts ./config:/config but doesn't ensure LND directory structure
  • start.sh only handles settings.toml and mostro.db
  • No setup for LND certificates in Dockerfile or start script

Required changes:

  • Create LND directory structure in start.sh
  • Document LND certificate requirements in DOCKER.md
  • Consider adding volume mount specifically for LND certificates
🔗 Analysis chain

Verify Docker volume mounting for LND certificates

The paths have been standardized to use /config/lnd/ directory. This change appears to be part of the Docker compose unification effort.

Let's verify the Docker compose configuration matches these paths:

Also applies to: 5-5

🏁 Scripts executed

The 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

Copy link
Contributor Author

@jgmontoya jgmontoya Nov 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the cert and macaroon files are copied in the docker-build Makefile target, the lnd directory is also created there

Copy link
Contributor

Choose a reason for hiding this comment

The 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 docker-up Makefile target. My apologies for the oversight.


✏️ Learnings added
Learnt from: jgmontoya
PR: MostroP2P/mostro#392
File: docker/settings.docker.toml:3-3
Timestamp: 2024-11-11T11:32:14.343Z
Learning: In the `Makefile`, the `docker-up` target handles copying the LND certificate and macaroon files to the Docker configuration directory.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

#secret_key = "<nostr nsec>"
Copy link
Contributor

@coderabbitai coderabbitai bot Nov 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Security: Avoid committing placeholder secret keys

The uncommented secret_key with a placeholder value <nostr nsec> poses security risks if deployed without proper configuration. This sensitive credential should be managed securely.

Consider these improvements:

  1. Move the secret key to an environment variable:
-#secret_key = "<nostr nsec>"
+secret_key = "${NOSTR_RELAY_SECRET_KEY}"
  1. Update the Docker Compose configuration to handle the secret:
services:
  nostr-relay:
    environment:
      - NOSTR_RELAY_SECRET_KEY=${NOSTR_RELAY_SECRET_KEY}
    # ... other config
  1. Add the environment variable to docker/.env.example:
NOSTR_RELAY_SECRET_KEY=your_secret_key_here

This approach:

  • Prevents sensitive data from being committed to version control
  • Follows Docker best practices for configuration
  • Makes the deployment process more secure and maintainable

Copy link
Contributor Author

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 needed as this is just the template config

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jgmontoya, understood. Thanks for the clarification that this is just the template config.


✏️ Learnings added
Learnt from: jgmontoya
PR: MostroP2P/mostro#392
File: docker/relay_config.toml:217-217
Timestamp: 2024-11-11T11:34:57.336Z
Learning: In the project, including placeholder secret keys in template configuration files like `docker/relay_config.toml` is acceptable, as they are intended for example purposes.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

Copy link
Member

@grunch grunch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK

@grunch grunch merged commit 8542920 into MostroP2P:main Nov 11, 2024
2 checks passed
@jgmontoya jgmontoya deleted the feat/improve-docker-setup branch November 11, 2024 15:32
@coderabbitai coderabbitai bot mentioned this pull request Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants