mirror of
https://github.com/kubesphere/kubekey.git
synced 2025-12-26 01:22:51 +00:00
support harbor automatically start
This commit is contained in:
parent
d116e0fdf8
commit
f283d89574
|
|
@ -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"
|
||||
|
|
@ -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 {
|
||||
|
|
@ -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",
|
||||
|
|
@ -265,6 +282,7 @@ func InstallHarbor(i *InstallRegistryModule) []task.Interface {
|
|||
enableDocker,
|
||||
installDockerCompose,
|
||||
syncHarborPackage,
|
||||
generateHarborService,
|
||||
generateHarborConfig,
|
||||
startHarbor,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
@ -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")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue