-
Notifications
You must be signed in to change notification settings - Fork 193
/
Copy pathoptions.go
96 lines (83 loc) · 2.85 KB
/
options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package gitlabcedocker
import (
"fmt"
"path/filepath"
"github.com/devstream-io/devstream/internal/pkg/configmanager"
dockerInstaller "github.com/devstream-io/devstream/internal/pkg/plugininstaller/docker"
"github.com/devstream-io/devstream/pkg/util/docker"
"github.com/devstream-io/devstream/pkg/util/log"
)
// Options is the struct for configurations of the gitlab-ce-docker plugin.
type Options struct {
Hostname string `validate:"hostname" mapstructure:"hostname"`
// GitLab home directory, we assume the path set by user is always correct.
GitLabHome string `mapstructure:"gitlabHome"`
SSHPort uint `mapstructure:"sshPort"`
HTTPPort uint `mapstructure:"httpPort"`
HTTPSPort uint `mapstructure:"httpsPort"`
RmDataAfterDelete *bool `mapstructure:"rmDataAfterDelete"`
ImageTag string `mapstructure:"imageTag"`
}
func (opts *Options) Defaults() {
if opts.Hostname == "" {
opts.Hostname = defaultHostname
}
if opts.GitLabHome == "" {
opts.GitLabHome = defaultGitlabHome
}
if opts.SSHPort == 0 {
opts.SSHPort = defaultSSHPort
}
if opts.HTTPPort == 0 {
opts.HTTPPort = defaultHTTPPort
}
if opts.HTTPSPort == 0 {
opts.HTTPSPort = defaultHTTPSPort
}
if opts.RmDataAfterDelete == nil {
opts.RmDataAfterDelete = defaultRMDataAfterDelete
}
if opts.ImageTag == "" {
opts.ImageTag = defaultImageTag
}
}
// gitlabURL is the access URL of GitLab.
var gitlabURL string
func (opts *Options) setGitLabURL() {
if gitlabURL != "" {
return
}
gitlabURL = fmt.Sprintf("http://%s:%d", opts.Hostname, opts.HTTPPort)
}
func showHelpMsg(options configmanager.RawOptions) error {
log.Infof("GitLab access URL: %s", gitlabURL)
log.Infof("GitLab initial root password: execute the command -> docker exec -it gitlab grep 'Password:' /etc/gitlab/initial_root_password")
return nil
}
func buildDockerOptions(opts *Options) *dockerInstaller.Options {
portPublishes := []docker.PortPublish{
{HostPort: opts.SSHPort, ContainerPort: 22},
{HostPort: opts.HTTPPort, ContainerPort: 80},
{HostPort: opts.HTTPSPort, ContainerPort: 443},
}
dockerOpts := &dockerInstaller.Options{
RmDataAfterDelete: opts.RmDataAfterDelete,
ImageName: gitlabImageName,
ImageTag: opts.ImageTag,
Hostname: opts.Hostname,
ContainerName: gitlabContainerName,
RestartAlways: true,
Volumes: buildDockerVolumes(opts),
RunParams: []string{dockerRunShmSizeParam},
PortPublishes: portPublishes,
}
return dockerOpts
}
func buildDockerVolumes(opts *Options) docker.Volumes {
volumes := []docker.Volume{
{HostPath: filepath.Join(opts.GitLabHome, "config"), ContainerPath: "/etc/gitlab"},
{HostPath: filepath.Join(opts.GitLabHome, "data"), ContainerPath: "/var/opt/gitlab"},
{HostPath: filepath.Join(opts.GitLabHome, "logs"), ContainerPath: "/var/log/gitlab"},
}
return volumes
}