Skip to content

Commit

Permalink
Merge pull request #4 from amands98/aman/revamp
Browse files Browse the repository at this point in the history
[WIP] feat: revamp harbor cli
  • Loading branch information
Vad1mo authored Feb 6, 2024
2 parents ec4cc6b + ff2a8b0 commit b95a9b2
Show file tree
Hide file tree
Showing 26 changed files with 189 additions and 78 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/publish_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Publish Release

on:
push:
tags:
- v*

jobs:
build:
runs-on: ubuntu-20.04
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Setup go env
uses: actions/setup-go@master
with:
go-version: "1.20"
- name: goreleaser with tag
uses: goreleaser/goreleaser-action@v5
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}


5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

# Go workspace file
go.work
/bin

# harbor compiled file
harbor
/harbor
dist/
37 changes: 37 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
project_name: harbor

builds:
- main: ./cmd/harbor
binary: ./harbor
env:
- CGO_ENABLED=0
ldflags:
- -w -s -X github.com/goharbor/harbor-cli/cmd/harbor/internal/version.GitCommit={{.FullCommit}}
goos:
- linux
- windows
- darwin
goarch:
- amd64
- arm64
- arm
ignore:
- goos: windows
goarch: arm
- goos: windows
goarch: arm64
archives:
- format: tar.gz
format_overrides:
- goos: windows
format: zip
release:
draft: true
prerelease: auto

changelog:
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"
3 changes: 3 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Code of Conduct

Harbor follows the [CNCF Code of Conduct](https://github.com/cncf/foundation/blob/master/code-of-conduct.md).
Empty file added CONTRIBUTING.md
Empty file.
35 changes: 35 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
GITCOMMIT := $(shell git rev-parse --short=8 HEAD)
PROJECT_PKG = github.com/goharbor/harbor-cli
RELEASE_CHANNEL="edge"
LDFLAGS = "-w -s -X $(PROJECT_PKG)/version.GitCommit=$(GITCOMMIT) -X $(PROJECT_PKG)/version.ReleaseChannel=$(RELEASE_CHANNEL)"
ARCH := amd64
GO_EXE = go

make:
gofmt -l -s -w .
go build -ldflags=${LDFLAGS} -o harbor cmd/harbor/main.go

windows:
go build -ldflags=${LDFLAGS} -o harbor.exe cmd/harbor/main.go

.PHONY: build-win-amd64
build-win-amd64: ## build for windows amd64
CGO_ENABLED=0 GOARCH=$(ARCH) GOOS=windows $(GO_EXE) build -v --ldflags=$(LDFLAGS) \
-o bin/harbor-windows-$(ARCH).exe ./cmd/harbor/main.go
.PHONY: build-linux-amd64
build-linux-amd64: ## build for linux amd64
CGO_ENABLED=0 GOARCH=$(ARCH) GOOS=linux $(GO_EXE) build -v --ldflags=$(LDFLAGS) \
-o bin/harbor-linux-$(ARCH) ./cmd/harbor/main.go

.PHONY: build-darwin-amd64
build-darwin-amd64: ## build for darwin amd64
CGO_ENABLED=0 GOARCH=$(ARCH) GOOS=darwin $(GO_EXE) build -v --ldflags=$(LDFLAGS) \
-o bin/harbor-darwin-$(ARCH) ./cmd/harbor/main.go

.PHONY: clean
clean:
rm -rf bin

.PHONY: lint
lint:
golangci-lint run --timeout 5m
10 changes: 10 additions & 0 deletions cmd/harbor/internal/version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package version

var (
Version = "0.1.0"
GitCommit = ""
)

func GetVersion() string {
return Version
}
14 changes: 14 additions & 0 deletions cmd/harbor/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package main

import (
"os"

"github.com/goharbor/harbor-cli/cmd/harbor/root"
)

func main() {
err := root.New().Execute()
if err != nil {
os.Exit(1)
}
}
49 changes: 23 additions & 26 deletions cmd/root.go → cmd/harbor/root/cmd.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package cmd
package root

import (
"github.com/akshatdalton/harbor-cli/cmd/constants"
"github.com/akshatdalton/harbor-cli/cmd/login"
"github.com/akshatdalton/harbor-cli/cmd/project"
"github.com/akshatdalton/harbor-cli/cmd/registry"
"github.com/goharbor/harbor-cli/cmd/harbor/root/project"
"github.com/goharbor/harbor-cli/cmd/harbor/root/registry"
"github.com/goharbor/harbor-cli/pkg/constants"
"github.com/spf13/cobra"
)

Expand All @@ -17,8 +16,8 @@ func newGetCommand() *cobra.Command {
}

cmd.PersistentFlags().String(constants.CredentialNameOption, "", constants.CredentialNameHelp)
cmd.AddCommand(project.NewGetProjectCommand())
cmd.AddCommand(registry.NewGetRegistryCommand())
cmd.AddCommand(project.GetProjectCommand())
cmd.AddCommand(registry.GetRegistryCommand())
return cmd
}

