Commit 5e966047 authored by Kamil Trzcinski's avatar Kamil Trzcinski
Browse files

Make lint happy (serious name refactoring)

parent 2f73fb39
......@@ -140,7 +140,7 @@ vet:
lint:
# Checking project code style...
@golint ./... | grep -v "be unexported"
@golint ./... | ( ! grep -v -e "be unexported" -e "don't use an underscore in package name" -e "ALL_CAPS" )
complexity:
# Checking code complexity
......
......@@ -16,9 +16,8 @@ func getDefaultConfigDirectory() string {
return filepath.Join(homeDir, ".gitlab-runner")
} else if currentDir := helpers.GetCurrentWorkingDirectory(); currentDir != "" {
return currentDir
} else {
panic("Cannot get default config file location")
}
panic("Cannot get default config file location")
}
func userModeWarning(withRun bool) {
......
......@@ -7,16 +7,18 @@ import (
"github.com/codegangsta/cli"
"gitlab.com/ayufan/golang-cli-helpers"
"gitlab.com/gitlab-org/gitlab-ci-multi-runner/common"
_ "gitlab.com/gitlab-org/gitlab-ci-multi-runner/executors/docker"
_ "gitlab.com/gitlab-org/gitlab-ci-multi-runner/executors/parallels"
_ "gitlab.com/gitlab-org/gitlab-ci-multi-runner/executors/shell"
_ "gitlab.com/gitlab-org/gitlab-ci-multi-runner/executors/ssh"
_ "gitlab.com/gitlab-org/gitlab-ci-multi-runner/executors/virtualbox"
"gopkg.in/yaml.v1"
"io/ioutil"
"os"
"os/exec"
"strings"
// Force to load all executors, executes init() on them
_ "gitlab.com/gitlab-org/gitlab-ci-multi-runner/executors/docker"
_ "gitlab.com/gitlab-org/gitlab-ci-multi-runner/executors/parallels"
_ "gitlab.com/gitlab-org/gitlab-ci-multi-runner/executors/shell"
_ "gitlab.com/gitlab-org/gitlab-ci-multi-runner/executors/ssh"
_ "gitlab.com/gitlab-org/gitlab-ci-multi-runner/executors/virtualbox"
)
type ExecCommand struct {
......@@ -47,9 +49,8 @@ func (c *ExecCommand) getCommands(commands interface{}) (string, error) {
return text + "\n", nil
} else if commands != nil {
return "", errors.New("unsupported script")
} else {
return "", nil
}
return "", nil
}
func (c *ExecCommand) supportedOption(key string, _ interface{}) bool {
......
package commands_helpers
package helpers
import (
"io/ioutil"
......
package commands_helpers
package helpers
import (
"testing"
......
package commands_helpers
package helpers
import (
"archive/zip"
......
package commands_helpers
package helpers
import (
"io"
......
package commands_helpers
package helpers
import (
"os"
......
package commands_helpers
package helpers
import (
"github.com/Sirupsen/logrus"
......
package commands_helpers
package helpers
import (
"testing"
......
package commands_helpers
package helpers
import (
"os"
......
package commands_helpers
package helpers
import (
"testing"
......
package commands_helpers
package helpers
import (
"bufio"
......
package commands_helpers
package helpers
import (
"io/ioutil"
......
package commands_helpers
package helpers
import (
"github.com/Sirupsen/logrus"
......
package commands_helpers
package helpers
import (
"errors"
......
......@@ -384,20 +384,20 @@ func (mr *RunCommand) Stop(s service.Service) error {
}
}
func (c *RunCommand) Execute(context *cli.Context) {
func (mr *RunCommand) Execute(context *cli.Context) {
svcConfig := &service.Config{
Name: c.ServiceName,
DisplayName: c.ServiceName,
Name: mr.ServiceName,
DisplayName: mr.ServiceName,
Description: defaultDescription,
Arguments: []string{"run"},
}
service, err := service_helpers.New(c, svcConfig)
service, err := service_helpers.New(mr, svcConfig)
if err != nil {
log.Fatalln(err)
}
if c.Syslog {
if mr.Syslog {
log.SetFormatter(new(log.TextFormatter))
logger, err := service.SystemLogger(nil)
if err == nil {
......
......@@ -86,13 +86,13 @@ func (s *RegisterCommand) askExecutor() {
s.Executor = s.ask("executor", "Please enter the executor: "+executors+":", true)
if common.NewExecutor(s.Executor) != nil {
return
}
message := "Invalid executor specified"
if s.NonInteractive {
log.Panicln(message)
} else {
message := "Invalid executor specified"
if s.NonInteractive {
log.Panicln(message)
} else {
log.Errorln(message)
}
log.Errorln(message)
}
}
}
......@@ -153,53 +153,53 @@ func (s *RegisterCommand) askRunner() {
}
}
func (c *RegisterCommand) askExecutorOptions() {
switch c.Executor {
func (s *RegisterCommand) askExecutorOptions() {
switch s.Executor {
case "docker":
c.askDocker()
c.SSH = nil
c.Parallels = nil
c.VirtualBox = nil
s.askDocker()
s.SSH = nil
s.Parallels = nil
s.VirtualBox = nil
case "docker-ssh":
c.askDocker()
c.askSSHLogin()
c.Parallels = nil
c.VirtualBox = nil
s.askDocker()
s.askSSHLogin()
s.Parallels = nil
s.VirtualBox = nil
case "ssh":
c.askSSHServer()
c.askSSHLogin()
c.Docker = nil
c.Parallels = nil
c.VirtualBox = nil
s.askSSHServer()
s.askSSHLogin()
s.Docker = nil
s.Parallels = nil
s.VirtualBox = nil
case "parallels":
c.askParallels()
c.askSSHServer()
c.Docker = nil
c.VirtualBox = nil
s.askParallels()
s.askSSHServer()
s.Docker = nil
s.VirtualBox = nil
case "VirtualBox":
c.askVirtualBox()
c.askSSHLogin()
c.Docker = nil
c.Parallels = nil
s.askVirtualBox()
s.askSSHLogin()
s.Docker = nil
s.Parallels = nil
}
}
func (c *RegisterCommand) Execute(context *cli.Context) {
func (s *RegisterCommand) Execute(context *cli.Context) {
userModeWarning(true)
c.context = context
err := c.loadConfig()
s.context = context
err := s.loadConfig()
if err != nil {
log.Panicln(err)
}
c.askRunner()
s.askRunner()
if !c.LeaveRunner {
if !s.LeaveRunner {
defer func() {
// De-register runner on panic
if r := recover(); r != nil {
if c.registered {
c.network.DeleteRunner(c.RunnerCredentials)
if s.registered {
s.network.DeleteRunner(s.RunnerCredentials)
}
// pass panic to next defer
......@@ -211,21 +211,21 @@ func (c *RegisterCommand) Execute(context *cli.Context) {
signal.Notify(signals, os.Interrupt)
go func() {
s := <-signals
c.network.DeleteRunner(c.RunnerCredentials)
log.Fatalf("RECEIVED SIGNAL: %v", s)
signal := <-signals
s.network.DeleteRunner(s.RunnerCredentials)
log.Fatalf("RECEIVED SIGNAL: %v", signal)
}()
}
c.askExecutor()
s.askExecutor()
if c.config.Concurrent < c.Limit {
log.Warningf("Specified limit (%d) larger then current concurrent limit (%d). Concurrent limit will not be enlarged.", c.Limit, c.config.Concurrent)
if s.config.Concurrent < s.Limit {
log.Warningf("Specified limit (%d) larger then current concurrent limit (%d). Concurrent limit will not be enlarged.", s.Limit, s.config.Concurrent)
}
c.askExecutorOptions()
c.addRunner(&c.RunnerConfig)
c.saveConfig()
s.askExecutorOptions()
s.addRunner(&s.RunnerConfig)
s.saveConfig()
log.Printf("Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!")
}
......
......@@ -93,9 +93,8 @@ func (c *RunnerCredentials) UniqueID() string {
func (c *RunnerCredentials) Log() *log.Entry {
if c.ShortDescription() != "" {
return log.WithField("runner", c.ShortDescription())
} else {
return log.WithFields(log.Fields{})
}
return log.WithFields(log.Fields{})
}
func (c *RunnerConfig) String() string {
......
......@@ -24,7 +24,7 @@ import (
"path"
)
type DockerExecutor struct {
type executor struct {
executors.AbstractExecutor
client *docker.Client
builds []*docker.Container
......@@ -34,11 +34,11 @@ type DockerExecutor struct {
const PrebuiltArchive = "prebuilt.tar.gz"
func (s *DockerExecutor) getServiceVariables() []string {
func (s *executor) getServiceVariables() []string {
return s.Build.GetAllVariables().PublicOrInternal().StringList()
}
func (s *DockerExecutor) getAuthConfig(imageName string) (docker.AuthConfiguration, error) {
func (s *executor) getAuthConfig(imageName string) (docker.AuthConfiguration, error) {
user, err := u.Current()
if s.Shell.User != "" {
user, err = u.Lookup(s.Shell.User)
......@@ -67,7 +67,7 @@ func (s *DockerExecutor) getAuthConfig(imageName string) (docker.AuthConfigurati
return docker.AuthConfiguration{}, fmt.Errorf("No credentials found for %v", indexName)
}
func (s *DockerExecutor) pullDockerImage(imageName string) (*docker.Image, error) {
func (s *executor) pullDockerImage(imageName string) (*docker.Image, error) {
s.Println("Pulling docker image", imageName, "...")
authConfig, err := s.getAuthConfig(imageName)
if err != nil {
......@@ -92,7 +92,7 @@ func (s *DockerExecutor) pullDockerImage(imageName string) (*docker.Image, error
return image, err
}
func (s *DockerExecutor) getDockerImage(imageName string) (*docker.Image, error) {
func (s *executor) getDockerImage(imageName string) (*docker.Image, error) {
s.Debugln("Looking for image", imageName, "...")
image, err := s.client.InspectImage(imageName)
if err == nil {
......@@ -126,7 +126,7 @@ func (s *DockerExecutor) getDockerImage(imageName string) (*docker.Image, error)
return newImage, nil
}
func (s *DockerExecutor) getPrebuiltImage(imageType string) (image *docker.Image, err error) {
func (s *executor) getPrebuiltImage(imageType string) (image *docker.Image, err error) {
imageName := "gitlab-runner-" + imageType + ":" + common.REVISION
s.Debugln("Looking for prebuilt image", imageName, "...")
image, err = s.client.InspectImage(imageName)
......@@ -156,22 +156,21 @@ func (s *DockerExecutor) getPrebuiltImage(imageType string) (image *docker.Image
return s.client.InspectImage(imageName)
}
func (s *DockerExecutor) getAbsoluteContainerPath(dir string) string {
func (s *executor) getAbsoluteContainerPath(dir string) string {
if path.IsAbs(dir) {
return dir
} else {
return path.Join(s.Build.FullProjectDir(), dir)
}
return path.Join(s.Build.FullProjectDir(), dir)
}
func (s *DockerExecutor) addHostVolume(binds *[]string, hostPath, containerPath string) error {
func (s *executor) addHostVolume(binds *[]string, hostPath, containerPath string) error {
containerPath = s.getAbsoluteContainerPath(containerPath)
s.Debugln("Using host-based", hostPath, "for", containerPath, "...")
*binds = append(*binds, fmt.Sprintf("%v:%v", hostPath, containerPath))
return nil
}
func (s *DockerExecutor) getLabels(containerType string, otherLabels ...string) map[string]string {
func (s *executor) getLabels(containerType string, otherLabels ...string) map[string]string {
labels := make(map[string]string)
labels[dockerLabelPrefix+".build.id"] = strconv.Itoa(s.Build.ID)
labels[dockerLabelPrefix+".build.sha"] = s.Build.Sha
......@@ -190,7 +189,7 @@ func (s *DockerExecutor) getLabels(containerType string, otherLabels ...string)
return labels
}
func (s *DockerExecutor) createCacheVolume(containerName, containerPath string) (*docker.Container, error) {
func (s *executor) createCacheVolume(containerName, containerPath string) (*docker.Container, error) {
// get busybox image
cacheImage, err := s.getPrebuiltImage("cache")
if err != nil {
......@@ -242,7 +241,7 @@ func (s *DockerExecutor) createCacheVolume(containerName, containerPath string)
return container, nil
}
func (s *DockerExecutor) addCacheVolume(binds, volumesFrom *[]string, containerPath string) error {
func (s *executor) addCacheVolume(binds, volumesFrom *[]string, containerPath string) error {
var err error
containerPath = s.getAbsoluteContainerPath(containerPath)
......@@ -289,7 +288,7 @@ func (s *DockerExecutor) addCacheVolume(binds, volumesFrom *[]string, containerP
return nil
}
func (s *DockerExecutor) addVolume(binds, volumesFrom *[]string, volume string) error {
func (s *executor) addVolume(binds, volumesFrom *[]string, volume string) error {
var err error
hostVolume := strings.SplitN(volume, ":", 2)
switch len(hostVolume) {
......@@ -307,7 +306,7 @@ func (s *DockerExecutor) addVolume(binds, volumesFrom *[]string, volume string)
return err
}
func (s *DockerExecutor) createVolumes() ([]string, []string, error) {
func (s *executor) createVolumes() ([]string, []string, error) {
var binds, volumesFrom []string
for _, volume := range s.Config.Docker.Volumes {
......@@ -337,7 +336,7 @@ func (s *DockerExecutor) createVolumes() ([]string, []string, error) {
return binds, volumesFrom, nil
}
func (s *DockerExecutor) splitServiceAndVersion(serviceDescription string) (string, string, string) {
func (s *executor) splitServiceAndVersion(serviceDescription string) (string, string, string) {
splits := strings.SplitN(serviceDescription, ":", 2)
service := ""
version := "latest"
......@@ -357,7 +356,7 @@ func (s *DockerExecutor) splitServiceAndVersion(serviceDescription string) (stri
return service, version, linkName
}
func (s *DockerExecutor) createService(service, version string) (*docker.Container, error) {
func (s *executor) createService(service, version string) (*docker.Container, error) {
if len(service) == 0 {
return nil, errors.New("invalid service name")
}
......@@ -401,7 +400,7 @@ func (s *DockerExecutor) createService(service, version string) (*docker.Contain
return container, nil
}
func (s *DockerExecutor) getServiceNames() ([]string, error) {
func (s *executor) getServiceNames() ([]string, error) {
services := s.Config.Docker.Services
if servicesOption, ok := s.Build.Options["services"].([]interface{}); ok {
......@@ -425,7 +424,7 @@ func (s *DockerExecutor) getServiceNames() ([]string, error) {
return services, nil
}
func (s *DockerExecutor) waitForServices() {
func (s *executor) waitForServices() {
waitForServicesTimeout := s.Config.Docker.WaitForServicesTimeout
if waitForServicesTimeout == 0 {
waitForServicesTimeout = common.DefaultWaitForServicesTimeout
......@@ -446,7 +445,7 @@ func (s *DockerExecutor) waitForServices() {
}
}
func (s *DockerExecutor) buildServiceLinks(linksMap map[string]*docker.Container) (links []string) {
func (s *executor) buildServiceLinks(linksMap map[string]*docker.Container) (links []string) {
for linkName, container := range linksMap {
newContainer, err := s.client.InspectContainer(container.ID)
if err != nil {
......@@ -459,7 +458,7 @@ func (s *DockerExecutor) buildServiceLinks(linksMap map[string]*docker.Container
return
}
func (s *DockerExecutor) createServices() ([]string, error) {
func (s *executor) createServices() ([]string, error) {
serviceNames, err := s.getServiceNames()
if err != nil {
return nil, err
......@@ -490,7 +489,7 @@ func (s *DockerExecutor) createServices() ([]string, error) {
return links, nil
}
func (s *DockerExecutor) prepareBuildContainer() (options *docker.CreateContainerOptions, err error) {
func (s *executor) prepareBuildContainer() (options *docker.CreateContainerOptions, err error) {
options = &docker.CreateContainerOptions{
Config: &docker.Config{
Tty: false,
......@@ -526,7 +525,7 @@ func (s *DockerExecutor) prepareBuildContainer() (options *docker.CreateContaine
return
}
func (s *DockerExecutor) createContainer(containerType, imageName string, cmd []string, options docker.CreateContainerOptions) (container *docker.Container, err error) {
func (s *executor) createContainer(containerType, imageName string, cmd []string, options docker.CreateContainerOptions) (container *docker.Container, err error) {
// Fetch image
image, err := s.getDockerImage(imageName)
if err != nil {
......@@ -563,7 +562,7 @@ func (s *DockerExecutor) createContainer(containerType, imageName string, cmd []
return
}
func (s *DockerExecutor) watchContainer(container *docker.Container, input io.Reader) (err error) {
func (s *executor) watchContainer(container *docker.Container, input io.Reader) (err error) {
s.Debugln("Starting container", container.ID, "...")
err = s.client.StartContainer(container.ID, nil)
if err != nil {
......@@ -601,7 +600,7 @@ func (s *DockerExecutor) watchContainer(container *docker.Container, input io.Re
return
}
func (s *DockerExecutor) removeContainer(id string) error {
func (s *executor) removeContainer(id string) error {
removeContainerOptions := docker.RemoveContainerOptions{
ID: id,
RemoveVolumes: true,
......@@ -612,7 +611,7 @@ func (s *DockerExecutor) removeContainer(id string) error {
return err
}
func (s *DockerExecutor) verifyAllowedImage(image, optionName string, allowedImages []string, internalImages []string) error {
func (s *executor) verifyAllowedImage(image, optionName string, allowedImages []string, internalImages []string) error {
for _, allowedImage := range allowedImages {
ok, _ := filepath.Match(allowedImage, image)
if ok {
......@@ -642,7 +641,7 @@ func (s *DockerExecutor) verifyAllowedImage(image, optionName string, allowedIma
return errors.New("invalid image")
}
func (s *DockerExecutor) getImageName() (string, error) {
func (s *executor) getImageName() (string, error) {
if image, ok := s.Build.Options["image"].(string); ok && image != "" {
image = s.Build.GetAllVariables().ExpandValue(image)
err := s.verifyAllowedImage(image, "images", s.Config.Docker.AllowedImages, []string{s.Config.Docker.Image})
......@@ -659,7 +658,7 @@ func (s *DockerExecutor) getImageName() (string, error) {
return s.Config.Docker.Image, nil
}
func (s *DockerExecutor) Prepare(globalConfig *common.Config, config *common.RunnerConfig, build *common.Build) error {
func (s *executor) Prepare(globalConfig *common.Config, config *common.RunnerConfig, build *common.Build) error {
err := s.AbstractExecutor.Prepare(globalConfig, config, build)
if err != nil {
return err
......@@ -688,7 +687,7 @@ func (s *DockerExecutor) Prepare(globalConfig *common.Config, config *common.Run
return nil
}
func (s *DockerExecutor) Cleanup() {
func (s *executor) Cleanup() {
for _, service := range s.services {
s.removeContainer(service.ID)
}
......@@ -704,7 +703,7 @@ func (s *DockerExecutor) Cleanup() {
s.AbstractExecutor.Cleanup()
}
func (s *DockerExecutor) runServiceHealthCheckContainer(container *docker.Container, timeout time.Duration) error {
func (s *executor) runServiceHealthCheckContainer(container *docker.Container, timeout time.Duration) error {
waitImage, err := s.getPrebuiltImage("service")
if err != nil {
return err
......@@ -746,11 +745,11 @@ func (s *DockerExecutor) runServiceHealthCheckContainer(container *docker.Contai
case err := <-waitResult:
return err
case <-time.After(timeout):
return fmt.Errorf("didn't respond in timely maner: %v (consider modifying wait_for_services_timeout: %v).", container.Name, timeout)
return fmt.Errorf("service %v did timeout", container.Name)
}
}
func (s *DockerExecutor) waitForServiceContainer(container *docker.Container, timeout time.Duration) error {
func (s *executor) waitForServiceContainer(container *docker.Container, timeout time.Duration) error {
err := s.runServiceHealthCheckContainer(container, timeout)
if err == nil {
return nil
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment