Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
# will have compiled files and executables
/target/
Cargo.lock
debug.log
debug.log
*.log
34 changes: 34 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Stage 1: Building the binary
FROM rust:latest as builder

# Install protobuf compiler
RUN apt-get update && apt-get install -y protobuf-compiler

# Set the working directory in the Docker image
WORKDIR /usr/src/civkit-node

# Copy the source code into the Docker image
COPY . .

# Build the application
RUN cargo build --release --bin=civkitd

# Stage 2: Setup the runtime environment
FROM ubuntu:latest

# Install runtime dependencies
# Including CA certificates
RUN apt-get update && apt-get install -y libsqlite3-0 libssl-dev ca-certificates && rm -rf /var/lib/apt/lists/*

# Copy the binaries from the builder stage
COPY --from=builder /usr/src/civkit-node/target/release/civkitd /usr/local/bin/civkitd

Copy link

Choose a reason for hiding this comment

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

we are compiling only the "civkitd" binary as well, so we should only copy that

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 left them thinking they could be useful for debugging / development purposes. i think we should do what you propose, keep it lean.

# Expose ports
EXPOSE 50031
EXPOSE 9735
EXPOSE 50021
EXPOSE 18443

# Set the default command to run the main binary
CMD ["civkitd"]

7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ cargo build
cd target/debug
#run commands above like ./civkitd
```
Docker Build
------------

```
docker build -t civkit-node .
docker run --rm civkit-node
```

Tagline
-------
Expand Down
4 changes: 0 additions & 4 deletions debug.log

This file was deleted.

1 change: 1 addition & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,4 @@ impl Default for Config {
}
}
}

19 changes: 12 additions & 7 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,11 @@ pub fn get_default_data_dir() -> PathBuf {
platform_path
}

// Function to initialize the logger with the given data directory
pub fn init_logger(data_dir: &PathBuf, log_level: &str ) -> Result<(), Box<dyn Error + Send + Sync>> {

pub fn init_logger(data_dir: &PathBuf, log_level: &str) -> Result<(), Box<dyn Error + Send + Sync>> {
if !data_dir.exists() {
fs::create_dir_all(data_dir)?;
}

let log_file = data_dir.join("debug.log");
let config = ConfigBuilder::new().build();
let level_filter = match log_level {
Expand All @@ -48,14 +46,21 @@ pub fn init_logger(data_dir: &PathBuf, log_level: &str ) -> Result<(), Box<dyn E
"info" => LevelFilter::Info,
"debug" => LevelFilter::Debug,
"trace" => LevelFilter::Trace,
_ => panic!("Invalid log level in config"),
_ => return Err("Invalid log level in config".into()),
};

let log_writer = File::create(&log_file)?;
let file_logger = WriteLogger::new(level_filter, config.clone(), log_writer);
let term_logger = TermLogger::new(level_filter, config, TerminalMode::Mixed).unwrap();

CombinedLogger::init(vec![file_logger, term_logger])
let mut loggers: Vec<Box<dyn simplelog::SharedLogger>> = vec![file_logger];

// Attempt to initialize terminal logger
match TermLogger::new(level_filter, config, TerminalMode::Mixed) {
Some(term_logger) => loggers.push(term_logger),
None => eprintln!("Warning: Terminal logging is not available."),
}

CombinedLogger::init(loggers)
.map_err(|err| Box::new(err) as Box<dyn Error + Send + Sync>)
}

Expand Down