-
Notifications
You must be signed in to change notification settings - Fork 4
feat: config module #141
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
Merged
Merged
feat: config module #141
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| # Rust build artifacts | ||
| target/ | ||
| **/*.rs.bk | ||
| *.pdb | ||
|
|
||
| # Git | ||
| .git/ | ||
| .gitignore | ||
|
|
||
| # Documentation and development files | ||
| *.md | ||
| LICENSE | ||
| SECURITY.md | ||
| CONTRIBUTING.md | ||
|
|
||
| # Development and editor files | ||
| .vscode/ | ||
| .idea/ | ||
| *.swp | ||
| *.swo | ||
| *~ | ||
|
|
||
| # OS files | ||
| .DS_Store | ||
| Thumbs.db | ||
|
|
||
| # Database files (if you don't want to include existing data) | ||
| immo/database/ | ||
|
|
||
| # Docker files (avoid recursion) | ||
| Dockerfile* | ||
| .dockerignore | ||
|
|
||
| # Logs | ||
| *.log | ||
|
|
||
| # Temporary files | ||
| tmp/ | ||
| temp/ |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| name: Cargo Fmt | ||
| permissions: | ||
| contents: read | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
|
|
||
| pull_request: | ||
| branches: | ||
| - main | ||
|
|
||
| jobs: | ||
| format: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v5 | ||
| - uses: dtolnay/rust-toolchain@stable | ||
| - run: cargo fmt --check | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| name: Clippy check | ||
| permissions: | ||
| contents: read | ||
|
|
||
| # Make sure CI fails on all warnings, including Clippy lints | ||
| env: | ||
| RUSTFLAGS: "-Dwarnings" | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
|
|
||
| pull_request: | ||
| branches: | ||
| - main | ||
|
|
||
| jobs: | ||
| clippy_check: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v5 | ||
| - name: Run Clippy | ||
| run: cargo clippy --all-targets --all-features | ||
|
||
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,4 +21,4 @@ Thumbs.db | |
| # For example, if you have a vendor directory for C dependencies: | ||
| # /vendor/ | ||
|
|
||
| nostr-relay | ||
| immo | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| # Multi-stage build for optimal image size and security | ||
| FROM rust:1.83-slim-bullseye AS builder | ||
|
|
||
| # Install build dependencies | ||
| RUN apt-get update && apt-get install -y \ | ||
| pkg-config \ | ||
| libssl-dev \ | ||
| liblmdb-dev \ | ||
| && rm -rf /var/lib/apt/lists/* | ||
|
|
||
| # Create app user for security | ||
| RUN useradd -m -u 1001 appuser | ||
|
|
||
| # Set working directory | ||
| WORKDIR /app | ||
|
|
||
| # Copy manifests first for better layer caching | ||
| COPY Cargo.toml Cargo.lock ./ | ||
|
|
||
| # Create a dummy main.rs to build dependencies | ||
| RUN mkdir src && echo "fn main() {}" > src/main.rs | ||
|
|
||
| # Build dependencies (this layer will be cached unless Cargo files change) | ||
| RUN cargo build --release && rm -rf src target/release/deps/immortal* | ||
|
|
||
| # Copy source code | ||
| COPY src/ ./src/ | ||
|
|
||
| # Build the application | ||
| RUN cargo build --release | ||
|
|
||
| # Runtime stage - use minimal base image | ||
| FROM debian:bullseye-slim AS runtime | ||
|
|
||
| # Install runtime dependencies only | ||
| RUN apt-get update && apt-get install -y \ | ||
| liblmdb0 \ | ||
| libssl1.1 \ | ||
| ca-certificates \ | ||
| && rm -rf /var/lib/apt/lists/* \ | ||
| && apt-get clean | ||
|
|
||
| # Create app user (same UID as builder for consistency) | ||
| RUN useradd -m -u 1001 appuser | ||
|
|
||
| # Create working directory and data directory | ||
| WORKDIR /app | ||
| RUN mkdir -p /app/immo/database && chown -R appuser:appuser /app | ||
|
|
||
| # Copy the built binary from builder stage | ||
| COPY --from=builder /app/target/release/immortal /usr/local/bin/immortal | ||
|
|
||
| # Copy configuration file | ||
| COPY config.toml /app/config.toml | ||
|
|
||
| # Ensure binary is executable and owned by appuser | ||
| RUN chmod +x /usr/local/bin/immortal && chown appuser:appuser /usr/local/bin/immortal /app/config.toml | ||
|
|
||
| # Switch to non-root user | ||
| USER appuser | ||
|
|
||
| # Expose the default port (configurable via config.toml) | ||
| EXPOSE 7777 | ||
|
|
||
| # Health check | ||
| HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ | ||
| CMD curl -f http://localhost:7777/ || exit 1 | ||
|
|
||
| # Use exec form for proper signal handling | ||
| ENTRYPOINT ["/usr/local/bin/immortal"] | ||
|
|
||
| # Add labels for better maintainability | ||
| LABEL maintainer="dezh-tech" \ | ||
| version="0.1.0" \ | ||
| description="Immortal Nostr Relay" \ | ||
| org.opencontainers.image.source="https://github.com/dezh-tech/immortal" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1 @@ | ||
| # Security Policy | ||
|
|
||
| This is a full guide for reporting and behaving with security vulnerabilities in this project. | ||
|
|
||
| ## Reporting a Vulnerability | ||
|
|
||
| If you find any security vulnerability in this project, you can send a full report to [security@dezh.tech](mailto:security@dezh.tech). We will review your report in around 1 week or more and respond to you. | ||
| We MAY consider paying a bounty reward to you using only Bitcoin (On-chain, Lightning, Cashu) depending on the vulnerability security level. By publishing any public writeup or report before a response from us you will not receive any bounty reward. | ||
| After our response to the vulnerability report, you/we can publish a public writeup or report about the vulnerability. | ||
| # TODO |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| port=7777 | ||
| working_dir="immo" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| pub mod types; | ||
|
|
||
| use crate::config::types::Config; | ||
| use std::fs; | ||
|
|
||
| pub fn load(path: &str) -> Result<Config, Box<dyn std::error::Error>> { | ||
| let s = fs::read_to_string(path)?; | ||
| let cfg: Config = toml::from_str(&s)?; | ||
| Ok(cfg) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| use serde::Deserialize; | ||
|
|
||
| #[derive(Debug, Deserialize)] | ||
| pub struct Config { | ||
| pub working_dir: String, | ||
| pub port: u16, | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.