Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve tag filtering functions, general cleanup, package updates. #8

Merged
merged 5 commits into from
Apr 14, 2024
Merged
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
36 changes: 36 additions & 0 deletions .github/workflows/dev-build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Build and Push Slackwatch Image

on:
push:
branches:
- dev

paths:
- 'src/**'
- 'Dockerfile'
- 'assets/**'

concurrency:
group: "slackwatch"
cancel-in-progress: true

jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Check out the code
uses: actions/checkout@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- 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
with:
context: ./
file: ./Dockerfile
push: true
tags: ghcr.io/slackspace-io/slackwatch:dev,ghcr.io/slackspace-io/slackwatch:${{ github.sha }}
3 changes: 1 addition & 2 deletions .github/workflows/slackwatch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ on:

paths:
- 'src/**'
- '.github/workflows/slackwatch.yml'
- 'Dockerfile'
- 'assets/**'

Expand All @@ -34,4 +33,4 @@ jobs:
context: ./
file: ./Dockerfile
push: true
tags: ghcr.io/slackspace-io/slackwatch:dev,ghcr.io/slackspace-io/slackwatch:${{ github.sha }}
tags: ghcr.io/slackspace-io/slackwatch:preview,ghcr.io/slackspace-io/slackwatch:${{ github.sha }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ docker-compose*.yml
#mdbook
book/
.site/
/site/
4 changes: 2 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2021"
[dependencies]
serde = { version = "1.0.197", features = ["derive"] }
dotenv = { version = "0.15.0"}
anyhow = { version = "1.0.81", features = ["std"] }
anyhow = { version = "1.0.82", features = ["std"] }
env_logger = { version = "0.11.3" }
tokio = { version = "1.37.0", features = ["full"], optional = true }
warp = { version = "0.3.7", optional = true }
Expand Down
2 changes: 1 addition & 1 deletion assets/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,6 @@
order: 1!important;
}