Expand All @@ -31,8 +30,8 @@ func newListCommand() *cobra.Command {
}

cmd.PersistentFlags().String(constants.CredentialNameOption, "", constants.CredentialNameHelp)
cmd.AddCommand(project.NewListProjectCommand())
cmd.AddCommand(registry.NewListRegistryCommand())
cmd.AddCommand(project.ListProjectCommand())
cmd.AddCommand(registry.ListRegistryCommand())
return cmd
}

Expand All @@ -45,8 +44,8 @@ func newCreateCommand() *cobra.Command {
}

cmd.PersistentFlags().String(constants.CredentialNameOption, "", constants.CredentialNameHelp)
cmd.AddCommand(project.NewCreateProjectCommand())
cmd.AddCommand(registry.NewCreateRegistryCommand())
cmd.AddCommand(project.CreateProjectCommand())
cmd.AddCommand(registry.CreateRegistryCommand())
return cmd
}

Expand All @@ -59,8 +58,8 @@ func newDeleteCommand() *cobra.Command {
}

cmd.PersistentFlags().String(constants.CredentialNameOption, "", constants.CredentialNameHelp)
cmd.AddCommand(project.NewDeleteProjectCommand())
cmd.AddCommand(registry.NewDeleteRegistryCommand())
cmd.AddCommand(project.DeleteProjectCommand())
cmd.AddCommand(registry.DeleteRegistryCommand())
return cmd
}

Expand All @@ -73,26 +72,24 @@ func newUpdateCommand() *cobra.Command {
}

cmd.PersistentFlags().String(constants.CredentialNameOption, "", constants.CredentialNameHelp)
cmd.AddCommand(registry.NewUpdateRegistryCommand())
cmd.AddCommand(registry.UpdateRegistryCommand())
return cmd
}

func addCommands(cmd *cobra.Command) {
cmd.AddCommand(login.NewLoginCommand())
cmd.AddCommand(newGetCommand())
cmd.AddCommand(newListCommand())
cmd.AddCommand(newCreateCommand())
cmd.AddCommand(newDeleteCommand())
cmd.AddCommand(newUpdateCommand())
}

