Skip to content

Commit

Permalink
Merge pull request #8 from RossyWhite/documents
Browse files Browse the repository at this point in the history
documentation
  • Loading branch information
RossyWhite committed May 12, 2023
2 parents 83fe20d + a1f29ca commit 76df4ed
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 6 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ name = "dyson"
version = "0.1.0"
edition = "2021"
authors = ["Daiki Shiroi <[email protected]>"]
description = "A CLI tool to destroy staled ECR images which are not used by applications."
license = "MIT"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
97 changes: 96 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,96 @@
# dyson
# dyson

dyson is a command-line tool that helps you delete unused ECR images from your registry.
It provides several commands to manage the deletion process.

## Installation

To use dyson, you need to have Rust and Cargo installed. If you don't have them installed, you can follow the
official Rust installation guide at [https://www.rust-lang.org/tools/install](https://www.rust-lang.org/tools/install).

Once you have Rust and Cargo installed, you can install dyson by running the following command:

```bash
cargo install dyson
```

Or, you can download the latest release from the [GitHub releases page](https://github.com/RossyWhite/dyson/releases).

## Usage

```bash
dyson [OPTIONS] <COMMAND>
```

Commands:

- `init`: Generate a configuration file
- `plan`: Make a deletion plan according to the config
- `apply`: Delete ECR images according to the config
- `help`: Print this message or the help of the given subcommand(s)

Options:

- `-c, --config <FILE>`: Path to the configuration file. Default: `dyson.yaml`

## Configuration

Dyson requires a configuration file that specifies the rules for identifying unused images. By default, the
configuration file is named `dyson.yaml`.

You can customize the configuration file to fit your specific needs. The configuration file uses YAML format and should
contain the following information:

## Configuration

Dyson requires a configuration file that specifies the rules for identifying unused images. By default, the
configuration file is named `dyson.yaml`.

You can customize the configuration file to fit your specific needs. The configuration file uses YAML format and should
contain the following information:

```yaml
registry:
name: my-registry
profile_name: profile1
excludes:
- exclude/*
filters:
- pattern: '*'
days_after: 30
ignore_tag_patterns:
- latest

scans:
- name: scan-target
profile_name: profile2
```
### Registry Configuration
The `registry` section defines the settings for your ECR registry:

- `name` (optional): The name of your ECR registry.
- `profile_name`: The AWS profile name to use for authentication when accessing the registry.
- `excludes` (optional): A list of repository patterns to exclude from the deletion process. Wildcards (`*`) are
supported.
- `filters` (optional): A list of filters images based on their last push date and tags.
- `pattern`: The repository pattern to match. Wildcards (`*`) are supported.
- `days_after` (optional): The number of days after pushed which an image is considered target for deletion.
- `ignore_tag_patterns` (optional): A list of tag patterns to ignore from target for deletion. Wildcards (`*`) are
supported.

### Scans Configuration

In the scan process, dyson will scan the accounts for images that are used by

- Lambda functions
- ECS Services
- ECS Task Definitions(currently latest two revisions are considered as used)

The `scans` section defines the scans target accounts.

- `name` (optional): The name of the scan.
- `profile_name`: The AWS profile name to use for authentication when accessing the account.

You can define multiple scans in the `scans` section if needed.
8 changes: 4 additions & 4 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ pub struct RepositoryFilterConfig {
/// The repository pattern to apply this option to
pub pattern: String,
/// The number of days after which to extract images
pub days_after: u64,
pub days_after: Option<u64>,
/// The tag patterns to ignore
pub ignore_tag_patterns: Vec<String>,
pub ignore_tag_patterns: Option<Vec<String>>,
}

/// Scan Target
Expand Down Expand Up @@ -58,8 +58,8 @@ impl DysonConfig {
excludes: Some(vec!["exclude/*".to_string()]),
filters: Some(vec![RepositoryFilterConfig {
pattern: "*".to_string(),
days_after: 30,
ignore_tag_patterns: vec!["latest".to_string()],
days_after: Some(30),
ignore_tag_patterns: Some(vec!["latest".to_string()]),
}]),
},
scans: vec![ScanConfig {
Expand Down
4 changes: 3 additions & 1 deletion src/provider/ecr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,11 @@ impl ImageFilterItem {
Ok(Self {
pattern: glob::Pattern::new(conf.pattern.as_str())
.map_err(ImageProviderError::initialization_error)?,
days_after: conf.days_after,
days_after: conf.days_after.unwrap_or(0), // by default, all images are target after pushed
ignore_tag_patterns: conf
.ignore_tag_patterns
.as_ref()
.unwrap_or(&Vec::new())
.iter()
.map(|p| {
glob::Pattern::new(p.as_str()).map_err(ImageProviderError::initialization_error)
Expand Down

0 comments on commit 76df4ed

Please sign in to comment.