Skip to content

Commit

Permalink
Merge pull request #14 from appuio/rename
Browse files Browse the repository at this point in the history
Rename image-cleanup to seiso
  • Loading branch information
Simon Rüegg authored Mar 23, 2020
2 parents 9f8cd65 + 04c95ae commit 4e7dcc8
Show file tree
Hide file tree
Showing 19 changed files with 180 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
/.idea
/.vscode
/vendor
/image-cleanup
/seiso
6 changes: 3 additions & 3 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ snapshot:

dockers:
- image_templates:
- "docker.io/appuio/image-cleanup:v{{ .Version }}"
- "docker.io/appuio/image-cleanup:v{{ .Major }}"
- "docker.io/appuio/seiso:v{{ .Version }}"
- "docker.io/appuio/seiso:v{{ .Major }}"

changelog:
sort: asc
Expand All @@ -45,4 +45,4 @@ changelog:
release:
github:
owner: appuio
name: image-cleanup
name: seiso
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FROM docker.io/library/alpine:3.11 as runtime

ENTRYPOINT ["image-cleanup"]
ENTRYPOINT ["seiso"]

RUN \
apk add --no-cache curl bash

COPY image-cleanup /usr/bin/image-cleanup
COPY seiso /usr/bin/
USER 1000:0
41 changes: 24 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# Image Cleanup Client
# Seiso