// CreateHarborCLI creates a new Harbor CLI
func CreateHarborCLI() *cobra.Command {
func New() *cobra.Command {
cmd := &cobra.Command{
Use: "harbor",
Use: "harbor [command]",
Short: "Official Harbor CLI",
}

addCommands(cmd)
cmd.AddCommand(
LoginCommand(),
newGetCommand(),
newListCommand(),
newCreateCommand(),
newDeleteCommand(),
newUpdateCommand(),
)
return cmd
}
8 changes: 4 additions & 4 deletions cmd/login/login.go → cmd/harbor/root/login.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package login
package root

import (
"context"
"fmt"

"github.com/akshatdalton/harbor-cli/cmd/utils"
"github.com/goharbor/go-client/pkg/harbor"
"github.com/goharbor/go-client/pkg/sdk/v2.0/client/user"
"github.com/goharbor/harbor-cli/pkg/utils"
"github.com/spf13/cobra"
)

Expand All @@ -17,8 +17,8 @@ type loginOptions struct {
password string
}

// NewLoginCommand creates a new `harbor login` command
func NewLoginCommand() *cobra.Command {
// LoginCommand creates a new `harbor login` command
func LoginCommand() *cobra.Command {
var opts loginOptions

cmd := &cobra.Command{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package project
import (
"context"

"github.com/akshatdalton/harbor-cli/cmd/constants"
"github.com/akshatdalton/harbor-cli/cmd/utils"
"github.com/goharbor/go-client/pkg/sdk/v2.0/client/project"
"github.com/goharbor/go-client/pkg/sdk/v2.0/models"
"github.com/goharbor/harbor-cli/pkg/constants"
"github.com/goharbor/harbor-cli/pkg/utils"
"github.com/spf13/cobra"
)

Expand All @@ -17,8 +17,8 @@ type createProjectOptions struct {
storageLimit int64
}

// NewCreateProjectCommand creates a new `harbor create project` command
func NewCreateProjectCommand() *cobra.Command {
// CreateProjectCommand creates a new `harbor create project` command
func CreateProjectCommand() *cobra.Command {
var opts createProjectOptions

cmd := &cobra.Command{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ package project
import (
"context"

"github.com/akshatdalton/harbor-cli/cmd/constants"
"github.com/akshatdalton/harbor-cli/cmd/utils"
"github.com/goharbor/go-client/pkg/sdk/v2.0/client/project"
"github.com/goharbor/harbor-cli/pkg/constants"
"github.com/goharbor/harbor-cli/pkg/utils"
"github.com/spf13/cobra"
)

type deleteProjectOptions struct {
projectNameOrID string
}

// NewDeleteProjectCommand creates a new `harbor delete project` command
func NewDeleteProjectCommand() *cobra.Command {
// DeleteProjectCommand creates a new `harbor delete project` command
func DeleteProjectCommand() *cobra.Command {
var opts deleteProjectOptions

cmd := &cobra.Command{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package project
import (
"context"

"github.com/akshatdalton/harbor-cli/cmd/constants"
"github.com/akshatdalton/harbor-cli/cmd/utils"
"github.com/goharbor/go-client/pkg/sdk/v2.0/client/project"
"github.com/goharbor/harbor-cli/pkg/constants"
"github.com/goharbor/harbor-cli/pkg/utils"
"github.com/spf13/cobra"
)

Expand All @@ -21,7 +21,7 @@ type listProjectOptions struct {
}

// NewListProjectCommand creates a new `harbor list project` command
func NewListProjectCommand() *cobra.Command {
func ListProjectCommand() *cobra.Command {
var opts listProjectOptions

cmd := &cobra.Command{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ package project
import (
"context"

"github.com/akshatdalton/harbor-cli/cmd/constants"
"github.com/akshatdalton/harbor-cli/cmd/utils"
"github.com/goharbor/go-client/pkg/sdk/v2.0/client/project"
"github.com/goharbor/harbor-cli/pkg/constants"
"github.com/goharbor/harbor-cli/pkg/utils"
"github.com/spf13/cobra"
)

type getProjectOptions struct {
projectNameOrID string
}

// NewGetProjectCommand creates a new `harbor get project` command
func NewGetProjectCommand() *cobra.Command {
// GetProjectCommand creates a new `harbor get project` command
func GetProjectCommand() *cobra.Command {
var opts getProjectOptions

cmd := &cobra.Command{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package registry
import (
"context"

"github.com/akshatdalton/harbor-cli/cmd/constants"
"github.com/akshatdalton/harbor-cli/cmd/utils"
"github.com/goharbor/go-client/pkg/sdk/v2.0/client/registry"
"github.com/goharbor/go-client/pkg/sdk/v2.0/models"
"github.com/goharbor/harbor-cli/pkg/constants"
"github.com/goharbor/harbor-cli/pkg/utils"
"github.com/spf13/cobra"
)

Expand All @@ -24,7 +24,7 @@ type createRegistrytOptions struct {
}

// NewCreateRegistryCommand creates a new `harbor create registry` command
func NewCreateRegistryCommand() *cobra.Command {
func CreateRegistryCommand() *cobra.Command {
var opts createRegistrytOptions

cmd := &cobra.Command{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"fmt"
"strconv"

"github.com/akshatdalton/harbor-cli/cmd/constants"
"github.com/akshatdalton/harbor-cli/cmd/utils"
"github.com/goharbor/go-client/pkg/sdk/v2.0/client/registry"
"github.com/goharbor/harbor-cli/pkg/constants"
"github.com/goharbor/harbor-cli/pkg/utils"
"github.com/spf13/cobra"
)

Expand All @@ -16,7 +16,7 @@ type deleteRegistryOptions struct {
}

// NewDeleteRegistryCommand creates a new `harbor delete registry` command
func NewDeleteRegistryCommand() *cobra.Command {
func DeleteRegistryCommand() *cobra.Command {
var opts deleteRegistryOptions

cmd := &cobra.Command{
Expand Down
Loading

0 comments on commit b95a9b2

Please sign in to comment.