Skip to content

Commit 682b8d5

Browse files
authored
Improve tag filtering functions, general cleanup, package updates. (#8)
* Add latest version display for workloads and implement next_run function for scheduler * Update GitHub Actions workflow for dev branch and improve Docker image build process * Add `/site/` directory to `.gitignore` for exclusion * Refactor scheduler service by removing redundant next_run function * Set max_tags to 1500 to ensure all tags return. Handle multiple newer versions to ensure only latest version is returned. Ensure include and exclude filters can be applied.
1 parent a86e4c7 commit 682b8d5

File tree

10 files changed

+84
-31
lines changed

10 files changed

+84
-31
lines changed

.github/workflows/dev-build.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Build and Push Slackwatch Image
2+
3+
on:
4+
push:
5+
branches:
6+
- dev
7+
8+
paths:
9+
- 'src/**'
10+
- 'Dockerfile'
11+
- 'assets/**'
12+
13+
concurrency:
14+
group: "slackwatch"
15+
cancel-in-progress: true
16+
17+
jobs:
18+
build-and-push:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Check out the code
22+
uses: actions/checkout@v2
23+
24+
- name: Set up Docker Buildx
25+
uses: docker/setup-buildx-action@v1
26+
27+
- name: Log in to GitHub Container Registry
28+
run: docker login ghcr.io -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }}
29+
30+
- name: Build and push
31+
uses: docker/build-push-action@v2
32+
with:
33+
context: ./
34+
file: ./Dockerfile
35+
push: true
36+
tags: ghcr.io/slackspace-io/slackwatch:dev,ghcr.io/slackspace-io/slackwatch:${{ github.sha }}

.github/workflows/slackwatch.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ on:
77

88
paths:
99
- 'src/**'
10-
- '.github/workflows/slackwatch.yml'
1110
- 'Dockerfile'
1211
- 'assets/**'
1312

@@ -34,4 +33,4 @@ jobs:
3433
context: ./
3534
file: ./Dockerfile
3635
push: true
37-
tags: ghcr.io/slackspace-io/slackwatch:dev,ghcr.io/slackspace-io/slackwatch:${{ github.sha }}
36+
tags: ghcr.io/slackspace-io/slackwatch:preview,ghcr.io/slackspace-io/slackwatch:${{ github.sha }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,4 @@ docker-compose*.yml
4040
#mdbook
4141
book/
4242
.site/
43+
/site/

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ edition = "2021"
77
[dependencies]
88
serde = { version = "1.0.197", features = ["derive"] }
99
dotenv = { version = "0.15.0"}
10-
anyhow = { version = "1.0.81", features = ["std"] }
10+
anyhow = { version = "1.0.82", features = ["std"] }
1111
env_logger = { version = "0.11.3" }
1212
tokio = { version = "1.37.0", features = ["full"], optional = true }
1313
warp = { version = "0.3.7", optional = true }

assets/style.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,6 @@
6767
order: 1!important;
6868
}
6969

