Skip to content

Commit

Permalink
Merge pull request #50 from lexara-prime-ai/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
irfanghat authored Jun 11, 2024
2 parents b9d41b6 + ae86213 commit 5a6da3c
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 4 deletions.
11 changes: 9 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
workspace = { members = ["wspr_cdk_server", "python_wrapper"] }
workspace = { members = [
"wspr_cdk_server",
"python_wrapper",
"windows_container",
] }
[package]
name = "wspr_cdk"
version = "0.0.12"
Expand Down
14 changes: 13 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,16 @@ EXPOSE 8000
# sudo docker run -it -p 8000:8000 \
# -e GOOGLE_APPLICATION_CREDENTIALS=/service_account.json \
# -v ./service_account.json:/wspr_cdk/service_account.json \
# test python ./hyper/hyper/server.py --interval 10
# test python ./hyper/hyper/server.py --interval 10


# Building & Running [standalone] modules:
#
# cargo build --release --workspace -> Builds all <workspace> modules.
# cargo build --release -p windows_container
# cargo build --release -p wspr_cdk_server
# cargo build --release -p wspr_cdk

# cargo run --release --manifest-path ./wspr_cdk_server/Cargo.toml
# cargo run --release --manifest-path wspr_cdk/Cargo.toml
# cargo run --release --manifest-path windows_container/Cargo.toml
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
# WSPR CDK

## Project Directory Structure(Cargo)

```sh
wspr_cdk
├── Cargo.toml
├── wspr_cdk_server
│ ├── Cargo.toml
│ └── src
│ └── main.rs
├── python_wrapper
│ ├── Cargo.toml
│ └── src
│ └── lib.rs
└── windows_container
├── Cargo.toml
└── src
└── main.rs
```

`wspr_cdk` provides an abstraction for accessing and analyzing **WSPR** (_Weak Signal Propagation Reporter_) real-time spot data. This crate allows you to perform queries and fetch data from the WSPR database with ease.

## Prerequisites
Expand Down
9 changes: 9 additions & 0 deletions windows_container/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "windows_container"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
regex = "1.10.5"
76 changes: 76 additions & 0 deletions windows_container/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#![allow(unused_imports)]

// Run the <windows_container> module independently:
// cargo run -p windows_container

// Build the <windows_container> module independently:
// cargo build -p windows_container

// Command:
// docker run -it --rm -p 8006:8006 --device=/dev/kvm --cap-add NET_ADMIN --stop-timeout 120 --name windows dockurr/windows

use regex::Regex;
use std::env;
use std::fs;
use std::path::Path;
use std::process::{exit, Command};

fn main() {
if !check_os() {
println!("This script only supports Linux operating systems.");
exit(1);
}

if !check_kvm_support() {
println!("KVM is not supported on this system.");
exit(1);
}

let image_name = "dockurr/windows";

if !validate_input(image_name) {
println!("Invalid Docker image name.");
exit(1);
}

run_docker_command(image_name);
}

fn check_os() -> bool {
env::consts::OS == "linux"
}

fn check_kvm_support() -> bool {
Path::new("/dev/kvm").exists()
}

fn validate_input(image_name: &str) -> bool {
let re = Regex::new(r"^[a-zA-Z0-9\-_/]+$").unwrap();
re.is_match(image_name)
}

fn run_docker_command(image_name: &str) {
let status = Command::new("docker")
.args([
"run",
"-it",
"--rm",
"-p",
"8006:8006",
"--device=/dev/kvm",
"--cap-add",
"NET_ADMIN",
"--stop-timeout",
"120",
"--name",
"windows",
image_name,
])
.status()
.expect("Failed to execute Docker command");

if !status.success() {
println!("Error running Docker command: {:?}", status);
exit(1);
}
}

0 comments on commit 5a6da3c

Please sign in to comment.