- Clear out some cruft tightly coupling libmachine to filestore - Comment out drivers other than virtualbox for now - Change way too many things - Mostly, break out the code to be more modular. - Destroy all traces of "provider" in its current form. It will be brought back as something more sensible, instead of something which overlaps in function with both Host and Store. - Fix mis-managed config passthru - Remove a few instances of state stored in env vars - This should be explicitly communicated in Go-land, not through the shell. - Rename "store" module to "persist" - This is done mostly to avoid confusion about the fact that a concrete instance of a "Store" interface is oftentimes referred to as "store" in the code. - Rip out repetitive antipattern for getting store - This replaces the previous repetive idiom for getting the cert info, and consequently the store, with a much less repetitive idiom. - Also, some redundant methods in commands.go for accessing hosts have either been simplified or removed entirely. - First steps towards fixing up tests - Test progress continues - Replace unit tests with integration tests - MAKE ALL UNIT TESTS PASS YAY - Add helper test files - Don't write to disk in libmachine/host - Heh.. coverage check strikes again - Fix remove code - Move cert code around - Continued progress: simplify Driver - Fixups and make creation work with new model - Move drivers module inside of libmachine - Move ssh module inside of libmachine - Move state module to libmachine - Move utils module to libmachine - Move version module to libmachine - Move log module to libmachine - Modify some constructor methods around - Change Travis build dep structure - Boring gofmt fix - Add version module - Move NewHost to store - Update some boring cert path infos to make API easier to use - Fix up some issues around the new model - Clean up some cert path stuff - Don't use shady functions to get store path :D - Continue artifact work - Fix silly machines dir bug - Continue fixing silly path issues - Change up output of vbm a bit - Continue work to make example go - Change output a little more - Last changes needed to make create finish properly - Fix config.go to use libmachine - Cut down code duplication and make both methods work with libmachine - Add pluggable logging implementation - Return error when machine already in desired state - Update example to show log method - Fix file:// bug - Fix Swarm defaults - Remove unused TLS settings from Engine and Swarm options - Remove spurious error - Correct bug detecting if migration was performed - Fix compilation errors from tests - Fix most of remaining test issues - Fix final silly bug in tests - Remove extraneous debug code - Add -race to test command - Appease the gofmt - Appease the generate coverage - Making executive decision to remove Travis coverage check In the early days I thought this would be a good idea because it would encourage people to write tests in case they added a new module. Well, in fact it has just turned into a giant nuisance and made refactoring work like this even more difficult. - Move Get to Load - Move HostListItem code to CLI Signed-off-by: Nathan LeClaire <nathan.leclaire@gmail.com>
219 lines
6.2 KiB
Go
219 lines
6.2 KiB
Go
package provision
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"text/template"
|
|
|
|
"github.com/docker/machine/libmachine/auth"
|
|
"github.com/docker/machine/libmachine/drivers"
|
|
"github.com/docker/machine/libmachine/engine"
|
|
"github.com/docker/machine/libmachine/log"
|
|
"github.com/docker/machine/libmachine/mcnutils"
|
|
"github.com/docker/machine/libmachine/provision/pkgaction"
|
|
"github.com/docker/machine/libmachine/provision/serviceaction"
|
|
"github.com/docker/machine/libmachine/swarm"
|
|
)
|
|
|
|
func init() {
|
|
Register("Debian", &RegisteredProvisioner{
|
|
New: NewDebianProvisioner,
|
|
})
|
|
}
|
|
|
|
func NewDebianProvisioner(d drivers.Driver) Provisioner {
|
|
return &DebianProvisioner{
|
|
GenericProvisioner{
|
|
DockerOptionsDir: "/etc/docker",
|
|
DaemonOptionsFile: "/etc/systemd/system/docker.service",
|
|
OsReleaseId: "debian",
|
|
Packages: []string{
|
|
"curl",
|
|
},
|
|
Driver: d,
|
|
},
|
|
}
|
|
}
|
|
|
|
type DebianProvisioner struct {
|
|
GenericProvisioner
|
|
}
|
|
|
|
func (provisioner *DebianProvisioner) Service(name string, action serviceaction.ServiceAction) error {
|
|
// daemon-reload to catch config updates; systemd -- ugh
|
|
if _, err := provisioner.SSHCommand("sudo systemctl daemon-reload"); err != nil {
|
|
return err
|
|
}
|
|
|
|
command := fmt.Sprintf("sudo systemctl -f %s %s", action.String(), name)
|
|
|
|
if _, err := provisioner.SSHCommand(command); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (provisioner *DebianProvisioner) Package(name string, action pkgaction.PackageAction) error {
|
|
var packageAction string
|
|
|
|
updateMetadata := true
|
|
|
|
switch action {
|
|
case pkgaction.Install, pkgaction.Upgrade:
|
|
packageAction = "install"
|
|
case pkgaction.Remove:
|
|
packageAction = "remove"
|
|
updateMetadata = false
|
|
}
|
|
|
|
switch name {
|
|
case "docker":
|
|
name = "docker-engine"
|
|
}
|
|
|
|
if updateMetadata {
|
|
if _, err := provisioner.SSHCommand("sudo apt-get update"); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
// handle the new docker-engine package; we can probably remove this
|
|
// after we have a few versions
|
|
if action == pkgaction.Upgrade && name == "docker-engine" {
|
|
// run the force remove on the existing lxc-docker package
|
|
// and remove the existing apt source list
|
|
// also re-run the get.docker.com script to properly setup
|
|
// the system again
|
|
|
|
commands := []string{
|
|
"rm /etc/apt/sources.list.d/docker.list || true",
|
|
"apt-get remove -y lxc-docker || true",
|
|
"curl -sSL https://get.docker.com | sh",
|
|
}
|
|
|
|
for _, cmd := range commands {
|
|
command := fmt.Sprintf("sudo DEBIAN_FRONTEND=noninteractive %s", cmd)
|
|
if _, err := provisioner.SSHCommand(command); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
}
|
|
|
|
command := fmt.Sprintf("DEBIAN_FRONTEND=noninteractive sudo -E apt-get %s -y %s", packageAction, name)
|
|
|
|
log.Debugf("package: action=%s name=%s", action.String(), name)
|
|
|
|
if _, err := provisioner.SSHCommand(command); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (provisioner *DebianProvisioner) dockerDaemonResponding() bool {
|
|
if _, err := provisioner.SSHCommand("sudo docker version"); err != nil {
|
|
log.Warnf("Error getting SSH command to check if the daemon is up: %s", err)
|
|
return false
|
|
}
|
|
|
|
// The daemon is up if the command worked. Carry on.
|
|
return true
|
|
}
|
|
|
|
func (provisioner *DebianProvisioner) Provision(swarmOptions swarm.SwarmOptions, authOptions auth.AuthOptions, engineOptions engine.EngineOptions) error {
|
|
provisioner.SwarmOptions = swarmOptions
|
|
provisioner.AuthOptions = authOptions
|
|
provisioner.EngineOptions = engineOptions
|
|
|
|
if provisioner.EngineOptions.StorageDriver == "" {
|
|
provisioner.EngineOptions.StorageDriver = "aufs"
|
|
}
|
|
|
|
// HACK: since debian does not come with sudo by default we install
|
|
log.Debug("installing sudo")
|
|
if _, err := provisioner.SSHCommand("if ! type sudo; then apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y sudo; fi"); err != nil {
|
|
return err
|
|
}
|
|
|
|
log.Debug("setting hostname")
|
|
if err := provisioner.SetHostname(provisioner.Driver.GetMachineName()); err != nil {
|
|
return err
|
|
}
|
|
|
|
log.Debug("installing base packages")
|
|
for _, pkg := range provisioner.Packages {
|
|
if err := provisioner.Package(pkg, pkgaction.Install); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
log.Debug("installing docker")
|
|
if err := installDockerGeneric(provisioner, engineOptions.InstallURL); err != nil {
|
|
return err
|
|
}
|
|
|
|
log.Debug("waiting for docker daemon")
|
|
if err := mcnutils.WaitFor(provisioner.dockerDaemonResponding); err != nil {
|
|
return err
|
|
}
|
|
|
|
provisioner.AuthOptions = setRemoteAuthOptions(provisioner)
|
|
|
|
log.Debug("configuring auth")
|
|
if err := ConfigureAuth(provisioner); err != nil {
|
|
return err
|
|
}
|
|
|
|
log.Debug("configuring swarm")
|
|
if err := configureSwarm(provisioner, swarmOptions, provisioner.AuthOptions); err != nil {
|
|
return err
|
|
}
|
|
|
|
// enable in systemd
|
|
log.Debug("enabling docker in systemd")
|
|
if err := provisioner.Service("docker", serviceaction.Enable); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (provisioner *DebianProvisioner) GenerateDockerOptions(dockerPort int) (*DockerOptions, error) {
|
|
var (
|
|
engineCfg bytes.Buffer
|
|
)
|
|
|
|
driverNameLabel := fmt.Sprintf("provider=%s", provisioner.Driver.DriverName())
|
|
provisioner.EngineOptions.Labels = append(provisioner.EngineOptions.Labels, driverNameLabel)
|
|
|
|
engineConfigTmpl := `[Service]
|
|
ExecStart=/usr/bin/docker -d -H tcp://0.0.0.0:{{.DockerPort}} -H unix:///var/run/docker.sock --storage-driver {{.EngineOptions.StorageDriver}} --tlsverify --tlscacert {{.AuthOptions.CaCertRemotePath}} --tlscert {{.AuthOptions.ServerCertRemotePath}} --tlskey {{.AuthOptions.ServerKeyRemotePath}} {{ range .EngineOptions.Labels }}--label {{.}} {{ end }}{{ range .EngineOptions.InsecureRegistry }}--insecure-registry {{.}} {{ end }}{{ range .EngineOptions.RegistryMirror }}--registry-mirror {{.}} {{ end }}{{ range .EngineOptions.ArbitraryFlags }}--{{.}} {{ end }}
|
|
MountFlags=slave
|
|
LimitNOFILE=1048576
|
|
LimitNPROC=1048576
|
|
LimitCORE=infinity
|
|
Environment={{range .EngineOptions.Env}}{{ printf "%q" . }} {{end}}
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
`
|
|
t, err := template.New("engineConfig").Parse(engineConfigTmpl)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
engineConfigContext := EngineConfigContext{
|
|
DockerPort: dockerPort,
|
|
AuthOptions: provisioner.AuthOptions,
|
|
EngineOptions: provisioner.EngineOptions,
|
|
}
|
|
|
|
t.Execute(&engineCfg, engineConfigContext)
|
|
|
|
return &DockerOptions{
|
|
EngineOptions: engineCfg.String(),
|
|
EngineOptionsPath: provisioner.DaemonOptionsFile,
|
|
}, nil
|
|
}
|