diff --git a/.github/workflows/dev-build.yaml b/.github/workflows/dev-build.yaml index e3a3daf..07efe9c 100644 --- a/.github/workflows/dev-build.yaml +++ b/.github/workflows/dev-build.yaml @@ -1,4 +1,4 @@ -name: Build and Push Slackwatch Image +name: Build and Push Dev Branch on: push: @@ -9,6 +9,7 @@ on: - 'src/**' - 'Dockerfile' - 'assets/**' + - '.github/workflows/dev-build.yaml' concurrency: group: "slackwatch" @@ -19,18 +20,20 @@ jobs: runs-on: ubuntu-latest steps: - name: Check out the code - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 + uses: docker/setup-buildx-action@v3 - name: Log in to GitHub Container Registry run: docker login ghcr.io -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }} - name: Build and push - uses: docker/build-push-action@v2 + uses: docker/build-push-action@v5 with: context: ./ file: ./Dockerfile push: true tags: ghcr.io/slackspace-io/slackwatch:dev,ghcr.io/slackspace-io/slackwatch:${{ github.sha }} + cache-from: type=registry,ref=ghcr.io/slackspace-io/slackwatch:build-cache + cache-to: type=registry,ref=ghcr.io/slackspace-io/slackwatch:build-cache,mode=max diff --git a/.github/workflows/slackwatch.yml b/.github/workflows/slackwatch.yml index 6b1fa2c..31b84d0 100644 --- a/.github/workflows/slackwatch.yml +++ b/.github/workflows/slackwatch.yml @@ -34,3 +34,5 @@ jobs: file: ./Dockerfile push: true tags: ghcr.io/slackspace-io/slackwatch:preview,ghcr.io/slackspace-io/slackwatch:${{ github.sha }} + cache-from: type=registry,ref=ghcr.io/slackspace-io/slackwatch:pr-build-cache + cache-to: type=registry,ref=ghcr.io/slackspace-io/slackwatch:pr-build-cache,mode=max diff --git a/Dockerfile b/Dockerfile index 22ea970..d6437c9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,14 @@ FROM rust:1.77.1 as builder WORKDIR /app -COPY . . RUN cargo install dioxus-cli@0.5.0 +COPY Cargo.toml Cargo.lock ./ +COPY src ./src RUN dx build --platform fullstack --release FROM rust:1.77.1 #RUN apt-get update && rm -rf /var/lib/apt/lists/* #Copy all files from the builder WORKDIR /app -COPY --from=builder /app/slackwatch /app/slackwatch +COPY --from=builder /app/target/release/slackwatch /app/slackwatch EXPOSE 8080 CMD ["/app/slackwatch/slackwatch"] diff --git a/src/main.rs b/src/main.rs index 5615567..5061b41 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,10 +16,6 @@ use dioxus::prelude::*; use log::info; use crate::config::Settings; -//#[cfg(feature = "server")] -//use k8s_openapi::merge_strategies::list::set; -//use std::env; -// mod config; mod database; mod gitops; @@ -35,22 +31,17 @@ mod site; #[tokio::main] async fn main() { println!("Hello, world!"); - //Logging and env variables env::set_var("RUST_LOG", "info"); env_logger::init(); - // dotenv::dotenv().ok(); - // Load Configurations let settings = Settings::new().unwrap_or_else(|err| { log::error!("Failed to load settings: {}", err); panic!("Failed to load settings: {}", err); }); log::info!("Starting up"); log::info!("Loading configuration {:?}", settings); - //create table if not exist #[cfg(feature = "server")] use crate::database::client::create_table_if_not_exist; create_table_if_not_exist().unwrap(); - //working tokio stuff tokio::task::spawn(services::scheduler::run_scheduler(settings.clone())); let mut config = dioxus::fullstack::Config::new(); @@ -59,12 +50,9 @@ async fn main() { config = config.addr(std::net::SocketAddr::from(([0, 0, 0, 0], 8080))); } -// Launch the app with the custom menu let site = std::thread::spawn(|| LaunchBuilder::new().with_cfg(config).launch(App)); - //let site = std::thread::spawn(|| launch(App)); log::info!("Started logger"); println!("Started print"); - //let _ = web::exweb::site(); site.join().unwrap(); } diff --git a/src/oldc.rs b/src/oldc.rs deleted file mode 100644 index b3fdb54..0000000 --- a/src/oldc.rs +++ /dev/null @@ -1,60 +0,0 @@ -//// src/config.rs -//use serde::{Deserialize, Serialize}; -//use std::env; -//use std::path::PathBuf; -// -//#[derive(Debug, Serialize, Deserialize)] -//pub struct AppConfig { -// pub database_path: PathBuf, -// pub refresh_schedule: String, -// pub refresh_interval: u64, -// pub k8s_config_path: PathBuf, -//} -// -//impl AppConfig { -// pub fn new() -> anyhow::Result { -// dotenv::dotenv().ok(); // Load .env file if it exists -// log::info!("Loading configuration"); -// -// let database_path = env::var("DATABASE_PATH") -// .unwrap_or_else(|_| "./data.db".into()) -// .into(); -// -// let refresh_schedule = env::var("REFRESH_SCHEDULE").unwrap_or_else(|_| "0 0 * * *".into()); // Default to daily at midnight -// -// Ok(AppConfig { -// k8s_config_path: env::var("K8S_CONFIG_PATH") -// .unwrap_or_else(|_| "~/.kube/config".into()) -// .into(), -// database_path, -// refresh_schedule, -// refresh_interval: env::var("REFRESH_INTERVAL") -// .unwrap_or_else(|_| "86400".into()) -// .parse::()?, -// }) -// } -//} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_app_config_new() { - // Setup - let _ = dotenv::dotenv(); // Ensure .env is loaded for this test if it exists - - // This test assumes specific values are set in .env or defaults are acceptable - let expected_db_path: PathBuf = env::var("DATABASE_PATH") - .unwrap_or_else(|_| "./data.db".into()) - .into(); - let expected_schedule = env::var("REFRESH_SCHEDULE").unwrap_or_else(|_| "0 0 * * *".into()); - - // Exercise - let config = AppConfig::new().expect("Failed to create AppConfig"); - - // Verify - assert_eq!(config.database_path, expected_db_path); - assert_eq!(config.refresh_schedule, expected_schedule); - } -}