mirror of https://github.com/docker/docs.git
Lint, step 1
The easy stuff Signed-off-by: Olivier Gambier <olivier@docker.com>
This commit is contained in:
parent
ab4b09bfb2
commit
19fc49b58a
|
@ -80,7 +80,7 @@ func main() {
|
|||
if c.GlobalBool("native-ssh") {
|
||||
ssh.SetDefaultClient(ssh.Native)
|
||||
}
|
||||
mcnutils.GithubApiToken = c.GlobalString("github-api-token")
|
||||
mcnutils.GithubAPIToken = c.GlobalString("github-api-token")
|
||||
mcndirs.BaseDir = c.GlobalString("storage-path")
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -220,7 +220,7 @@ var Commands = []cli.Command{
|
|||
Name: "ip",
|
||||
Usage: "Get the IP address of a machine",
|
||||
Description: "Argument(s) are one or more machine names.",
|
||||
Action: fatalOnError(cmdIp),
|
||||
Action: fatalOnError(cmdIP),
|
||||
},
|
||||
{
|
||||
Name: "kill",
|
||||
|
@ -278,7 +278,7 @@ var Commands = []cli.Command{
|
|||
Name: "ssh",
|
||||
Usage: "Log into or run a command on a machine with SSH.",
|
||||
Description: "Arguments are [machine-name] [command]",
|
||||
Action: fatalOnError(cmdSsh),
|
||||
Action: fatalOnError(cmdSSH),
|
||||
SkipFlagParsing: true,
|
||||
},
|
||||
{
|
||||
|
@ -321,7 +321,7 @@ var Commands = []cli.Command{
|
|||
Name: "url",
|
||||
Usage: "Get the URL of a machine",
|
||||
Description: "Argument is a machine name.",
|
||||
Action: fatalOnError(cmdUrl),
|
||||
Action: fatalOnError(cmdURL),
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ import (
|
|||
"github.com/docker/machine/libmachine/state"
|
||||
)
|
||||
|
||||
// For when the cert is computed to be invalid.
|
||||
// ErrCertInvalid for when the cert is computed to be invalid.
|
||||
type ErrCertInvalid struct {
|
||||
wrappedErr error
|
||||
hostUrl string
|
||||
|
|
|
@ -2,6 +2,6 @@ package commands
|
|||
|
||||
import "github.com/docker/machine/cli"
|
||||
|
||||
func cmdIp(c *cli.Context) error {
|
||||
func cmdIP(c *cli.Context) error {
|
||||
return runActionWithContext("ip", c)
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
"github.com/docker/machine/libmachine/state"
|
||||
)
|
||||
|
||||
func cmdSsh(c *cli.Context) error {
|
||||
func cmdSSH(c *cli.Context) error {
|
||||
// Check for help flag -- Needed due to SkipFlagParsing
|
||||
for _, arg := range c.Args() {
|
||||
if arg == "-help" || arg == "--help" || arg == "-h" {
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
"github.com/docker/machine/cli"
|
||||
)
|
||||
|
||||
func cmdUrl(c *cli.Context) error {
|
||||
func cmdURL(c *cli.Context) error {
|
||||
if len(c.Args()) != 1 {
|
||||
return ErrExpectedOneMachine
|
||||
}
|
||||
|
|
2
doc.go
2
doc.go
|
@ -1,4 +1,4 @@
|
|||
// Machine defines interfaces to manage a variety of docker instances
|
||||
// Package machine defines interfaces to manage a variety of docker instances
|
||||
// deployed on different backends (VMs, baremetal).
|
||||
// The goal is to allow users get from zero to docker as fast as possible.
|
||||
package machine
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
"sync"
|
||||
)
|
||||
|
||||
// Why the interface? We may only want to print to STDOUT and STDERR for now,
|
||||
// Logger - Why the interface? We may only want to print to STDOUT and STDERR for now,
|
||||
// but it won't neccessarily be that way forever. This interface is intended
|
||||
// to provide a "framework" for a variety of different logging types in the
|
||||
// future (log to file, log to logstash, etc.) There could be a driver model
|
||||
|
@ -37,7 +37,7 @@ var (
|
|||
l = StandardLogger{
|
||||
mu: &sync.Mutex{},
|
||||
}
|
||||
IsDebug bool = false
|
||||
IsDebug = false
|
||||
)
|
||||
|
||||
type Fields map[string]interface{}
|
||||
|
|
|
@ -17,7 +17,7 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
GithubApiToken string
|
||||
GithubAPIToken string
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -47,8 +47,8 @@ type B2dUtils struct {
|
|||
isoFilename string
|
||||
commonIsoPath string
|
||||
imgCachePath string
|
||||
githubApiBaseUrl string
|
||||
githubBaseUrl string
|
||||
githubAPIBaseURL string
|
||||
githubBaseURL string
|
||||
}
|
||||
|
||||
func NewB2dUtils(storePath string) *B2dUtils {
|
||||
|
@ -63,31 +63,31 @@ func NewB2dUtils(storePath string) *B2dUtils {
|
|||
}
|
||||
}
|
||||
|
||||
func (b *B2dUtils) getReleasesRequest(apiUrl string) (*http.Request, error) {
|
||||
req, err := http.NewRequest("GET", apiUrl, nil)
|
||||
func (b *B2dUtils) getReleasesRequest(apiURL string) (*http.Request, error) {
|
||||
req, err := http.NewRequest("GET", apiURL, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if GithubApiToken != "" {
|
||||
req.Header.Add("Authorization", fmt.Sprintf("token %s", GithubApiToken))
|
||||
if GithubAPIToken != "" {
|
||||
req.Header.Add("Authorization", fmt.Sprintf("token %s", GithubAPIToken))
|
||||
}
|
||||
|
||||
return req, nil
|
||||
}
|
||||
|
||||
// Get the latest boot2docker release tag name (e.g. "v0.6.0").
|
||||
// GetLatestBoot2DockerReleaseURL gets the latest boot2docker release tag name (e.g. "v0.6.0").
|
||||
// FIXME: find or create some other way to get the "latest release" of boot2docker since the GitHub API has a pretty low rate limit on API requests
|
||||
func (b *B2dUtils) GetLatestBoot2DockerReleaseURL(apiUrl string) (string, error) {
|
||||
if apiUrl == "" {
|
||||
apiUrl = "https://api.github.com/repos/boot2docker/boot2docker/releases"
|
||||
func (b *B2dUtils) GetLatestBoot2DockerReleaseURL(apiURL string) (string, error) {
|
||||
if apiURL == "" {
|
||||
apiURL = "https://api.github.com/repos/boot2docker/boot2docker/releases"
|
||||
}
|
||||
isoUrl := ""
|
||||
isoURL := ""
|
||||
// match github (enterprise) release urls:
|
||||
// https://api.github.com/repos/../../releases or
|
||||
// https://some.github.enterprise/api/v3/repos/../../releases
|
||||
re := regexp.MustCompile("(https?)://([^/]+)(/api/v3)?/repos/([^/]+)/([^/]+)/releases")
|
||||
if matches := re.FindStringSubmatch(apiUrl); len(matches) == 6 {
|
||||
if matches := re.FindStringSubmatch(apiURL); len(matches) == 6 {
|
||||
scheme := matches[1]
|
||||
host := matches[2]
|
||||
org := matches[4]
|
||||
|
@ -96,7 +96,7 @@ func (b *B2dUtils) GetLatestBoot2DockerReleaseURL(apiUrl string) (string, error)
|
|||
host = "github.com"
|
||||
}
|
||||
client := getClient()
|
||||
req, err := b.getReleasesRequest(apiUrl)
|
||||
req, err := b.getReleasesRequest(apiURL)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
@ -118,13 +118,13 @@ func (b *B2dUtils) GetLatestBoot2DockerReleaseURL(apiUrl string) (string, error)
|
|||
|
||||
tag := t[0].TagName
|
||||
log.Infof("Latest release for %s/%s/%s is %s\n", host, org, repo, tag)
|
||||
isoUrl = fmt.Sprintf("%s://%s/%s/%s/releases/download/%s/boot2docker.iso", scheme, host, org, repo, tag)
|
||||
isoURL = fmt.Sprintf("%s://%s/%s/%s/releases/download/%s/boot2docker.iso", scheme, host, org, repo, tag)
|
||||
} else {
|
||||
//does not match a github releases api url
|
||||
isoUrl = apiUrl
|
||||
isoURL = apiURL
|
||||
}
|
||||
|
||||
return isoUrl, nil
|
||||
return isoURL, nil
|
||||
}
|
||||
|
||||
func removeFileIfExists(name string) error {
|
||||
|
@ -136,9 +136,9 @@ func removeFileIfExists(name string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// Download boot2docker ISO image for the given tag and save it at dest.
|
||||
func (b *B2dUtils) DownloadISO(dir, file, isoUrl string) error {
|
||||
u, err := url.Parse(isoUrl)
|
||||
// DownloadISO downloads boot2docker ISO image for the given tag and save it at dest.
|
||||
func (b *B2dUtils) DownloadISO(dir, file, isoURL string) error {
|
||||
u, err := url.Parse(isoURL)
|
||||
var src io.ReadCloser
|
||||
if u.Scheme == "file" || u.Scheme == "" {
|
||||
s, err := os.Open(u.Path)
|
||||
|
@ -148,7 +148,7 @@ func (b *B2dUtils) DownloadISO(dir, file, isoUrl string) error {
|
|||
src = s
|
||||
} else {
|
||||
client := getClient()
|
||||
s, err := client.Get(isoUrl)
|
||||
s, err := client.Get(isoURL)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -194,18 +194,18 @@ func (b *B2dUtils) DownloadISO(dir, file, isoUrl string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (b *B2dUtils) DownloadLatestBoot2Docker(apiUrl string) error {
|
||||
latestReleaseUrl, err := b.GetLatestBoot2DockerReleaseURL(apiUrl)
|
||||
func (b *B2dUtils) DownloadLatestBoot2Docker(apiURL string) error {
|
||||
latestReleaseURL, err := b.GetLatestBoot2DockerReleaseURL(apiURL)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return b.DownloadISOFromURL(latestReleaseUrl)
|
||||
return b.DownloadISOFromURL(latestReleaseURL)
|
||||
}
|
||||
|
||||
func (b *B2dUtils) DownloadISOFromURL(latestReleaseUrl string) error {
|
||||
log.Infof("Downloading %s to %s...", latestReleaseUrl, b.commonIsoPath)
|
||||
if err := b.DownloadISO(b.imgCachePath, b.isoFilename, latestReleaseUrl); err != nil {
|
||||
func (b *B2dUtils) DownloadISOFromURL(latestReleaseURL string) error {
|
||||
log.Infof("Downloading %s to %s...", latestReleaseURL, b.commonIsoPath)
|
||||
if err := b.DownloadISO(b.imgCachePath, b.isoFilename, latestReleaseURL); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -235,9 +235,9 @@ func (b *B2dUtils) CopyIsoToMachineDir(isoURL, machineName string) error {
|
|||
} else {
|
||||
//if ISO is specified, check if it matches a github releases url or fallback
|
||||
//to a direct download
|
||||
if downloadUrl, err := b.GetLatestBoot2DockerReleaseURL(isoURL); err == nil {
|
||||
log.Infof("Downloading %s from %s...", b.isoFilename, downloadUrl)
|
||||
if err := b.DownloadISO(machineDir, b.isoFilename, downloadUrl); err != nil {
|
||||
if downloadURL, err := b.GetLatestBoot2DockerReleaseURL(isoURL); err == nil {
|
||||
log.Infof("Downloading %s from %s...", b.isoFilename, downloadURL)
|
||||
if err := b.DownloadISO(machineDir, b.isoFilename, downloadURL); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -17,14 +17,14 @@ func TestGetLatestBoot2DockerReleaseUrl(t *testing.T) {
|
|||
defer ts.Close()
|
||||
|
||||
b := NewB2dUtils("/tmp/isos")
|
||||
isoUrl, err := b.GetLatestBoot2DockerReleaseURL(ts.URL + "/repos/org/repo/releases")
|
||||
isoURL, err := b.GetLatestBoot2DockerReleaseURL(ts.URL + "/repos/org/repo/releases")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
expectedUrl := fmt.Sprintf("%s/org/repo/releases/download/0.1/boot2docker.iso", ts.URL)
|
||||
if isoUrl != expectedUrl {
|
||||
t.Fatalf("expected url %s; received %s", expectedUrl, isoUrl)
|
||||
expectedURL := fmt.Sprintf("%s/org/repo/releases/download/0.1/boot2docker.iso", ts.URL)
|
||||
if isoURL != expectedURL {
|
||||
t.Fatalf("expected url %s; received %s", expectedURL, isoURL)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -58,7 +58,7 @@ func TestDownloadIso(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestGetReleasesRequestNoToken(t *testing.T) {
|
||||
GithubApiToken = ""
|
||||
GithubAPIToken = ""
|
||||
b2d := NewB2dUtils("/tmp/store")
|
||||
req, err := b2d.getReleasesRequest("http://some.github.api")
|
||||
if err != nil {
|
||||
|
@ -72,7 +72,7 @@ func TestGetReleasesRequestNoToken(t *testing.T) {
|
|||
|
||||
func TestGetReleasesRequest(t *testing.T) {
|
||||
expectedToken := "CATBUG"
|
||||
GithubApiToken = expectedToken
|
||||
GithubAPIToken = expectedToken
|
||||
b2d := NewB2dUtils("/tmp/store")
|
||||
|
||||
req, err := b2d.getReleasesRequest("http://some.github.api")
|
||||
|
|
|
@ -14,6 +14,7 @@ import (
|
|||
"github.com/docker/machine/libmachine/log"
|
||||
)
|
||||
|
||||
// GetHomeDir returns the home directory
|
||||
// TODO: Having this here just strikes me as dangerous, but some of the drivers
|
||||
// depend on it ;_;
|
||||
func GetHomeDir() string {
|
||||
|
@ -104,6 +105,7 @@ func DumpVal(vals ...interface{}) {
|
|||
}
|
||||
}
|
||||
|
||||
// TruncateID returns a shorten id
|
||||
// Following two functions are from github.com/docker/docker/utils module. It
|
||||
// was way overkill to include the whole module, so we just have these bits
|
||||
// that we're using here.
|
||||
|
|
|
@ -13,6 +13,7 @@ import (
|
|||
// The /etc/os-release file contains operating system identification data
|
||||
// See http://www.freedesktop.org/software/systemd/man/os-release.html for more details
|
||||
|
||||
// OsRelease reflects values in /etc/os-release
|
||||
// Values in this struct must always be string
|
||||
// or the reflection will not work properly.
|
||||
type OsRelease struct {
|
||||
|
|
|
@ -14,7 +14,7 @@ import (
|
|||
|
||||
var provisioners = make(map[string]*RegisteredProvisioner)
|
||||
|
||||
// Distribution specific actions
|
||||
// Provisioner defines distribution specific actions
|
||||
type Provisioner interface {
|
||||
// Create the files for the daemon to consume configuration settings (return struct of content and path)
|
||||
GenerateDockerOptions(dockerPort int) (*DockerOptions, error)
|
||||
|
@ -62,7 +62,7 @@ type Provisioner interface {
|
|||
GetOsReleaseInfo() (*OsRelease, error)
|
||||
}
|
||||
|
||||
// Detection
|
||||
// RegisteredProvisioner creates a new provisioner
|
||||
type RegisteredProvisioner struct {
|
||||
New func(d drivers.Driver) Provisioner
|
||||
}
|
||||
|
|
|
@ -19,8 +19,8 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
versionsUrl = "http://releases.rancher.com/os/versions.yml"
|
||||
isoUrl = "https://github.com/rancherio/os/releases/download/%s/machine-rancheros.iso"
|
||||
versionsURL = "http://releases.rancher.com/os/versions.yml"
|
||||
isoURL = "https://github.com/rancherio/os/releases/download/%s/machine-rancheros.iso"
|
||||
hostnameTmpl = `sudo mkdir -p /var/lib/rancher/conf/cloud-config.d/
|
||||
sudo tee /var/lib/rancher/conf/cloud-config.d/machine-hostname.yml << EOF
|
||||
#cloud-config
|
||||
|
@ -206,8 +206,8 @@ func (provisioner *RancherProvisioner) upgradeIso() error {
|
|||
}
|
||||
|
||||
func (provisioner *RancherProvisioner) getLatestISOURL() (string, error) {
|
||||
log.Debugf("Reading %s", versionsUrl)
|
||||
resp, err := http.Get(versionsUrl)
|
||||
log.Debugf("Reading %s", versionsURL)
|
||||
resp, err := http.Get(versionsURL)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
@ -219,7 +219,7 @@ func (provisioner *RancherProvisioner) getLatestISOURL() (string, error) {
|
|||
line := scanner.Text()
|
||||
if strings.HasPrefix(line, "current: ") {
|
||||
log.Debugf("Found %s", line)
|
||||
return fmt.Sprintf(isoUrl, strings.Split(line, ":")[2]), err
|
||||
return fmt.Sprintf(isoURL, strings.Split(line, ":")[2]), err
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -146,11 +146,11 @@ func ConfigureAuth(p Provisioner) error {
|
|||
return err
|
||||
}
|
||||
|
||||
dockerUrl, err := driver.GetURL()
|
||||
dockerURL, err := driver.GetURL()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
u, err := url.Parse(dockerUrl)
|
||||
u, err := url.Parse(dockerURL)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -97,7 +97,7 @@ func TestMachinePortBoot2Docker(t *testing.T) {
|
|||
Driver: &fakedriver.Driver{},
|
||||
}
|
||||
dockerPort := 2376
|
||||
bindUrl := fmt.Sprintf("tcp://0.0.0.0:%d", dockerPort)
|
||||
bindURL := fmt.Sprintf("tcp://0.0.0.0:%d", dockerPort)
|
||||
p.AuthOptions = auth.AuthOptions{
|
||||
CaCertRemotePath: "/test/ca-cert",
|
||||
ServerKeyRemotePath: "/test/server-key",
|
||||
|
@ -119,8 +119,8 @@ func TestMachinePortBoot2Docker(t *testing.T) {
|
|||
url := u[1]
|
||||
url = strings.Replace(url, "'", "", -1)
|
||||
url = strings.Replace(url, "\\\"", "", -1)
|
||||
if url != bindUrl {
|
||||
t.Errorf("expected url %s; received %s", bindUrl, url)
|
||||
if url != bindURL {
|
||||
t.Errorf("expected url %s; received %s", bindURL, url)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -129,7 +129,7 @@ func TestMachineCustomPortBoot2Docker(t *testing.T) {
|
|||
Driver: &fakedriver.Driver{},
|
||||
}
|
||||
dockerPort := 3376
|
||||
bindUrl := fmt.Sprintf("tcp://0.0.0.0:%d", dockerPort)
|
||||
bindURL := fmt.Sprintf("tcp://0.0.0.0:%d", dockerPort)
|
||||
p.AuthOptions = auth.AuthOptions{
|
||||
CaCertRemotePath: "/test/ca-cert",
|
||||
ServerKeyRemotePath: "/test/server-key",
|
||||
|
@ -152,7 +152,7 @@ func TestMachineCustomPortBoot2Docker(t *testing.T) {
|
|||
url := u[1]
|
||||
url = strings.Replace(url, "'", "", -1)
|
||||
url = strings.Replace(url, "\\\"", "", -1)
|
||||
if url != bindUrl {
|
||||
t.Errorf("expected url %s; received %s", bindUrl, url)
|
||||
if url != bindURL {
|
||||
t.Errorf("expected url %s; received %s", bindURL, url)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ type KeyPair struct {
|
|||
PublicKey []byte
|
||||
}
|
||||
|
||||
// Generate a new SSH keypair
|
||||
// NewKeyPair generates a new SSH keypair
|
||||
// This will return a private & public key encoded as DER.
|
||||
func NewKeyPair() (keyPair *KeyPair, err error) {
|
||||
priv, err := rsa.GenerateKey(rand.Reader, 2048)
|
||||
|
@ -53,7 +53,7 @@ func NewKeyPair() (keyPair *KeyPair, err error) {
|
|||
}, nil
|
||||
}
|
||||
|
||||
// Write keypair to files
|
||||
// WriteToFile writes keypair to files
|
||||
func (kp *KeyPair) WriteToFile(privateKeyPath string, publicKeyPath string) error {
|
||||
files := []struct {
|
||||
File string
|
||||
|
@ -92,7 +92,7 @@ func (kp *KeyPair) WriteToFile(privateKeyPath string, publicKeyPath string) erro
|
|||
return nil
|
||||
}
|
||||
|
||||
// Calculate the fingerprint of the public key
|
||||
// Fingerprint calculates the fingerprint of the public key
|
||||
func (kp *KeyPair) Fingerprint() string {
|
||||
b, _ := base64.StdEncoding.DecodeString(string(kp.PublicKey))
|
||||
h := md5.New()
|
||||
|
@ -102,7 +102,7 @@ func (kp *KeyPair) Fingerprint() string {
|
|||
return fmt.Sprintf("%x", h.Sum(nil))
|
||||
}
|
||||
|
||||
// Generate SSH keypair based on path of the private key
|
||||
// GenerateSSHKey generates SSH keypair based on path of the private key
|
||||
// The public key would be generated to the same path with ".pub" added
|
||||
func GenerateSSHKey(path string) error {
|
||||
if _, err := os.Stat(path); err != nil {
|
||||
|
|
|
@ -31,7 +31,6 @@ var states = []string{
|
|||
func (s State) String() string {
|
||||
if int(s) >= 0 && int(s) < len(states) {
|
||||
return states[s]
|
||||
} else {
|
||||
return ""
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue