diff --git a/.gitignore b/.gitignore index c4039b3..e3076f2 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ # will have compiled files and executables /target/ Cargo.lock -debug.log \ No newline at end of file +debug.log +*.log \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..6e6bcad --- /dev/null +++ b/Dockerfile @@ -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 + +# Expose ports +EXPOSE 50031 +EXPOSE 9735 +EXPOSE 50021 +EXPOSE 18443 + +# Set the default command to run the main binary +CMD ["civkitd"] + diff --git a/README.md b/README.md index 8f5bb6e..b3b802a 100644 --- a/README.md +++ b/README.md @@ -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 ------- diff --git a/debug.log b/debug.log deleted file mode 100644 index ce80bf9..0000000 --- a/debug.log +++ /dev/null @@ -1,4 +0,0 @@ -10:25:07 [ INFO] Logging initialized. Log file located at: "/home/daven/./civkit-node/debug.log" -10:25:07 [ERROR] This is a test error message -10:25:07 [ WARN] This is a test warning message -10:25:07 [ INFO] This is a test info message diff --git a/src/config.rs b/src/config.rs index a8660af..78a5d51 100644 --- a/src/config.rs +++ b/src/config.rs @@ -103,3 +103,4 @@ impl Default for Config { } } } + diff --git a/src/util.rs b/src/util.rs index 38f9f97..425729f 100644 --- a/src/util.rs +++ b/src/util.rs @@ -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> { - +pub fn init_logger(data_dir: &PathBuf, log_level: &str) -> Result<(), Box> { 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 { @@ -48,14 +46,21 @@ pub fn init_logger(data_dir: &PathBuf, log_level: &str ) -> Result<(), Box 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> = 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) }