[![dockeri.co](https://dockeri.co/image/appuio/image-cleanup)](https://hub.docker.com/r/appuio/image-cleanup)
[![dockeri.co](https://dockeri.co/image/appuio/seiso)](https://hub.docker.com/r/appuio/seiso)

![](https://img.shields.io/github/workflow/status/appuio/image-cleanup/Build)
![](https://img.shields.io/github/v/release/appuio/image-cleanup?include_prereleases)
![](https://img.shields.io/github/issues-raw/appuio/image-cleanup)
![](https://img.shields.io/github/issues-pr-raw/appuio/image-cleanup)
![](https://img.shields.io/github/license/appuio/image-cleanup)
![](https://img.shields.io/github/workflow/status/appuio/seiso/Build)
![](https://img.shields.io/github/v/release/appuio/seiso?include_prereleases)
![](https://img.shields.io/github/issues-raw/appuio/seiso)
![](https://img.shields.io/github/issues-pr-raw/appuio/seiso)
![](https://img.shields.io/github/license/appuio/seiso)

## General

The image cleanup client is used to clean up container images in an image registry (currently only OpenShift image registries
Seiso is a client that is used to clean up container images in an image registry (currently only OpenShift image registries
are supported).

The tool is intended to be used closely within an application lifecycle management (Review apps). It analyzes a git repository
and compares the history with the target image registry, removing old and unused image tags according to customizable rules.

The tool can also be used more aggressively by deleting unkown image tags too ("orphans"). See more usage examples below.
The tool can also be used more aggressively by deleting unknown image tags too ("orphans"). See more usage examples below.

This tool is opinionated in the naming of image tags, as the image tags have to follow certain naming rules for this to work.
E.g. stick to tagging with Git SHA value: `namespace/app:a3d0df2c5060b87650df6a94a0a9600510303003` or Git Tag: `namespace/app:v1.2.3`.
Expand All @@ -29,6 +29,13 @@ This prevents accidental deletions when testing.

The primary execution environments are CI/CD pipelines after image pushes, rollouts or any other sort of automated cleanup jobs.

In the future, there might be more stuff to cleanup (e.g. stuck Pods, ConfigMaps, Secrets, etc.), but for now, only OpenShift
image registries are supported.

## The name

seiso 清楚 : Japanese for "cleaning" (think “shine” in English): Keep the workplace free of hanging wires, grease, scraps, and waste.

## Usage

The following examples assume the namespace `namespace`, and and image stream named `app`. For the image cleanup to work,
Expand All @@ -54,21 +61,21 @@ In all cases, it is assumed that the git repository is already checked out in th
Let's assume target branch is `a`:

```console
image-cleanup history namespace/app --keep 2
seiso images history namespace/app --keep 2
```
Only the image tag `a1` will be deleted (only current branch is compared).

### Example: Keep no image tags

```console
image-cleanup history namespace/app --keep 0
seiso images history namespace/app --keep 0
```
This would delete `a1` and `a2`, but *not* `a5`, as this image is being actively used by a Pod.

### Example: Delete orphaned images

```console
image-cleanup orphans namespace/app --older-than 7d
seiso images orphans namespace/app --older-than 7d
```
This will delete `a1`, `a2`, `b3` and `b4`, if we assume that `a5` is being actively used, and `c6` is younger than 7d
(image tag push date, not commit date).
Expand All @@ -89,22 +96,22 @@ v1.10.1
```

```console
image-cleanup history namespace/app --keep 2 --tags
seiso images history namespace/app --keep 2 --tags
```
This would delete `v1.9.3` as expected, since the `--sort` flag is `version` by default (including support for v prefix).
If `alphabetic`, the order for semver tags is reversed (probably undesired). For date-based tags, `alphabetic` sorting
flag might be better suitable, e.g. `2020-03-17`.

## Migrate from legacy cleanup plugin

Projects using the legacy `oc` cleanup plugin can be migrated to `image-cleanup` as follows
Projects using the legacy `oc` cleanup plugin can be migrated to `seiso` as follows

```console
oc -n "$OPENSHIFT_PROJECT" plugin cleanup "$APP_NAME" -p "$PWD" -f=y
```
becomes:
```console
image-cleanup history "$OPENSHIFT_PROJECT/$APP_NAME" --force
seiso images history "$OPENSHIFT_PROJECT/$APP_NAME" --force
```

## Development
Expand All @@ -122,9 +129,9 @@ goreleaser --snapshot --rm-dist

### Run
```
./dist/image-cleanup_linux_amd64/image-cleanup --help
./dist/seiso_linux_amd64/seiso --help
# or
docker run --rm -it appuio/image-cleanup:<tag>
docker run --rm -it appuio/seiso:<tag>
```

## Release
Expand Down
6 changes: 3 additions & 3 deletions cmd/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package cmd

import (
"fmt"
"github.com/appuio/image-cleanup/cfg"
"github.com/appuio/image-cleanup/pkg/git"
"github.com/appuio/image-cleanup/pkg/openshift"
"github.com/appuio/seiso/cfg"
"github.com/appuio/seiso/pkg/git"
"github.com/appuio/seiso/pkg/openshift"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
Expand Down
10 changes: 5 additions & 5 deletions cmd/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package cmd

import (
"fmt"
"github.com/appuio/image-cleanup/cfg"
"github.com/appuio/image-cleanup/pkg/cleanup"
"github.com/appuio/image-cleanup/pkg/git"
"github.com/appuio/image-cleanup/pkg/openshift"
"github.com/appuio/seiso/cfg"
"github.com/appuio/seiso/pkg/cleanup"
"github.com/appuio/seiso/pkg/git"
"github.com/appuio/seiso/pkg/openshift"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
Expand All @@ -27,7 +27,7 @@ var (
)

func init() {
rootCmd.AddCommand(historyCmd)
imagesCmd.AddCommand(historyCmd)
defaults := cfg.NewDefaultConfig()

addCommonFlagsForGit(historyCmd, defaults)
Expand Down
15 changes: 15 additions & 0 deletions cmd/images.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package cmd

import (
"github.com/spf13/cobra"
)

// imagesCmd represents the images command
var imagesCmd = &cobra.Command{
Use: "images",
Short: "Cleans up your image registry from unused image tags",
}

func init() {
rootCmd.AddCommand(imagesCmd)
}
10 changes: 5 additions & 5 deletions cmd/orphans.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package cmd
import (
"errors"
"fmt"
"github.com/appuio/image-cleanup/cfg"
"github.com/appuio/image-cleanup/pkg/cleanup"
"github.com/appuio/image-cleanup/pkg/git"
"github.com/appuio/image-cleanup/pkg/openshift"
"github.com/appuio/seiso/cfg"
"github.com/appuio/seiso/pkg/cleanup"
"github.com/appuio/seiso/pkg/git"
"github.com/appuio/seiso/pkg/openshift"
"github.com/karrick/tparse"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -41,7 +41,7 @@ var (
)

func init() {
rootCmd.AddCommand(orphanCmd)
imagesCmd.AddCommand(orphanCmd)
defaults := cfg.NewDefaultConfig()

addCommonFlagsForGit(orphanCmd, defaults)
Expand Down
2 changes: 1 addition & 1 deletion cmd/orphans_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cmd

import (
"github.com/appuio/image-cleanup/cfg"
"github.com/appuio/seiso/cfg"
"github.com/stretchr/testify/assert"
"regexp"
"testing"
Expand Down
6 changes: 3 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cmd

import (
"github.com/appuio/image-cleanup/cfg"
"github.com/appuio/seiso/cfg"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
Expand All @@ -14,8 +14,8 @@ import (
var (
// rootCmd represents the base command when called without any subcommands
rootCmd = &cobra.Command{
Use: "image-cleanup",
Short: "Cleans up images tags on remote registries",
Use: "seiso",
Short: "keeps your kubernetes projects clean",
PersistentPreRun: parseConfig,
}
config = cfg.NewDefaultConfig()
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/appuio/image-cleanup
module github.com/appuio/seiso

go 1.13

Expand All @@ -13,8 +13,8 @@ require (
github.com/openshift/client-go v0.0.0-20180830153425-431ec9a26e50
github.com/sirupsen/logrus v1.4.2
github.com/spf13/cobra v0.0.6
github.com/spf13/pflag v1.0.3
github.com/spf13/viper v1.4.0
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.6.2
github.com/stretchr/testify v1.5.1
github.com/thoas/go-funk v0.6.0
golang.org/x/net v0.0.0-20191014212845-da9a3fd4c582 // indirect
Expand Down
Loading

0 comments on commit 4e7dcc8

Please sign in to comment.