bump v0.4.2
This commit is contained in:
parent
296a856a9c
commit
041072bf0a
|
@ -76,7 +76,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "clear-docker-images"
|
||||
version = "0.4.1"
|
||||
version = "0.4.2"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"clap",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "clear-docker-images"
|
||||
version = "0.4.1"
|
||||
version = "0.4.2"
|
||||
edition = "2021"
|
||||
authors = ["Antoine <DataHearth> Langlois"]
|
||||
description = "small binary to clean up docker images (mostly in CI)"
|
||||
|
|
|
@ -10,9 +10,16 @@ WORKDIR /clear-docker-images
|
|||
|
||||
build-linux:
|
||||
COPY . .
|
||||
RUN rustup target add 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
|
||||
|
||||
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:
|
||||
FROM docker:20.10.12-dind-alpine3.15
|
||||
|
||||
|
@ -20,7 +27,7 @@ build-images:
|
|||
LABEL repository="https://github.com/DataHearth/clear-docker-images"
|
||||
LABEL org.opencontainers.image.source="https://github.com/DataHearth/clear-docker-images"
|
||||
|
||||
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"]
|
||||
|
||||
|
|
3
Makefile
3
Makefile
|
@ -1,4 +1,4 @@
|
|||
VERSION := 0.4.1
|
||||
VERSION := 0.4.2
|
||||
|
||||
.PHONY: bump-version
|
||||
bump-version:
|
||||
|
@ -7,6 +7,7 @@ bump-version:
|
|||
@sd "version = \"${VERSION}\"" "version = \"${NEW_VERSION}\"" Cargo.toml
|
||||
@sd "VERSION=${VERSION}" "VERSION=${NEW_VERSION}" .env
|
||||
@sd "VERSION := ${VERSION}" "VERSION := ${NEW_VERSION}" Makefile
|
||||
@cargo update --package=clear-docker-images
|
||||
@git add .
|
||||
@git commit -m "bump v${NEW_VERSION}"
|
||||
@git tag -m "bump v${NEW_VERSION}" v${NEW_VERSION}
|
||||
|
|
|
@ -49,7 +49,7 @@ where
|
|||
if size.contains("KB") {
|
||||
size.replace("KB", "")
|
||||
.parse::<f32>()
|
||||
.map(|s| s / 1000 as f32)
|
||||
.map(|s| s / 1000.0)
|
||||
.map_err(serde::de::Error::custom)
|
||||
} else if size.contains("MB") {
|
||||
size.replace("MB", "")
|
||||
|
@ -58,7 +58,7 @@ where
|
|||
} else if size.contains("GB") {
|
||||
size.replace("GB", "")
|
||||
.parse::<f32>()
|
||||
.map(|s| s * 1000 as f32)
|
||||
.map(|s| s * 1000.0)
|
||||
.map_err(serde::de::Error::custom)
|
||||
} else {
|
||||
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);
|
||||
exit(1);
|
||||
});
|
||||
let mut images: Vec<String> = output.lines().map(|s| s.to_string()).collect();
|
||||
// * remove last empty line
|
||||
images.remove(images.len() - 1);
|
||||
let images: Vec<String> = output.lines().map(|s| s.to_string()).collect();
|
||||
|
||||
if images.len() == 0 {
|
||||
warn!("No images found for current timestamp and/or repository");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return images;
|
||||
|
|
36
src/main.rs
36
src/main.rs
|
@ -17,12 +17,11 @@ const TWO_DAYS_TIMESTAMP: i64 = 172_800;
|
|||
struct Args {
|
||||
/// 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))]
|
||||
date: DateArgs,
|
||||
date: Option<DateArgs>,
|
||||
|
||||
/// filter by repository name
|
||||
#[clap(short, long)]
|
||||
repository: Option<String>,
|
||||
|
||||
/// add tags exclusion
|
||||
|
@ -49,15 +48,30 @@ pub struct DateArgs {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
if SimpleLogger::new().init().is_err() {
|
||||
eprintln!("failed to initialize logger");
|
||||
let args = Args::parse();
|
||||
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);
|
||||
}
|
||||
|
||||
let args = Args::parse();
|
||||
|
||||
let tags = args.tags.map_or(vec![], |tags| tags);
|
||||
let (ids, saved_size) = process_imgs(args.repository, tags, args.date);
|
||||
let (ids, saved_size) = process_imgs(
|
||||
args.repository,
|
||||
args.tags.map_or(vec![], |tags| tags),
|
||||
args.date.map_or(
|
||||
DateArgs {
|
||||
start: Utc::now().timestamp() - TWO_DAYS_TIMESTAMP,
|
||||
stop: None,
|
||||
},
|
||||
|d| d,
|
||||
),
|
||||
);
|
||||
|
||||
if args.dry_run {
|
||||
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!(
|
||||
"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)
|
||||
} else {
|
||||
format!("{:.2}MB", saved_size)
|
||||
|
|
Reference in New Issue