Giter Club home page Giter Club logo

nexus-cli's Introduction

CircleCI MIT License

Nexus CLI for Docker Registry

Usage

Download

Below are the available downloads for the latest version of Nexus CLI (1.0.0-beta). Please download the proper package for your operating system and architecture.

Linux:

wget https://s3.eu-west-2.amazonaws.com/nexus-cli/1.0.0-beta/linux/nexus-cli

Windows:

wget https://s3.eu-west-2.amazonaws.com/nexus-cli/1.0.0-beta/windows/nexus-cli

Mac OS X:

wget https://s3.eu-west-2.amazonaws.com/nexus-cli/1.0.0-beta/osx/nexus-cli

OpenBSD:

wget https://s3.eu-west-2.amazonaws.com/nexus-cli/1.0.0-beta/openbsd/nexus-cli

FreeBSD:

wget https://s3.eu-west-2.amazonaws.com/nexus-cli/1.0.0-beta/freebsd/nexus-cli

Installation

To install the library and command line program, use the following:

go get -u github.com/mlabouardy/nexus-cli

Available Commands

$ nexus-cli configure
$ nexus-cli image ls
$ nexus-cli image tags -name mlabouardy/nginx
$ nexus-cli image info -name mlabouardy/nginx -tag 1.2.0
$ nexus-cli image delete -name mlabouardy/nginx -tag 1.2.0
$ nexus-cli image delete -name mlabouardy/nginx -keep 4
$ nexus-cli image size -name mlabouardy/nginx

Tutorials

nexus-cli's People

Contributors

mlabouardy avatar nicovillanueva avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nexus-cli's Issues

404

I've already configured nexus host name password.

And try this
./nexus-cli image ls
404

quotes in password should be escaped

When you do a configure the quotes " are not escaped if present in password this cause the authentication to fail.

Workaround is to edit the .credential file manually

delete function removes the image from the repo, but the list still says it's there

When I used the nexus-cli image delete command to remove a specific image tag, it removes the image tag from the repository (I checked the UI for the repo and it was gone), but then when I use the nexus-cli image tags command to get a list of the tags, it still showed up in the list. Anybody know of a workaround for this? I saw another issue talking about them remaining in the blob store, not sure if that's related or not. I tried the solution listed there of running the "purge unused docker manifests and images" and "compact blobstore" tasks and it didn't work.

For the -keep option, is it possible to do a numeric sort?

Great tool. Nice to be able to delete images from the nexus registry from the comand line. Is it possible to do a numeric (ie. version) sort when using the --keep option.

For example when I list the tags of an image I get:

  • 1.0.1
  • 1.0.11
  • 1.0.4
  • latest
    There are 4 images for repository xx

Then do the -keep 2 option, I get:

  • 1.0.4
  • latest

Would like to keep the last 2 versions:

  • 1.0.11
  • latest

nexus-cli image delete and keep option (wrong sorting)

I had registry with 190 tags for image, tags were generated automagically and images were pushed with incremented version number from 1 to 190.

nexus@reg:~$ ./nexus-cli image tags -n testimage
1
10
100
101
102
103
104
105
106
107
108
109
11
110
111
112
113
114
115
116
117
118
119
12
120
121
122
123
...

I have decided to remove old images and keep only last 20:

nexus@reg:~$ ./nexus-cli image delete -n testimage -k 20

and the effect is:

nexus@reg:~$ ./nexus-cli image tags -n testimage
81
82
83
84
85
86
87
88
89
9
90
91
92
93
94
95
96
97
98
99
There are 20 images for testimage

Nexus-cli version:
nexus@reg:~$ ./nexus-cli --version Nexus CLI version 1.0.0-beta

Image size include duplicate layers in the total size

When running image size -n {image} you get total size of all layer in all tags . This counts each of the layers toward total size. Most images include base layers in each of the images thus do not need to be counted for each tag.

tag v1.0
layer: xyz
layer: abc

tag v1.1
layer: xyz
layer : cdf

Sum should be xyz + abc + cdf ( not xyz + abc + xyz + cdf )

I propose to pull out the sizeInfo to the outside loop and only count distinct layer to toward total image size.

		sizeInfo := make(map[string]int64)

		for _, tag := range tags {
			manifest, err := r.ImageManifest(imgName, tag)
			if err != nil {
				return cli.NewExitError(err.Error(), 1)
			}


			for _, layer := range manifest.Layers {
				sizeInfo[layer.Digest] = layer.Size
			}


		}

		for _, size := range sizeInfo {
			totalSize += size
		}
		fmt.Printf("%d %s\n", totalSize, imgName)

