bump v0.4.2

This commit is contained in:
DataHearth 2022-03-06 04:29:22 +01:00
parent 296a856a9c
commit 041072bf0a
No known key found for this signature in database
GPG Key ID: E88FD356ACC5F3C4
6 changed files with 40 additions and 21 deletions

2
Cargo.lock generated
View File

@ -76,7 +76,7 @@ dependencies = [
[[package]] [[package]]
name = "clear-docker-images" name = "clear-docker-images"
version = "0.4.1" version = "0.4.2"
dependencies = [ dependencies = [
"chrono", "chrono",
"clap", "clap",

View File

@ -1,6 +1,6 @@
[package] [package]
name = "clear-docker-images" name = "clear-docker-images"
version = "0.4.1" version = "0.4.2"
edition = "2021" edition = "2021"
authors = ["Antoine <DataHearth> Langlois"] authors = ["Antoine <DataHearth> Langlois"]
description = "small binary to clean up docker images (mostly in CI)" description = "small binary to clean up docker images (mostly in CI)"

View File

@ -10,9 +10,16 @@ WORKDIR /clear-docker-images
build-linux: build-linux:
COPY . . COPY . .
RUN rustup target add x86_64-unknown-linux-gnu
RUN cargo build --release --target x86_64-unknown-linux-gnu RUN cargo build --release --target x86_64-unknown-linux-gnu
SAVE ARTIFACT target/x86_64-unknown-linux-gnu /x86_64-unknown-linux-gnu AS LOCAL target/x86_64-unknown-linux-gnu SAVE ARTIFACT target/x86_64-unknown-linux-gnu /x86_64-unknown-linux-gnu AS LOCAL target/x86_64-unknown-linux-gnu
build-musl:
COPY . .
RUN rustup target add x86_64-unknown-linux-musl
RUN cargo build --release --target x86_64-unknown-linux-musl
SAVE ARTIFACT target/x86_64-unknown-linux-musl /x86_64-unknown-linux-musl AS LOCAL target/x86_64-unknown-linux-musl
build-images: build-images:
FROM docker:20.10.12-dind-alpine3.15 FROM docker:20.10.12-dind-alpine3.15
@ -20,7 +27,7 @@ build-images:
LABEL repository="https://github.com/DataHearth/clear-docker-images" LABEL repository="https://github.com/DataHearth/clear-docker-images"
LABEL org.opencontainers.image.source=&quot;https://github.com/DataHearth/clear-docker-images&quot; LABEL org.opencontainers.image.source=&quot;https://github.com/DataHearth/clear-docker-images&quot;
COPY +build-linux/x86_64-unknown-linux-gnu /usr/local/bin/clear-docker-images COPY +build-musl/x86_64-unknown-linux-musl/release/clear-docker-images /usr/local/bin/clear-docker-images
VOLUME ["/var/run/docker.sock"] VOLUME ["/var/run/docker.sock"]

View File

@ -1,4 +1,4 @@
VERSION := 0.4.1 VERSION := 0.4.2
.PHONY: bump-version .PHONY: bump-version
bump-version: bump-version:
@ -7,6 +7,7 @@ bump-version:
@sd "version = \"${VERSION}\"" "version = \"${NEW_VERSION}\"" Cargo.toml @sd "version = \"${VERSION}\"" "version = \"${NEW_VERSION}\"" Cargo.toml
@sd "VERSION=${VERSION}" "VERSION=${NEW_VERSION}" .env @sd "VERSION=${VERSION}" "VERSION=${NEW_VERSION}" .env
@sd "VERSION := ${VERSION}" "VERSION := ${NEW_VERSION}" Makefile @sd "VERSION := ${VERSION}" "VERSION := ${NEW_VERSION}" Makefile
@cargo update --package=clear-docker-images
@git add . @git add .
@git commit -m "bump v${NEW_VERSION}" @git commit -m "bump v${NEW_VERSION}"
@git tag -m "bump v${NEW_VERSION}" v${NEW_VERSION} @git tag -m "bump v${NEW_VERSION}" v${NEW_VERSION}

View File

@ -49,7 +49,7 @@ where
if size.contains("KB") { if size.contains("KB") {
size.replace("KB", "") size.replace("KB", "")
.parse::<f32>() .parse::<f32>()
.map(|s| s / 1000 as f32) .map(|s| s / 1000.0)
.map_err(serde::de::Error::custom) .map_err(serde::de::Error::custom)
} else if size.contains("MB") { } else if size.contains("MB") {
size.replace("MB", "") size.replace("MB", "")
@ -58,7 +58,7 @@ where
} else if size.contains("GB") { } else if size.contains("GB") {
size.replace("GB", "") size.replace("GB", "")
.parse::<f32>() .parse::<f32>()
.map(|s| s * 1000 as f32) .map(|s| s * 1000.0)
.map_err(serde::de::Error::custom) .map_err(serde::de::Error::custom)
} else { } else {
Err(serde::de::Error::custom(format!( Err(serde::de::Error::custom(format!(
@ -131,13 +131,10 @@ fn parse_imgs(repository: Option<String>) -> Vec<String> {
error!("failed to parse docker output: {}", e); error!("failed to parse docker output: {}", e);
exit(1); exit(1);
}); });
let mut images: Vec<String> = output.lines().map(|s| s.to_string()).collect(); let images: Vec<String> = output.lines().map(|s| s.to_string()).collect();
// * remove last empty line
images.remove(images.len() - 1);
if images.len() == 0 { if images.len() == 0 {
warn!("No images found for current timestamp and/or repository"); warn!("No images found for current timestamp and/or repository");
exit(1);
} }
return images; return images;

View File

@ -17,12 +17,11 @@ const TWO_DAYS_TIMESTAMP: i64 = 172_800;
struct Args { struct Args {
/// filter by date. /// filter by date.
/// ///
/// Can filter by a minimum age $DATE or from $START|$STOP (format example: YYYY-MM-DD or YYYY-MM-DDTHH:MM:SS) [default: $NOW - 2 days] /// Can filter by a minimum age $DATE or from $START|$STOP (format example: YYYY-MM-DD or YYYY-MM-DDTHH:MM:SS) [default: $NOW - 2d]
#[clap(short, long, parse(try_from_str = parse_user_date))] #[clap(short, long, parse(try_from_str = parse_user_date))]
date: DateArgs, date: Option<DateArgs>,
/// filter by repository name /// filter by repository name
#[clap(short, long)]
repository: Option<String>, repository: Option<String>,
/// add tags exclusion /// add tags exclusion
@ -49,15 +48,30 @@ pub struct DateArgs {
} }
fn main() { fn main() {
if SimpleLogger::new().init().is_err() { let args = Args::parse();
eprintln!("failed to initialize logger"); let logger = SimpleLogger::new()
.without_timestamps()
.with_level(match args.verbose {
true => log::LevelFilter::Debug,
false => log::LevelFilter::Info,
});
if let Some(e) = logger.init().err() {
eprintln!("failed to initialize logger: {}", e);
exit(1); exit(1);
} }
let args = Args::parse(); let (ids, saved_size) = process_imgs(
args.repository,
let tags = args.tags.map_or(vec![], |tags| tags); args.tags.map_or(vec![], |tags| tags),
let (ids, saved_size) = process_imgs(args.repository, tags, args.date); args.date.map_or(
DateArgs {
start: Utc::now().timestamp() - TWO_DAYS_TIMESTAMP,
stop: None,
},
|d| d,
),
);
if args.dry_run { if args.dry_run {
info!("dry run activated"); info!("dry run activated");
@ -91,12 +105,12 @@ fn main() {
}; };
} }
if args.verbose || args.dry_run { if args.dry_run {
info!("deleted images: {:#?}", ids); info!("deleted images: {:#?}", ids);
} }
info!( info!(
"Total disk space saved: {}", "Total disk space saved: {}",
if saved_size / 1000 as f32 > 1 as f32 { if saved_size / 1000.0 > 1.0 {
format!("{:.2}GB", saved_size / 1000.0) format!("{:.2}GB", saved_size / 1000.0)
} else { } else {
format!("{:.2}MB", saved_size) format!("{:.2}MB", saved_size)