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

feature: support harbor automatically start #1302

Merged
merged 1 commit into from
May 27, 2022
Merged
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
20 changes: 19 additions & 1 deletion pkg/bootstrap/registry/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ package registry

import (
"fmt"
"path/filepath"

"github.com/kubesphere/kubekey/pkg/bootstrap/registry/templates"
"github.com/kubesphere/kubekey/pkg/common"
"github.com/kubesphere/kubekey/pkg/container"
Expand All @@ -26,7 +28,6 @@ import (
"github.com/kubesphere/kubekey/pkg/core/prepare"
"github.com/kubesphere/kubekey/pkg/core/task"
"github.com/kubesphere/kubekey/pkg/core/util"
"path/filepath"
)

type RegistryCertsModule struct {
Expand Down Expand Up @@ -232,6 +233,22 @@ func InstallHarbor(i *InstallRegistryModule) []task.Interface {
Retry: 2,
}

// generate Harbor Systemd
generateHarborService := &task.RemoteTask{
Name: "GenerateHarborService",
Desc: "Generate harbor service",
Hosts: i.Runtime.GetHostsByRole(common.Registry),
Action: &action.Template{
Template: templates.HarborServiceTempl,
Dst: "/etc/systemd/system/harbor.service",
Data: util.Data{
"Harbor_install_path": "/opt/harbor",
},
},
Parallel: true,
Retry: 1,
}

generateHarborConfig := &task.RemoteTask{
Name: "GenerateHarborConfig",
Desc: "Generate harbor config",
Expand Down Expand Up @@ -265,6 +282,7 @@ func InstallHarbor(i *InstallRegistryModule) []task.Interface {
enableDocker,
installDockerCompose,
syncHarborPackage,
generateHarborService,
generateHarborConfig,
startHarbor,
}
Expand Down
7 changes: 4 additions & 3 deletions pkg/bootstrap/registry/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ package registry

import (
"fmt"
"path/filepath"
"strings"

"github.com/kubesphere/kubekey/pkg/common"
"github.com/kubesphere/kubekey/pkg/core/connector"
"github.com/kubesphere/kubekey/pkg/files"
"github.com/kubesphere/kubekey/pkg/utils"
"github.com/pkg/errors"
"path/filepath"
"strings"
)

type SyncCertsFile struct {
Expand Down Expand Up @@ -215,7 +216,7 @@ type StartHarbor struct {
}

func (g *StartHarbor) Execute(runtime connector.Runtime) error {
startCmd := "cd /opt/harbor && chmod +x install.sh && export PATH=$PATH:/usr/local/bin; ./install.sh --with-notary --with-trivy --with-chartmuseum"
startCmd := "cd /opt/harbor && chmod +x install.sh && export PATH=$PATH:/usr/local/bin; ./install.sh --with-notary --with-trivy --with-chartmuseum && systemctl daemon-reload && systemctl enable harbor && systemctl restart harbor"
if _, err := runtime.GetRunner().SudoCmd(startCmd, false); err != nil {
return errors.Wrap(errors.WithStack(err), "start harbor failed")
}
Expand Down
18 changes: 17 additions & 1 deletion pkg/bootstrap/registry/templates/harbor.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,27 @@ limitations under the License.
package templates

import (
"github.com/lithammer/dedent"
"text/template"

"github.com/lithammer/dedent"
)

var (
// HarborServiceTempl defines the template of registry's configuration file.
HarborServiceTempl = template.Must(template.New("harborSerivce").Parse(
dedent.Dedent(`[Unit]
Description=Harbor
After=docker.service systemd-networkd.service systemd-resolved.service
Requires=docker.service

[Service]
Type=simple
ExecStart=/usr/local/bin/docker-compose -f {{ .Harbor_install_path }}/docker-compose.yml up
ExecStop=/usr/local/bin/docker-compose -f {{ .Harbor_install_path }}/docker-compose.yml down
Restart=on-failure
[Install]
WantedBy=multi-user.target
`)))
// HarborConfigTempl defines the template of registry's configuration file.
HarborConfigTempl = template.Must(template.New("harborConfig").Parse(
dedent.Dedent(`# Configuration file of Harbor
Expand Down