|
1 | 1 | package gitlabcedocker
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "fmt" |
4 | 5 | "path/filepath"
|
5 | 6 |
|
| 7 | + "github.com/devstream-io/devstream/internal/pkg/plugininstaller" |
6 | 8 | dockerInstaller "github.com/devstream-io/devstream/internal/pkg/plugininstaller/docker"
|
7 | 9 | "github.com/devstream-io/devstream/pkg/util/docker"
|
| 10 | + "github.com/devstream-io/devstream/pkg/util/log" |
8 | 11 | )
|
9 | 12 |
|
10 | 13 | // Options is the struct for configurations of the gitlab-ce-docker plugin.
|
11 | 14 | type Options struct {
|
| 15 | + Hostname string `validate:"hostname" mapstructure:"hostname"` |
12 | 16 | // GitLab home directory, we assume the path set by user is always correct.
|
13 |
| - GitLabHome string `validate:"required" mapstructure:"gitlab_home"` |
14 |
| - Hostname string `validate:"required,hostname" mapstructure:"hostname"` |
15 |
| - SSHPort uint `validate:"required" mapstructure:"ssh_port"` |
16 |
| - HTTPPort uint `validate:"required" mapstructure:"http_port"` |
17 |
| - HTTPSPort uint `validate:"required" mapstructure:"https_port"` |
18 |
| - RmDataAfterDelete bool `mapstructure:"rm_data_after_delete"` |
| 17 | + GitLabHome string `mapstructure:"gitlab_home"` |
| 18 | + SSHPort uint `mapstructure:"ssh_port"` |
| 19 | + HTTPPort uint `mapstructure:"http_port"` |
| 20 | + HTTPSPort uint `mapstructure:"https_port"` |
| 21 | + RmDataAfterDelete *bool `mapstructure:"rm_data_after_delete"` |
19 | 22 | ImageTag string `mapstructure:"image_tag"`
|
20 | 23 | }
|
21 | 24 |
|
22 |
| -func buildDockerOptions(opts *Options) *dockerInstaller.Options { |
23 |
| - dockerOpts := &dockerInstaller.Options{} |
24 |
| - dockerOpts.RmDataAfterDelete = opts.RmDataAfterDelete |
25 |
| - dockerOpts.ImageName = gitlabImageName |
26 |
| - dockerOpts.ImageTag = opts.ImageTag |
27 |
| - dockerOpts.Hostname = opts.Hostname |
28 |
| - dockerOpts.ContainerName = gitlabContainerName |
29 |
| - dockerOpts.RestartAlways = true |
| 25 | +func (opts *Options) Defaults() { |
| 26 | + if opts.Hostname == "" { |
| 27 | + opts.Hostname = defaultHostname |
| 28 | + } |
| 29 | + if opts.GitLabHome == "" { |
| 30 | + opts.GitLabHome = defaultGitlabHome |
| 31 | + } |
| 32 | + if opts.SSHPort == 0 { |
| 33 | + opts.SSHPort = defaultSSHPort |
| 34 | + } |
| 35 | + if opts.HTTPPort == 0 { |
| 36 | + opts.HTTPPort = defaultHTTPPort |
| 37 | + } |
| 38 | + if opts.HTTPSPort == 0 { |
| 39 | + opts.HTTPSPort = defaultHTTPSPort |
| 40 | + } |
| 41 | + if opts.RmDataAfterDelete == nil { |
| 42 | + opts.RmDataAfterDelete = defaultRMDataAfterDelete |
| 43 | + } |
| 44 | + if opts.ImageTag == "" { |
| 45 | + opts.ImageTag = defaultImageTag |
| 46 | + } |
| 47 | +} |
| 48 | + |
| 49 | +// gitlabURL is the access URL of GitLab. |
| 50 | +var gitlabURL string |
30 | 51 |
|
| 52 | +func (opts *Options) setGitLabURL() { |
| 53 | + if gitlabURL != "" { |
| 54 | + return |
| 55 | + } |
| 56 | + gitlabURL = fmt.Sprintf("http://%s:%d", opts.Hostname, opts.HTTPPort) |
| 57 | +} |
| 58 | + |
| 59 | +func showHelpMsg(options plugininstaller.RawOptions) error { |
| 60 | + log.Infof("GitLab access URL: %s", gitlabURL) |
| 61 | + log.Infof("GitLab initial root password: execute the command -> docker exec -it gitlab grep 'Password:' /etc/gitlab/initial_root_password") |
| 62 | + |
| 63 | + return nil |
| 64 | +} |
| 65 | + |
| 66 | +func buildDockerOptions(opts *Options) *dockerInstaller.Options { |
31 | 67 | portPublishes := []docker.PortPublish{
|
32 | 68 | {HostPort: opts.SSHPort, ContainerPort: 22},
|
33 | 69 | {HostPort: opts.HTTPPort, ContainerPort: 80},
|
34 | 70 | {HostPort: opts.HTTPSPort, ContainerPort: 443},
|
35 | 71 | }
|
36 |
| - dockerOpts.PortPublishes = portPublishes |
37 | 72 |
|
38 |
| - dockerOpts.Volumes = buildDockerVolumes(opts) |
39 |
| - |
40 |
| - dockerOpts.RunParams = []string{dockerRunShmSizeParam} |
| 73 | + dockerOpts := &dockerInstaller.Options{ |
| 74 | + RmDataAfterDelete: opts.RmDataAfterDelete, |
| 75 | + ImageName: gitlabImageName, |
| 76 | + ImageTag: opts.ImageTag, |
| 77 | + Hostname: opts.Hostname, |
| 78 | + ContainerName: gitlabContainerName, |
| 79 | + RestartAlways: true, |
| 80 | + Volumes: buildDockerVolumes(opts), |
| 81 | + RunParams: []string{dockerRunShmSizeParam}, |
| 82 | + PortPublishes: portPublishes, |
| 83 | + } |
41 | 84 |
|
42 | 85 | return dockerOpts
|
43 | 86 | }
|
|
0 commit comments