Multiple executions give different output

I'm using the nexus-cli in a script to allow me using regex in tag and delete all except last x tags for this regex.

My script looks like:

images=($(./nexus-cli image ls | grep -v "Total images:"))
tag="functional_([0-9])+"
keep=5

while [[ $# > 0 ]]; do
  case $1 in
    -t|--tag)
      shift
      tag=$1
      ;;
    -n|--number)
      shift
      keep=$1
      ;;
    *)
      usage
      ;;
  esac
  shift
done

echo "Cleaning tags for ${#images[@]} images"
for image in ${images[@]}; do
  echo "Tags for $image"
  tags=($(./nexus-cli image tags -n $image | egrep "$tag" | sort -k 2n -t'_'))
  n_delete=$((${#tags[@]}-$keep))
  echo "Found ${#tags[@]} tags"
  if [ $n_delete -gt 0 ]; then
    echo "Going to delete $n_delete tags"
    for tag in ${tags[@]:0:$n_delete}; do
      ./nexus-cli image delete -n $image -t $tag
    done
  else
    echo "Not enough tags (${#tags[@]})"
  fi
done

My problem is that using the default parameters (for example), images that have multiple functional_x tags are reporting that have 0 images with tag that fit the regex.

In script:

Tags for influxdb_configure
Found 0 tags
Not enough tags (0)

In shell:

root@nexus-dev:/home/ops# ./nexus-cli image tags -n influxdb_configure | grep functional
functional_1
functional_2
functional_3
functional_latest

Which can be the problem?

md2man: cannot find package

Trying to install:

go get -u github.com/mlabouardy/nexus-cli

Results in:

package github.com/cpuguy83/go-md2man/v2/md2man: cannot find package "github.com/cpuguy83/go-md2man/v2/md2man" in any of:
	/usr/local/go/src/github.com/cpuguy83/go-md2man/v2/md2man (from $GOROOT)
	/go/src/github.com/cpuguy83/go-md2man/v2/md2man (from $GOPATH)

Added ArchLinux Package

Hello,

I just packaged this software for Archlinux, i can know be installed with and AUR helper such as:

yay -S nexus-cli-bin

Also the reposiotory for the PKGBUILD is on masterkorp/nexus-cli-bin-pkgbuild

You might want to add this information to your README

用openai写了一个基于nexus-cli的可视化脚本,分享给大家

#!/bin/bash
# -------------------------------------------------------
# 基于nexus-cli的图形化工具
# openai提供技术支持
# 2024.5.16
# -------------------------------------------------------

# 假设nexus-cli已经在PATH中
NEXUS_CLI="nexus-cli" 
IFS=" "

list_images() {
    # 获取所有的 images 并移除最后的汇总行
    readarray -t images <<< `$NEXUS_CLI image ls | grep -v xxl | sed '$d'`

    # 检查是否获取到了镜像列表
    if [ ${#images[@]} -eq 0 ]; then
        whiptail --title "Error" --msgbox "No images found or unable to fetch images." 10 50
        exit 1
    fi

    # 创建 whiptail 菜单选项,每行显示一个image,并在前面加上序号
    menu_options=()
    for i in "${!images[@]}"; do
        menu_options+=("$(($i+1))" "${images[$i]}")
    done

    # 使用 whiptail 显示可选的 image 列表
    selected_index=$(whiptail --title "NEXUS Image Maintenance Tool - Images" --menu "Choose an image" 30 80 20 "${menu_options[@]}" 3>&1 1>&2 2>&3)
    if [ $? -eq 0 ]; then
        # 减去 1 是因为数组索引从 0 开始
        list_tags "${images[$(($selected_index-1))]}"
    fi
}

# 显示选定镜像的tag列表,并允许用户选择
list_tags() {
    local image_name=$1
	# 获取所有的 tags 并移除最后的汇总行
    readarray -t tags <<< `$NEXUS_CLI image tags --name="$image_name" | sed '$d'`
    if [ -z "$tags" ]; then
        whiptail --title "Error" --msgbox "No tags found for image $image_name or unable to fetch tags." 10 50
        return
    fi
	
	# 创建 whiptail 菜单选项,每行显示一个image,并在前面加上序号
    menu_options=()
    for i in "${!tags[@]}"; do
        menu_options+=("$(($i+1))" "${tags[$i]}")
    done
	
    tag_selection=$(whiptail --title "NEXUS Image Maintenance Tool - Tags" --menu "Choose a tag of $image_name" 30 80 20 "${menu_options[@]}" 3>&1 1>&2 2>&3)
    if [ $? -eq 0 ]; then
        show_info "$image_name" "${tags[$(($tag_selection-1))]}"
    else
        list_images
    fi
}

# 显示所选tag的信息
show_info() {
    local image_name=$1
    local tag_name=$2
    info=$($NEXUS_CLI image info --name="$image_name" --tag="$tag_name")
	
	whiptail --title "Information for $image_name:$tag_name" --yes-button "OK" --no-button "Delete"  --yesno "$info" 30 80
	exit_status=$?
    if [ $exit_status -eq 0 ]; then
        # 用户选择了 OK
        list_tags "$image_name"
    else
        # 用户选择了 Delete
        delete_tag "$image_name" "$tag_name"
    fi
}

# 删除指定的tag
delete_tag() {
    local image_name=$1
    local tag_name=$2
    if (whiptail --yesno "Are you sure you want to delete the tag $tag_name of image $image_name?" 10 60); then
        $NEXUS_CLI image delete --name="$image_name" --tag="$tag_name"
        whiptail --msgbox "Tag $tag_name of image $image_name has been deleted." 10 60
    fi
	list_tags "$image_name"
}

# 检查nexus-cli是否存在
if ! command -v $NEXUS_CLI &> /dev/null; then
    echo "nexus-cli could not be found. Please install it and add it to your PATH."
    exit 1
fi

# 运行主程序
list_images

.crendetials file not found?

Hi,
I installed nexus-cli according to the guide on the GitHub and it works fine in Command-line.

But when I invoke nexus-cli in the shell scripts showing below:
nexus-cli image delete -n dev/myapp -k 2

the following message always appears:
.crendetials file not found

I checked and was sure that the file .crendetials existed in the user's home directory which executes nexus-cli.

Am I wrong and how to resolve this issue? Thanks.

HTTP Code: 400

vitaliebrinza:nexus vitalieb$ ./nexus-cli -v
Nexus CLI version 1.0.0-beta

vitaliebrinza:nexus vitalieb$ ./nexus-cli configure
Enter Nexus Host: https://artefacts3.domain:8084
Enter Nexus Repository Name: company
Enter Nexus Username: admin
Enter Nexus Password: password

gives me:
vitaliebrinza:nexus vitalieb$ ./nexus-cli image ls
HTTP Code: 400

unability to actually delete images

nexus-cli is able to list images and tags

root@nexus:~# ./nexus-cli image tags -name api-builder
1
10
11
12
13
14
15
16
17
18
19
2
3
4
5
6
7
8
9

but unable to delete them:
root@nexus:~# ./nexus-cli image delete -name api-builder -keep 2

api-builder:1 image will be deleted ...
api-builder:10 image will be deleted ...
api-builder:11 image will be deleted ...
api-builder:12 image will be deleted ...
api-builder:13 image will be deleted ...
api-builder:14 image will be deleted ...
api-builder:15 image will be deleted ...
api-builder:16 image will be deleted ...
api-builder:17 image will be deleted ...
api-builder:18 image will be deleted ...
api-builder:19 image will be deleted ...
api-builder:2 image will be deleted ...
api-builder:3 image will be deleted ...
api-builder:4 image will be deleted ...
api-builder:5 image will be deleted ...
api-builder:6 image will be deleted ...
api-builder:7 image will be deleted ...

After running this command, nothing changes inside repository.
Tested under nexus 3.7.1-02 and 3.9.0-01

Total images: 0. How to resolve it?

I configure all. And when i want to get image list, it shows me that images count - 0. I tried to use different repository name, like docker docker-private docker-group, but it always show me zero. Maybe anyone know how to resolve this problem?
image

[Feature request] Allow to provide configuration on CLI

I would like to do something like:

nexus-cli configure --host http://example.org --repository example --username someone --password somePass

or something like:

nexus-cli images ls --host http://example.org --repository example --username someone --password somePass

Option to ignore tags (at least for delete)

Hi,

I am a little bit concerned, that (lets say) "--keep 4" can also delete my "latest"-tag. I would be more confident, if I could explicitely tell nexus-cli to ignore certain tags (or patterns, see #8 ).

nexus-cli image delete --name foo --keep 12 --ignore latest --ignore edge

failed to delete too many tags

Hi,

I tried to delete to many tags, but it out of range, any help? many thx!
./nexus-cli image tags -name test/uow-adapter
2022/11/24 00:51:08 strconv.Atoi: parsing "00958811696408296102645668": value out of range

looks I have 4002 tags now.
image

nfs mounts

we are using nfs share to store our docker images
we tried deleting using your script and we failed

Will your script work on nfs mounts to say is there any limitations

Deletes incorrect images

I'm cleaning up a nexus repo after a massive coding effort that generated many images, manifests and tags. Since I made the mistake of using a single docker-hosted repo for snapshots and releases, I have to be careful what I delete. Images destined for a test environment are tagged with 'stage' in addition to the commit SHA. I can't use nexus-cli's 'keep' feature because the image tagged with stage may not be the latest image pushed to the repository. I use this comment to delete the unwanted images:

nexus-cli image tags -n image-name | grep -Ev "stage|There" | xargs -I{} nexus-cli image delete -n image-name -t {}

The grep removes the stage tag and the summary line from the list of image tags. The first run of this command deletes most of the tags with some exceptions. The output has '404 not found' interleaved with the '...successful deleted' messages'. A second run deletes tags missed on the first run. Continuing to run the command until I see no 404's yields a nasty surprise. image-name, all of its manifests and tags (including stage) are gone.

Regular expression for tags to delete

I'm using a plugin to generate a new version based on git status (gradle reckon plugin).
This has the disadvantage of pushing a lot of docker images that I have to clean.

It would be great to have support for simple regular expression when deleting images:

nexus-cli image delete  -n my-image -t 1.1.0-dev.*  

Docker images are deleted from GUI but not from blob store

After running the script, Docker images are being (partially?) removed.
Deletions index isn't being updated and when I run compact 'blob store' space isn't being reclaimed.
When I browser assets / components the old Docker images are removed from the GUI, but not from the blob store.

Running 'compact blob store' task manually it exits with status code 0.

Currently running Nexus 3.5.X

Compiled Binaries

The compiled binaries are out of date. Anyway you could update those with the newer commits?

installation issue

getting this error while installation

github.com/mlabouardy/nexus-cli

../src/github.com/mlabouardy/nexus-cli/main.go:25:14: cannot use []cli.Author literal (type []cli.Author) as type []*cli.Author in assignment
../src/github.com/mlabouardy/nexus-cli/main.go:31:15: cannot use []cli.Command literal (type []cli.Command) as type []*cli.Command in assignment
../src/github.com/mlabouardy/nexus-cli/main.go:42:4: cannot use []cli.Command literal (type []cli.Command) as type []*cli.Command in field value
../src/github.com/mlabouardy/nexus-cli/main.go:54:21: cannot use cli.StringFlag literal (type cli.StringFlag) as type cli.Flag in array or slice literal:
cli.StringFlag does not implement cli.Flag (Apply method has pointer receiver)
../src/github.com/mlabouardy/nexus-cli/main.go:67:21: cannot use cli.StringFlag literal (type cli.StringFlag) as type cli.Flag in array or slice literal:
cli.StringFlag does not implement cli.Flag (Apply method has pointer receiver)
../src/github.com/mlabouardy/nexus-cli/main.go:70:21: cannot use cli.StringFlag literal (type cli.StringFlag) as type cli.Flag in array or slice literal:
cli.StringFlag does not implement cli.Flag (Apply method has pointer receiver)
../src/github.com/mlabouardy/nexus-cli/main.go:82:21: cannot use cli.StringFlag literal (type cli.StringFlag) as type cli.Flag in array or slice literal:
cli.StringFlag does not implement cli.Flag (Apply method has pointer receiver)
../src/github.com/mlabouardy/nexus-cli/main.go:85:21: cannot use cli.StringFlag literal (type cli.StringFlag) as type cli.Flag in array or slice literal:
cli.StringFlag does not implement cli.Flag (Apply method has pointer receiver)
../src/github.com/mlabouardy/nexus-cli/main.go:88:21: cannot use cli.StringFlag literal (type cli.StringFlag) as type cli.Flag in array or slice literal:
cli.StringFlag does not implement cli.Flag (Apply method has pointer receiver)
../src/github.com/mlabouardy/nexus-cli/main.go:100:21: cannot use cli.StringFlag literal (type cli.StringFlag) as type cli.Flag in array or slice literal:
cli.StringFlag does not implement cli.Flag (Apply method has pointer receiver)
../src/github.com/mlabouardy/nexus-cli/main.go:31:15: too many errors

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.