2017-08-15 00:09:41 -07:00
|
|
|
// Copyright 2017 AMIS Technologies
|
|
|
|
// This file is part of the go-ethereum library.
|
|
|
|
//
|
|
|
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
package container
|
|
|
|
|
2017-08-15 00:19:43 -07:00
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
"net/url"
|
2017-09-06 00:58:57 -07:00
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/docker/docker/client"
|
2017-08-15 00:19:43 -07:00
|
|
|
)
|
|
|
|
|
2017-08-15 00:09:41 -07:00
|
|
|
func (eth *ethereum) Image() string {
|
|
|
|
if eth.imageTag == "" {
|
|
|
|
return eth.imageRepository + ":latest"
|
|
|
|
}
|
|
|
|
return eth.imageRepository + ":" + eth.imageTag
|
|
|
|
}
|
2017-08-15 00:19:43 -07:00
|
|
|
|
2017-08-18 00:24:35 -07:00
|
|
|
func (eth *ethereum) ContainerID() string {
|
|
|
|
return eth.containerID
|
|
|
|
}
|
|
|
|
|
2017-08-15 00:19:43 -07:00
|
|
|
func (eth *ethereum) Host() string {
|
|
|
|
var host string
|
2017-09-06 00:58:57 -07:00
|
|
|
daemonHost := os.Getenv("DOCKER_HOST")
|
|
|
|
if daemonHost == "" {
|
|
|
|
daemonHost = client.DefaultDockerHost
|
|
|
|
}
|
2017-08-15 00:19:43 -07:00
|
|
|
url, err := url.Parse(daemonHost)
|
|
|
|
if err != nil {
|
2017-09-11 01:56:05 -07:00
|
|
|
log.Error("Failed to parse daemon host", "host", daemonHost, "err", err)
|
2017-08-15 00:19:43 -07:00
|
|
|
return host
|
|
|
|
}
|
|
|
|
|
|
|
|
if url.Scheme == "unix" {
|
|
|
|
host = "localhost"
|
|
|
|
} else {
|
|
|
|
host, _, err = net.SplitHostPort(url.Host)
|
|
|
|
if err != nil {
|
2017-09-11 01:56:05 -07:00
|
|
|
log.Error("Failed to split host and port", "url", url.Host, "err", err)
|
|
|
|
return ""
|
2017-08-15 00:19:43 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return host
|
|
|
|
}
|