step

package
v0.0.0-...-c982c64 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 16, 2016 License: MIT Imports: 14 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BootLocalTemplate = `` /* 271-byte string literal not displayed */
View Source
var ExportsTemplate = `{{.UsersDir}} {{.DockerDaemonIp}} -alldirs -mapall=501:20
{{.DataDir}} {{.DockerDaemonIp}} -alldirs -maproot=0`
View Source
var MachineStep = ConfigStep{
	Name: "docker machine",
	NeedsRun: func(envt *config.Environment) bool {
		machine := envt.GetMachine()
		return !(machine.IsCreated() && machine.IsBooted())
	},
	Run: func(envt *config.Environment) (err error) {
		machine := envt.GetMachine()
		if !machine.IsCreated() {
			err = machine.Create().Run()
			if err != nil {
				return
			}
		}
		if !machine.IsBooted() {
			err = machine.Boot().Run()
			fmt.Printf(util.FgYellow+"Run the following command once the setup is complete:\n\teval $(docker-machine env %s)\n"+util.Reset, envt.MachineName)
		}
		newEvt := config.NewEnvironment()

		envt.DockerDaemonIp = newEvt.DockerDaemonIp
		envt.DockerClientIp = newEvt.DockerClientIp
		return
	},
}
View Source
var NfsClientStep = ConfigStep{
	Name: "nfs client",
	NeedsRun: func(envt *config.Environment) bool {
		machine := envt.GetMachine()
		mountErr := machine.Exec(fmt.Sprintf("mount -t nfs|grep %s", envt.UsersDir)).Run()
		if mountErr != nil {
			return true
		}
		mountErr = machine.Exec(fmt.Sprintf("mount -t nfs|grep %s", envt.DataDir)).Run()

		return mountErr != nil
	},
	Run: func(envt *config.Environment) (err error) {
		bootLocal, err := doTemplate(BootLocalTemplate, envt)
		if err != nil {
			return
		}
		machine := envt.GetMachine()
		cmd := machine.Exec("sudo tee /var/lib/boot2docker/bootlocal.sh")
		pipeInputToCmd(cmd, bootLocal)
		out, err := cmd.CombinedOutput()
		if err != nil {
			return errors.New(string(out))
		}

		out, err = machine.Exec("sync; sudo chmod +x /var/lib/boot2docker/bootlocal.sh; sync").CombinedOutput()
		if err != nil {
			return errors.New(string(out))
		}
		err = machine.Reboot().Run()
		return
	},
}
View Source
var NfsServerStep = ConfigStep{
	Name: "nfs server",
	NeedsRun: func(envt *config.Environment) bool {
		exports, err := doTemplateAppend(ExportsTemplate, envt, "/etc/exports")
		if err != nil {
			return true
		}
		matches, err := checkIfFileMatches("/etc/exports", exports)

		return err != nil || !matches
	},
	Run: func(envt *config.Environment) (err error) {
		fmt.Println("Editing /etc/exports... sudo privileges may be required")
		out, err := exec.Command("sudo", "touch", "/etc/exports").CombinedOutput()
		if err != nil {
			return errors.New(fmt.Sprintf("Failed to create/update exports file: %s", string(out)))
		}

		exports, err := doTemplateAppend(ExportsTemplate, envt, "/etc/exports")
		if err != nil {
			return err
		}

		cmd := exec.Command("sudo", "tee", "/etc/exports")
		pipeInputToCmd(cmd, exports)
		out, err = cmd.CombinedOutput()
		if err != nil {
			return errors.New(string(out))
		}

		cmd = exec.Command("sudo", "nfsd", "restart")
		out, err = cmd.CombinedOutput()
		if err != nil {
			return errors.New(string(out))
		}
		return
	},
}
View Source
var ServicesStep = ConfigStep{
	Name: "service containers",
	NeedsRun: func(envt *config.Environment) bool {
		out, err := dockerCommand(envt, "inspect -f {{.State.Status}} vagabond_proxy").Output()
		if err != nil || !bytes.Contains(out, []byte("running")) {
			return true
		}
		out, err = dockerCommand(envt, "inspect -f {{.State.Status}} vagabond_dnsmasq").Output()
		return err != nil || !bytes.Contains(out, []byte("running"))
	},
	Run: func(envt *config.Environment) error {
		dockerCommand(envt, "stop vagabond_proxy vagabond_dnsmasq").Run()
		dockerCommand(envt, "rm vagabond_proxy vagabond_dnsmasq").Run()
		cmd := dockerCommand(envt, "run --name vagabond_proxy -d -p 80:80 -v /var/run/docker.sock:/tmp/docker.sock:ro jwilder/nginx-proxy")
		if out, err := cmd.CombinedOutput(); err != nil {
			return errors.New(string(out))
		}
		cmd = dockerCommand(envt, fmt.Sprintf("run --name vagabond_dnsmasq -d -p 53:53/udp -p 53:53/tcp --cap-add NET_ADMIN andyshinn/dnsmasq --address=/docker/%s", envt.DockerDaemonIp))
		if out, err := cmd.CombinedOutput(); err != nil {
			return errors.New(string(out))
		}
		return nil
	},
}
View Source
var VariablesStep = ConfigStep{
	Name: "environment variables",
	NeedsRun: func(envt *config.Environment) bool {
		profileFilename, err := homedir.Expand("~/.bash_profile")
		if err != nil {
			util.Fatal("Unable to find home directory")
		}
		profile, err := doTemplateAppend(profileTemplate, envt, profileFilename)
		if err != nil {
			return true
		}
		matches, err := checkIfFileMatches(profileFilename, profile)
		if err != nil || !matches {
			return true
		}
		return false
	},
	Run: func(envt *config.Environment) (err error) {
		profileFilename, err := homedir.Expand("~/.bash_profile")
		if err != nil {
			util.Fatal("Unable to find home directory")
		}
		profile, err := doTemplateAppend(profileTemplate, envt, profileFilename)
		if err != nil {
			return
		}
		cmd := exec.Command("tee", profileFilename)
		pipeInputToCmd(cmd, profile)
		out, err := cmd.CombinedOutput()
		if err != nil {
			return errors.New(string(out))
		}
		fmt.Printf(util.FgYellow + fmt.Sprintf("Run the following command once the setup is complete:\n\tsource %s\n", profileFilename) + util.Reset)
		return
	},
}

Functions

This section is empty.

Types

type ConfigStep

type ConfigStep struct {
	Name     string
	NeedsRun func(envt *config.Environment) bool
	Run      func(envt *config.Environment) error
}

func NewDnsAction

func NewDnsAction() ConfigStep

func (ConfigStep) GetName

func (act ConfigStep) GetName() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL