Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add harbor app #878

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,7 @@ A CLI or "tool" is a command line tool that you run directly on your own worksta
| gitea | Install gitea |
| gitlab | Install GitLab |
| grafana | Install grafana |
| harbor | Install harbor |
| influxdb | Install influxdb |
| ingress-nginx | Install ingress-nginx |
| inlets-operator | Install inlets-operator |
Expand Down Expand Up @@ -674,13 +675,13 @@ A CLI or "tool" is a command line tool that you run directly on your own worksta
| vault | Install vault |
| waypoint | Install Waypoint |

There are 56 apps that you can install on your cluster.
There are 57 apps that you can install on your cluster.

> Note to contributors, run `arkade install --print-table` to generate this list

### Catalog of CLIs

| TOOL | DESCRIPTION |
| TOOL | DESCRIPTION |
|------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------|
| [actions-usage](https://github.com/self-actuated/actions-usage) | Get usage insights from GitHub Actions. |
| [actuated-cli](https://github.com/self-actuated/actuated-cli) | Official CLI for actuated.dev |
Expand Down
173 changes: 173 additions & 0 deletions cmd/apps/harbor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
// Copyright (c) arkade author(s) 2022. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

package apps

import (
"fmt"

"github.com/spf13/cobra"

"github.com/alexellis/arkade/pkg"
"github.com/alexellis/arkade/pkg/apps"
"github.com/alexellis/arkade/pkg/config"
"github.com/alexellis/arkade/pkg/types"
)

func MakeInstallHarbor() *cobra.Command {
var harbor = &cobra.Command{
Use: "harbor",
Short: "Install harbor",
Long: `Install harbor`,
Example: ` arkade install harbor
# with ingress and custom domain
arkade install harbor --ingress=true --domain=example.com`,
SilenceUsage: true,
}

harbor.Flags().StringP("namespace", "n", "harbor", "The namespace to install the chart")
harbor.Flags().Bool("update-repo", true, "Update the helm repo")
harbor.Flags().Bool("ingress", false, "Enable ingress")
harbor.Flags().Bool("trivy", false, "Enable trivy")
harbor.Flags().Bool("notary", false, "Enable notary")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notary was removed as of release 2.8 we have replaced it with cosign!

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the info @OrlinVasilev

Anything else we need to know?

@Jasstkn want to swap it out?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that looks ok for now! Cosign comes by default

harbor.Flags().String("domain", "", "Set ingress domain")
harbor.Flags().Bool("persistence", false, "Enable harbor server persistence")
harbor.Flags().StringArray("set", []string{}, "Use custom flags or override existing flags \n(example --set image.tag=1.11.2)")

harbor.PreRunE = func(cmd *cobra.Command, args []string) error {
_, err := cmd.Flags().GetString("namespace")
if err != nil {
return err
}

_, err = cmd.Flags().GetStringArray("set")
if err != nil {
return err
}

_, err = cmd.Flags().GetBool("update-repo")
if err != nil {
return err
}

ingressEnabled, err := cmd.Flags().GetBool("ingress")
if err != nil {
return err
}

_, err = cmd.Flags().GetBool("trivy")
if err != nil {
return err
}

_, err = cmd.Flags().GetBool("notary")
if err != nil {
return err
}

ingressDomain, err := cmd.Flags().GetString("domain")
if err != nil {
return err
}

if !ingressEnabled && ingressDomain != "" {
return fmt.Errorf("--domain option should be used only with --ingress=true")
}

_, err = cmd.Flags().GetBool("persistence")
if err != nil {
return err
}

return nil
}

harbor.RunE = func(cmd *cobra.Command, args []string) error {
kubeConfigPath, _ := cmd.Flags().GetString("kubeconfig")
if err := config.SetKubeconfig(kubeConfigPath); err != nil {
return err
}

namespace, _ := cmd.Flags().GetString("namespace")
updateRepo, _ := cmd.Flags().GetBool("update-repo")
ingressEnabled, _ := cmd.Flags().GetBool("ingress")
ingressDomain, _ := cmd.Flags().GetString("domain")
persistence, _ := cmd.Flags().GetBool("persistence")
trivyEnabled, _ := cmd.Flags().GetBool("trivy")
notaryEnabled, _ := cmd.Flags().GetBool("notary")
customFlags, _ := cmd.Flags().GetStringArray("set")

overrides := map[string]string{
"expose.type": "clusterIP",
"externalURL": "harbor",
"trivy.enabled": "false",
"notary.enabled": "false",
"persistence.enabled": "false",
"expose.tls.auto.commonName": "harbor",
"chartmuseum.enabled": "false", // disable chartmuseum per https://github.com/goharbor/harbor/discussions/15057
}

if ingressDomain != "" {
overrides["expose.ingress.hosts.core"] = fmt.Sprintf("harbor.%s", ingressDomain)
overrides["externalURL"] = fmt.Sprintf("https://harbor.%s", ingressDomain)
}

if ingressEnabled {
overrides["expose.type"] = "ingress"
}

if persistence {
overrides["persistence.enabled"] = "true"
}

if trivyEnabled {
overrides["trivy.enabled"] = "true"
}

if notaryEnabled {
overrides["notary.enabled"] = "true"
overrides["expose.ingress.hosts.notary"] = fmt.Sprintf("notary.%s", ingressDomain)
}

if err := config.MergeFlags(overrides, customFlags); err != nil {
return err
}

harborOptions := types.DefaultInstallOptions().
WithNamespace(namespace).
WithHelmRepo("harbor/harbor").
WithHelmURL("https://helm.goharbor.io").
WithOverrides(overrides).
WithHelmUpdateRepo(updateRepo).
WithKubeconfigPath(kubeConfigPath)

_, err := apps.MakeInstallChart(harborOptions)
if err != nil {
return err
}

fmt.Println(HarborInstallMsg)

return nil
}

return harbor
}

const HarborInfoMsg = `Please wait for several minutes for Harbor deployment to complete.
Then you should be able to visit the Harbor portal at https://harbor.<your-domain>/ or via kubectl port-forward:
kubectl port-forward -n harbor svc/harbor 8081:443

# use https when port-forwarding, e.g.
https://localhost:8081

To login, get the admin password by running:
kubectl get secrets -n harbor harbor-core -o jsonpath="{.data.HARBOR_ADMIN_PASSWORD}" | base64 -d

For more details, please visit https://github.com/goharbor/harbor
`

const HarborInstallMsg = `=======================================================================
= Harbor has been installed. =
=======================================================================` +
"\n\n" + HarborInfoMsg + "\n\n" + pkg.SupportMessageShort
1 change: 1 addition & 0 deletions cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ func GetApps() map[string]ArkadeApp {
arkadeApps["kuma"] = NewArkadeApp(apps.MakeInstallKuma, apps.KumaInfoMsg)
arkadeApps["qemu-static"] = NewArkadeApp(apps.MakeInstallQemuStatic, apps.QemuStaticInfoMsg)
arkadeApps["vault"] = NewArkadeApp(apps.MakeInstallVault, apps.VaultInfoMsg)
arkadeApps["harbor"] = NewArkadeApp(apps.MakeInstallHarbor, apps.HarborInstallMsg)

// Special "chart" app - let a user deploy any helm chart
arkadeApps["chart"] = NewArkadeApp(apps.MakeInstallChart, "")
Expand Down