Giter Club home page Giter Club logo

drprune's Introduction

gif-header

โœจ Prune container images in a CLI way โœจ

Semantic Release Commitizen friendly GitHub repo size


gif-about

A CLI tool that prune old images on GitHub (ghcr.io) registry and GitLab (registry.gitlab.com) registry

Getting Startedย ย ย |ย ย ย  Descriptionย ย ย |ย ย ย  Usageย ย ย |ย ย ย  Installationย ย ย |ย ย ย  Conceptsย ย ย |ย ย ย  Versioning


โžค Getting Started

If you want contribute on this project, first you need to make a git clone:

git clone --depth 1 https://github.com/ci-monk/drprune.git -b main

This will give you access to the code on your local machine.

โžค Usage

Variables

Environment Description
GH_TOKEN GitHub API Token
GH_USERNAME GitHub User/Organization Name
GH_CONTAINER GitHub Container Name
GL_TOKEN GitLab API Token
GL_NAMESPACE GitLab Namespace

CLI

GitHub

drprune gh images -t $GH_TOKEN -n <username> -c <container-name>
drprune gh insights -t $GH_TOKEN -n <username>

GitLab

drprune gl images -t $GL_TOKEN -ns <namespace>
drprune gl insights -t $GL_TOKEN -ns <namespace>

CI

GitHub Actions

GitLab CI

โžค Installation

with go:

# if you cannot install directly, try following command,
# then input install command again
go get -u github.com/lpmatos/drprune/cmd/drprune

# or
go get -v ./...
go run ./cmd/drprune/main.go --help

with brew:

brew tap ci-monk/tools
brew install drprune

โžค Concepts

Cobra

Cobra is a CLI framework for Golang. Using it you can speed up your development and creating a powerful and modern CLI application. Cobra is built on a structure of commands, arguments and flags:

  • Commands represent actions.
  • Args are things.
  • Flags are modifiers for those actions.

The best applications will read like sentences when used. Users will know how to use the application because they will natively understand how to use it. This pattern is: APPCLI VERB NOUN --ADJECTIVE or APPCLI COMMAND ARG --FLAG.

Commands

Command is the central point of the application. Each interaction thar the application supports will be contained in a command. We can create commands with children commands and optionally run an action. In the example above, server is the command.

Flags

A flag is a way to modify the behavior of a command. Cobra supports fully POSIX-compliant flags as well the Go flag package. A Cobra command can define flags that persist through to children commands and flags that are only available to that command. In the example above, port is the flag.

โžค Learnings

  • Create a Golang CLI application.
  • Create a multistage Golang Dockerfile.
  • Create a docker-compose file with waiting entrypoint.
  • Setup a Golang Releaser publish pipeline using github actions.
  • Understand how GiHub works with packages.
  • Understand how GitLab works with packages.
  • Handler operations in GitHub API to delete container images using a SDK.
  • Handler operations in GitLab API to delete container images using a SDK.

โžค Links

โžค Versioning

To check the change history, please access the CHANGELOG.md file.

โžค Project status

The project is currently being updated! ๐Ÿ‘พ

โžค Donations

If my work has impacted your life in a positive way and you'd like to buy me a coffee (or a hundred), that'd be much appreciated!

โžค Show your support

Give me a โญ๏ธ if this project helped you!

gif-header

Made with ๐Ÿ’œ by me ๐Ÿ‘‹ inspired on readme-md-generator

drprune's People

Contributors

dependabot[bot] avatar jkoelker avatar lpsm-dev avatar renovate-bot avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

jkoelker anhnmt

drprune's Issues

Does this tool even work?

Behavior

I am trying to use this tool to prune old images from ghcr repository: I run this command:

$ /bin/drprune gh images -n $GH_ORG_NAME -t "$GH_TOKEN" -c $IMAGE_NAME


โ–ˆโ–ˆโ•—โ–ˆโ–ˆโ–ˆโ•—   โ–ˆโ–ˆโ–ˆโ•— โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—  โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•— โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—
โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ–ˆโ–ˆโ•— โ–ˆโ–ˆโ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•”โ•โ•โ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•”โ•โ•โ•โ•โ• โ–ˆโ–ˆโ•”โ•โ•โ•โ•โ•โ–ˆโ–ˆโ•”โ•โ•โ•โ•โ•
โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•”โ–ˆโ–ˆโ–ˆโ–ˆโ•”โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•‘  โ–ˆโ–ˆโ–ˆโ•—โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—  โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—
โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•‘โ•šโ–ˆโ–ˆโ•”โ•โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•”โ•โ•โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•‘   โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•”โ•โ•โ•  โ•šโ•โ•โ•โ•โ–ˆโ–ˆโ•‘
โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•‘ โ•šโ•โ• โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•‘  โ–ˆโ–ˆโ•‘โ•šโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•”โ•โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•‘
โ•šโ•โ•โ•šโ•โ•     โ•šโ•โ•โ•šโ•โ•  โ•šโ•โ• โ•šโ•โ•โ•โ•โ•โ• โ•šโ•โ•โ•โ•โ•โ•โ•โ•šโ•โ•โ•โ•โ•โ•โ•

INFO[2022-07-27_18:17:31] โœ… Package: xxxxxx/xxxxxxx
INFO[2022-07-27_18:17:31] โœ… We have 232 versions in this package

No matter what args I run this with, the number 232 does not change. So I'm wondering, does this tool even do what it's supposed to, or is it just a prototype?

Expected behavior

Old images should be deleted from GHCR

Actual behavior

Nothing is deleted

Environment

I am using the latest main version, built using make build on Ubuntu 20.04 (snap version of golang, v1.18.3)

Use this as part of a GitHub action

Describe the solution you'd like
This tool seems pretty cool but the setup is non-trivial. Have you considered publishing a Github action or docker image to make this easier to use in an automated environment?

Describe alternatives you've considered
remove-stale-images-action used to do this perfectly under the old GitHub packages APIs. Unfortunately it has not worked since the switch to GHCR

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.