From b3d7d955ad7be805101cfb2920cbb37f337d8055 Mon Sep 17 00:00:00 2001 From: market_madi Date: Tue, 9 Jan 2024 15:22:47 +0530 Subject: [PATCH 1/7] add docker --- Dockerfile | 30 ++++++++++++++++++++++++++++++ debug.log | 8 ++++---- src/config.rs | 1 + src/util.rs | 19 ++++++++++++------- 4 files changed, 47 insertions(+), 11 deletions(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..29c31a4 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,30 @@ +# 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 + +# 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/debug/civkitd /usr/local/bin/civkitd +COPY --from=builder /usr/src/civkit-node/target/debug/civkit-cli /usr/local/bin/civkit-cli +COPY --from=builder /usr/src/civkit-node/target/debug/civkit-sample /usr/local/bin/civkit-sample + +# Set the default command to run the main binary +CMD ["civkitd"] + diff --git a/debug.log b/debug.log index ce80bf9..24d3973 100644 --- a/debug.log +++ b/debug.log @@ -1,4 +1,4 @@ -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 +09:36:28 [ INFO] Logging initialized. Log file located at: "/home/daven/./civkit-node/debug.log" +09:36:28 [ERROR] This is a test error message +09:36:28 [ WARN] This is a test warning message +09:36:28 [ 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) } From 7e21f2f2f42fea40fa7a4ea763186486832e4de4 Mon Sep 17 00:00:00 2001 From: market_madi Date: Tue, 9 Jan 2024 15:38:27 +0530 Subject: [PATCH 2/7] added commands to readme.md --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) 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 ------- From 1dbb5d31b1bf152a9de901178294866b53d3e870 Mon Sep 17 00:00:00 2001 From: market_madi Date: Wed, 10 Jan 2024 21:50:05 +0530 Subject: [PATCH 3/7] Updated Dockerfile, README, and util.rs for Docker support --- Dockerfile | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 29c31a4..6af8c33 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,7 +11,7 @@ WORKDIR /usr/src/civkit-node COPY . . # Build the application -RUN cargo build +RUN cargo build --release --bin=civkitd # Stage 2: Setup the runtime environment FROM ubuntu:latest @@ -25,6 +25,12 @@ COPY --from=builder /usr/src/civkit-node/target/debug/civkitd /usr/local/bin/civ COPY --from=builder /usr/src/civkit-node/target/debug/civkit-cli /usr/local/bin/civkit-cli COPY --from=builder /usr/src/civkit-node/target/debug/civkit-sample /usr/local/bin/civkit-sample +# Expose ports +EXPOSE 50031 +EXPOSE 9735 +EXPOSE 50021 +EXPOSE 18443 + # Set the default command to run the main binary CMD ["civkitd"] From c4ccf55a0998dc9cd10c44f4c2574f287331f599 Mon Sep 17 00:00:00 2001 From: market_madi Date: Wed, 10 Jan 2024 21:56:03 +0530 Subject: [PATCH 4/7] editing debug.log --- debug.log | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debug.log b/debug.log index 24d3973..86ba81f 100644 --- a/debug.log +++ b/debug.log @@ -1,4 +1,4 @@ -09:36:28 [ INFO] Logging initialized. Log file located at: "/home/daven/./civkit-node/debug.log" +09:36:28 [ INFO] Logging initialized. Log file located at: "civkit-node/debug.log" 09:36:28 [ERROR] This is a test error message 09:36:28 [ WARN] This is a test warning message 09:36:28 [ INFO] This is a test info message From a70193f9070127e61c64e103d86036855d3f9e17 Mon Sep 17 00:00:00 2001 From: market_madi Date: Wed, 10 Jan 2024 22:13:18 +0530 Subject: [PATCH 5/7] Stop tracking debug.log --- debug.log | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 debug.log diff --git a/debug.log b/debug.log deleted file mode 100644 index 86ba81f..0000000 --- a/debug.log +++ /dev/null @@ -1,4 +0,0 @@ -09:36:28 [ INFO] Logging initialized. Log file located at: "civkit-node/debug.log" -09:36:28 [ERROR] This is a test error message -09:36:28 [ WARN] This is a test warning message -09:36:28 [ INFO] This is a test info message From 64b765340d6e4f82c2949e76109f4b1ebf9d11b8 Mon Sep 17 00:00:00 2001 From: market_madi Date: Wed, 10 Jan 2024 22:13:30 +0530 Subject: [PATCH 6/7] Update .gitignore to ignore log files --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 From 82ec174c3bc85747c3f51a838c6f50ec9fd2d4f7 Mon Sep 17 00:00:00 2001 From: market_madi Date: Thu, 11 Jan 2024 08:32:47 +0530 Subject: [PATCH 7/7] copying to release , only compile civkitd --- Dockerfile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6af8c33..6e6bcad 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,9 +21,7 @@ FROM ubuntu:latest 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/debug/civkitd /usr/local/bin/civkitd -COPY --from=builder /usr/src/civkit-node/target/debug/civkit-cli /usr/local/bin/civkit-cli -COPY --from=builder /usr/src/civkit-node/target/debug/civkit-sample /usr/local/bin/civkit-sample +COPY --from=builder /usr/src/civkit-node/target/release/civkitd /usr/local/bin/civkitd # Expose ports EXPOSE 50031