Skip to content

goharbor/harbor-cli

Repository files navigation

Harbor-CLI Logo_256px

Harbor CLI β€” a command-line interface for interacting with your Harbor container registry. A streamlined, user-friendly alternative to the WebUI, as your daily driver or for scripting and automation.

Artifact Hub FOSSA Status codecov

Scope πŸ§ͺ

  1. CLI alternative to the WebUI
  2. Tool for scripting and automation of common repeatable Harbor tasks running on your machine or inside your pipeline

Features

The project's first goal is to reach WebUI parity.

βœ… project       Mange projects  
βœ… repo          Manage repositories  
βœ… artifact      Manage artifacts  
βœ… label         Manage labels  
βœ… tag           Manage tags   
βœ… quota         Manage quotas  
βœ… webhook       Manage webhook policies 
❌ robot         Robot Account 

βœ… login         Log in to Harbor registry  
βœ… user          Manage users  

βœ… registry      Manage registries
❌ replication   Manage replication

βœ… config        Manage the config of the Harbor CLI
βœ… cve-allowlist Manage system CVE allowlist
βœ… health        Get the health status of Harbor components
βœ… instance      Manage preheat provider instances in Harbor
βœ… info          Display detailed Harbor system, statistics, and CLI environment information


βœ… scanner       scanner commands
βœ… schedule      Schedule jobs in Harbor

βœ… completion    Generate the autocompletion script for the specified shell\
βœ… help          Help about any command
βœ… version       Version of Harbor CLI

Installation

Container

Running Harbor CLI as a container is simple. Use the following command to get started:

docker run -ti --rm -v $HOME/.config/harbor-cli/config.yaml:/root/.config/harbor-cli/config.yaml \
  -e HARBOR_ENCRYPTION_KEY=$(echo "ThisIsAVeryLongPassword" | base64) \
  registry.goharbor.io/harbor-cli/harbor-cli \
  --help

Use the HARBOR_ENCRYPTION_KEY container environment variable as a base64-encoded 32-byte key for AES-256 encryption. This securely stores your harbor login password.

I you intend to run the CLI as a container,it is advised to set the following environment variables and to create an alias and append the alias to your .zshrc or .bashrc file

echo "export HARBOR_CLI_CONFIG=\$HOME/.config/harbor-cli/config.yaml" >> ~/.zshrc
echo "export HARBOR_ENCRYPTION_KEY=\$(cat <path_to_32bit_private_key_file> | base64)" >> ~/.zshrc
echo "alias harbor='docker run -ti --rm -v \$HARBOR_CLI_CONFIG:/root/.config/harbor-cli/config.yaml -e HARBOR_ENCRYPTION_KEY=\$HARBOR_ENCRYPTION_KEY registry.goharbor.io/harbor-cli/harbor-cli'" >> ~/.zshrc 
source ~/.zshrc # or restart your terminal

Linux, MacOS and Windows

Harbor CLI will soon be published on Homebrew. Meantime, we recommend using Harbor in the Container or downloading the binary from the releases page

Add the Harbor CLI to your Container Image

Using Curl or Wget isn't needed if you want to add the Harbor CLI to your container. Instead, we recommend copying the Harbor CLI from our official image by using the following Dockerfile:

#...
COPY --from=registry.goharbor.io/harbor-cli/harbor-cli:latest /harbor /usr/local/bin/harbor
# --chown and --chmod flags can be used to set the permissions

Example CommandsπŸ’‘

>./harbor    

Official Harbor CLI

Usage:
  harbor [command]

Examples:

// Base command:
harbor

// Display help about the command:
harbor help


Available Commands:
  artifact      Manage artifacts
  completion    Generate the autocompletion script for the specified shell
  config        Manage the config of the Harbor CLI
  cve-allowlist Manage system CVE allowlist
  health        Get the health status of Harbor components
  help          Help about any command
  info          Show the current credential information
  instance      Manage preheat provider instances in Harbor
  label         Manage labels in Harbor
  login         Log in to Harbor registry
  project       Manage projects and assign resources to them
  registry      Manage registries
  repo          Manage repositories
  schedule      Schedule jobs in Harbor
  tag           Manage tags in Harbor registry
  user          Manage users
  version       Version of Harbor CLI

Flags:
  -c, --config string          config file (default is $HOME/.config/harbor-cli/config.yaml)
  -h, --help                   help for harbor
  -o, --output-format string   Output format. One of: json|yaml
  -v, --verbose                verbose output

Use "harbor [command] --help" for more information about a command.

Config Management

Hierarchy

Use the --config flag to specify a custom configuration file path (the highest priority).

  harbor --config /path/to/custom/config.yaml artifact list

If --config is not provided, Harbor CLI checks the HARBOR_CLI_CONFIG environment variable for the config file path.

export HARBOR_CLI_CONFIG=/path/to/custom/config.yaml
harbor artifact list

If neither is set, it defaults to $XDG_CONFIG_HOME/harbor-cli/config.yaml or $HOME/.config/harbor-cli/config.yaml if XDG_CONFIG_HOME is unset.

harbor artifact list
Data Path
  • Data paths are determined by the XDG_DATA_HOME environment variable.
  • If XDG_DATA_HOME is not set, it defaults to $HOME/.local/share/harbor-cli/data.yaml.
  • The data file always contains the path of the latest config used.
Config TL;DR
  • --config flag > HARBOR_CLI_CONFIG environment variable > default XDG config paths.
  • Environment variables override default settings, and the --config flag takes precedence over both environment variables and defaults.
  • The data file always contains the path of the latest config used.

Log in to Harbor Registry

harbor login demo.goharbor.io -u harbor-cli -p Harbor12345

Create a New Project

harbor project create

List all Projects

harbor project list

# output
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Project Name  Access Level  Type          Repo Count    Creation Time                   β”‚
β”‚ ──────────────────────────────────────────────────────────────────────────────────────── β”‚
β”‚  library       public        project       0             1 hour ago                      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

List all Repository in a Project

harbor repo list

# output
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Name                      Artifacts     Pulls         Last Modified Time              β”‚
β”‚ ────────────────────────────────────────────────────────────────────────────────────── β”‚
β”‚  library/harbor-cli        1             0             0 minute ago                    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Supported Platforms

Platform Status
Linux βœ…
macOS βœ…
Windows βœ…

Build From Source

Make sure you have the latest Dagger installed in your system.

Using Dagger

git clone https://github.com/goharbor/harbor-cli.git && cd harbor-cli
dagger call build-dev --platform darwin/arm64 export --path=./harbor-cli
./harbor-dev --help

If golang is installed in your system, you can also build the project using the following commands:

git clone https://github.com/goharbor/harbor-cli.git && cd harbor-cli
go build -o harbor-cli cmd/harbor/main.go

Version Compatibility With Harbor

At the moment, the Harbor CLI is developed and tested with Harbor 2.13. The CLI should work with versions prior to 2.13, but not all functionalities may be available or work as expected.

Harbor <2.0.0 is not supported.

Community

License

This project is licensed under the Apache 2.0 License. See the LICENSE file for details.

FOSSA Status

Acknowledgements

This project is maintained by the Harbor community. We thank all our contributors and users for their support.

❀️ Show your support

For any questions or issues, please open an issue on our GitHub Issues page.
Give a ⭐ if this project helped you, Thank YOU!

About

[Sandbox] Official Harbor CLI

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Contributors 35

Languages