70-
.workload-version, .workload-image, .workload-namespace, .workload-last-scanned {
70+
.workload-version, .workload-image, .workload-namespace, .workload-last-scanned, .workload-latest-version {
7171
margin-top: 10px;
7272
}

src/repocheck/repocheck.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ pub async fn get_tags_for_image(image: &str) -> Result<Vec<String>, Box<dyn std:
2626
let auth = RegistryAuth::Anonymous;
2727
let config = ClientConfig::default();
2828
let mut client = Client::new(config);
29+
let max_tags = Some(1500);
2930
log::info!("Fetching tags for image: {:?}", reference.tag());
3031
let tags = client
31-
.list_tags(&reference, &auth, None, reference.tag())
32+
.list_tags(&reference, &auth, max_tags, reference.tag())
3233
.await?;
3334
log::info!("Available tags for {}: {:?}", reference, tags.tags);
3435
//length of tags

src/services/scheduler.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,13 @@ use std::str::FromStr;
66
use std::time::Duration;
77
use tokio::time::{sleep_until, Instant as TokioInstant};
88

9+
10+
911
#[cfg(feature = "server")]
1012
pub async fn scheduler(schedule: &Schedule) {
11-
// Example cron schedule: Every minute
1213
log::info!("Scheduler started");
13-
//let schedule_str = "0 * * * * *"; // Adjust the cron expression as needed
14-
//let schedule = Schedule::from_str(schedule_str).expect("Failed to parse cron expression");
1514
println!("Cron schedule: {}", schedule);
1615
log::info!("Cron schedule: {}", schedule);
17-
// Find the next scheduled time
18-
//print next 5 scheduled times
1916
let mut i = 0;
2017
for datetime in schedule.upcoming(chrono::Utc) {
2118
if i < 5 {

src/services/workloads.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ pub async fn parse_tags(workload: &Workload) -> Result<Workload, Box<dyn std::er
117117
.collect();
118118

119119
log::info!("Filtered tags: {:?}", tags);
120-
} else if let Some(exclude_pattern_str) = &workload.exclude_pattern {
120+
}
121+
if let Some(exclude_pattern_str) = &workload.exclude_pattern {
121122
log::info!("Exclude pattern defined, using only exclude");
122123
log::info!("Exclude pattern: {}", exclude_pattern_str);
123124

@@ -145,8 +146,14 @@ pub async fn parse_tags(workload: &Workload) -> Result<Workload, Box<dyn std::er
145146
if tag_version > current_version {
146147
// tag_version is greater than current_version
147148
// Do something with this tag
148-
println!("Tag {} is newer than current version", tag);
149-
latest_version = tag.clone();
149+
if latest_version.is_empty() {
150+
log::info!("latest_version is empty - setting to tag {}", tag);
151+
latest_version = tag.clone();
152+
} else if tag_version > Version::parse(&strip_tag_lettings(&latest_version)).unwrap() {
153+
log::info!("Tag {} is newer than {} current latest_version updating", tag, latest_version);
154+
latest_version = tag.clone();
155+
}
156+
150157
}
151158
} else {
152159
// Handle the case where the tag is not a valid SemVer format

src/site/app.rs

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ async fn get_all_workloads() -> Result<String, ServerFnError> {
2929
use crate::database::client::return_all_workloads;
3030
let workloads = return_all_workloads();
3131
Ok(workloads.unwrap().iter().map(|w| w.name.clone()).collect::<Vec<String>>().join(", "))
32-
33-
// Ok(workloads.unwrap().iter().map(|w| w.name.clone()).collect::<Vec<String>>().join(", "))
3432
}
3533

3634

@@ -67,6 +65,31 @@ fn Home() -> Element {
6765
}
6866
}
6967

68+
#[component]
69+
fn DebugWorkloadCard(props: WorkloadCardProps) -> Element {
70+
rsx! {
71+
div {
72+
class: if props.workload.update_available == models::models::UpdateStatus::Available {
73+
"workload-card-update-available"
74+
} else {
75+
"workload-card"
76+
},
77+
div { class: "workload-name", "{props.workload.name}" },
78+
div { class: "workload-
79+
namespace", "Namespace: {props.workload.namespace}" },
80+
div { class: "workload-version", "Current Tag {props.workload.current_version}" },
81+
div { class: "workload-image", "Image: {props.workload.image}" },
82+
div { class: "workload-last-scanned", "Last Scanned: {props.workload.last_scanned}" },
83+
if props.workload.update_available == models::models::UpdateStatus::Available {
84+
div { class: "workload-latest-version", "Latest Version Available: {props.workload.latest_version}" }
85+
br {}
86+
}
87+
}
88+
}
89+
}
90+
91+
92+
7093
#[component]
7194
fn WorkloadCard(props: WorkloadCardProps) -> Element {
7295
let data = use_signal(|| {props.workload.clone()});
@@ -91,6 +114,8 @@ fn WorkloadCard(props: WorkloadCardProps) -> Element {
91114
div { class: "workload-image", "Image: {props.workload.image}" },
92115
div { class: "workload-last-scanned", "Last Scanned: {props.workload.last_scanned}" },
93116
if props.workload.update_available == models::models::UpdateStatus::Available {
117+
div { class: "workload-latest-version", "Latest Version Available: {props.workload.latest_version}" }
118+
br {}
94119
button { onclick: move |_| {
95120
async move {
96121
if let Ok(_) = upgrade_workload(data()).await {
@@ -106,20 +131,6 @@ fn WorkloadCard(props: WorkloadCardProps) -> Element {
106131
pub fn App() -> Element {
107132
println!("App started");
108133
rsx! { Router::<Route> {} }
109-
//rsx!{
110-
// div {
111-
// "App"
112-
// }
113-
//}
114-
//rsx! { All {} }
115-
// rsx! {
116-
// "server data is {workloads():?}"
117-
// div {}
118-
// "server data is {all():?}"
119-
// div { {all().map(|w| rsx! { div {"{w:?}"}})}}
120-
//
121-
//
122-
//}
123134
}
124135

125136

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

0 commit comments

Comments
 (0)