.workload-version, .workload-image, .workload-namespace, .workload-last-scanned {
.workload-version, .workload-image, .workload-namespace, .workload-last-scanned, .workload-latest-version {
margin-top: 10px;
}
3 changes: 2 additions & 1 deletion src/repocheck/repocheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ pub async fn get_tags_for_image(image: &str) -> Result<Vec<String>, Box<dyn std:
let auth = RegistryAuth::Anonymous;
let config = ClientConfig::default();
let mut client = Client::new(config);
let max_tags = Some(1500);
log::info!("Fetching tags for image: {:?}", reference.tag());
let tags = client
.list_tags(&reference, &auth, None, reference.tag())
.list_tags(&reference, &auth, max_tags, reference.tag())
.await?;
log::info!("Available tags for {}: {:?}", reference, tags.tags);
//length of tags
Expand Down
7 changes: 2 additions & 5 deletions src/services/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@ use std::str::FromStr;
use std::time::Duration;
use tokio::time::{sleep_until, Instant as TokioInstant};



#[cfg(feature = "server")]
pub async fn scheduler(schedule: &Schedule) {
// Example cron schedule: Every minute
log::info!("Scheduler started");
//let schedule_str = "0 * * * * *"; // Adjust the cron expression as needed
//let schedule = Schedule::from_str(schedule_str).expect("Failed to parse cron expression");
println!("Cron schedule: {}", schedule);
log::info!("Cron schedule: {}", schedule);
// Find the next scheduled time
//print next 5 scheduled times
let mut i = 0;
for datetime in schedule.upcoming(chrono::Utc) {
if i < 5 {
Expand Down
13 changes: 10 additions & 3 deletions src/services/workloads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ pub async fn parse_tags(workload: &Workload) -> Result<Workload, Box<dyn std::er
.collect();

log::info!("Filtered tags: {:?}", tags);
} else if let Some(exclude_pattern_str) = &workload.exclude_pattern {
}
if let Some(exclude_pattern_str) = &workload.exclude_pattern {
log::info!("Exclude pattern defined, using only exclude");
log::info!("Exclude pattern: {}", exclude_pattern_str);

Expand Down Expand Up @@ -145,8 +146,14 @@ pub async fn parse_tags(workload: &Workload) -> Result<Workload, Box<dyn std::er
if tag_version > current_version {
// tag_version is greater than current_version
// Do something with this tag
println!("Tag {} is newer than current version", tag);
latest_version = tag.clone();
if latest_version.is_empty() {
log::info!("latest_version is empty - setting to tag {}", tag);
latest_version = tag.clone();
} else if tag_version > Version::parse(&strip_tag_lettings(&latest_version)).unwrap() {
log::info!("Tag {} is newer than {} current latest_version updating", tag, latest_version);
latest_version = tag.clone();
}

}
} else {
// Handle the case where the tag is not a valid SemVer format
Expand Down
44 changes: 28 additions & 16 deletions src/site/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ async fn get_all_workloads() -> Result<String, ServerFnError> {
use crate::database::client::return_all_workloads;
let workloads = return_all_workloads();
Ok(workloads.unwrap().iter().map(|w| w.name.clone()).collect::<Vec<String>>().join(", "))

// Ok(workloads.unwrap().iter().map(|w| w.name.clone()).collect::<Vec<String>>().join(", "))
}


Expand Down Expand Up @@ -67,6 +65,31 @@ fn Home() -> Element {
}
}

#[component]
fn DebugWorkloadCard(props: WorkloadCardProps) -> Element {
rsx! {
div {
class: if props.workload.update_available == models::models::UpdateStatus::Available {
"workload-card-update-available"
} else {
"workload-card"
},
div { class: "workload-name", "{props.workload.name}" },
div { class: "workload-
namespace", "Namespace: {props.workload.namespace}" },
div { class: "workload-version", "Current Tag {props.workload.current_version}" },
div { class: "workload-image", "Image: {props.workload.image}" },
div { class: "workload-last-scanned", "Last Scanned: {props.workload.last_scanned}" },
if props.workload.update_available == models::models::UpdateStatus::Available {
div { class: "workload-latest-version", "Latest Version Available: {props.workload.latest_version}" }
br {}
}
}
}
}



#[component]
fn WorkloadCard(props: WorkloadCardProps) -> Element {
let data = use_signal(|| {props.workload.clone()});
Expand All @@ -91,6 +114,8 @@ fn WorkloadCard(props: WorkloadCardProps) -> Element {
div { class: "workload-image", "Image: {props.workload.image}" },
div { class: "workload-last-scanned", "Last Scanned: {props.workload.last_scanned}" },
if props.workload.update_available == models::models::UpdateStatus::Available {
div { class: "workload-latest-version", "Latest Version Available: {props.workload.latest_version}" }
br {}
button { onclick: move |_| {
async move {
if let Ok(_) = upgrade_workload(data()).await {
Expand All @@ -106,20 +131,6 @@ fn WorkloadCard(props: WorkloadCardProps) -> Element {
pub fn App() -> Element {
println!("App started");
rsx! { Router::<Route> {} }
//rsx!{
// div {
// "App"
// }
//}
//rsx! { All {} }
// rsx! {
// "server data is {workloads():?}"
// div {}
// "server data is {all():?}"
// div { {all().map(|w| rsx! { div {"{w:?}"}})}}
//
//
//}
}


Expand Down Expand Up @@ -170,6 +181,7 @@ fn All() -> Element {
div { class: "workload-version", "Current Tag {w.current_version}" },
div { class: "workload-image", "Image: {w.image}" },
div { class: "workload-last-scanned", "Last Scanned: {w.last_scanned}" },
div { class: "workload-name", "{w.latest_version}" },
if w.update_available == models::models::UpdateStatus::Available {
div { class: "workload-update-available", "Update Available" }
}
Expand Down
Loading