container, tests: support docker image repository and tag
This commit is contained in:
parent
36bad019e1
commit
d090a771a3
|
@ -0,0 +1,24 @@
|
||||||
|
// 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
|
||||||
|
|
||||||
|
func (eth *ethereum) Image() string {
|
||||||
|
if eth.imageTag == "" {
|
||||||
|
return eth.imageRepository + ":latest"
|
||||||
|
}
|
||||||
|
return eth.imageRepository + ":" + eth.imageTag
|
||||||
|
}
|
|
@ -68,27 +68,30 @@ type ethereum struct {
|
||||||
rpcPort string
|
rpcPort string
|
||||||
hostName string
|
hostName string
|
||||||
containerID string
|
containerID string
|
||||||
imageName string
|
|
||||||
logging bool
|
imageRepository string
|
||||||
client *client.Client
|
imageTag string
|
||||||
|
|
||||||
|
logging bool
|
||||||
|
client *client.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
func (eth *ethereum) Init(genesisFile string) error {
|
func (eth *ethereum) Init(genesisFile string) error {
|
||||||
filters := filters.NewArgs()
|
filters := filters.NewArgs()
|
||||||
filters.Add("reference", eth.imageName)
|
filters.Add("reference", eth.Image())
|
||||||
|
|
||||||
images, err := eth.client.ImageList(context.Background(), types.ImageListOptions{
|
images, err := eth.client.ImageList(context.Background(), types.ImageListOptions{
|
||||||
Filters: filters,
|
Filters: filters,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Cannot search %s, err: %v", eth.imageName, err)
|
log.Printf("Cannot search %s, err: %v", eth.Image(), err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(images) == 0 {
|
if len(images) == 0 {
|
||||||
out, err := eth.client.ImagePull(context.Background(), eth.imageName, types.ImagePullOptions{})
|
out, err := eth.client.ImagePull(context.Background(), eth.Image(), types.ImagePullOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Cannot pull %s, err: %v", eth.imageName, err)
|
log.Printf("Cannot pull %s, err: %v", eth.Image(), err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if eth.logging {
|
if eth.logging {
|
||||||
|
@ -100,7 +103,7 @@ func (eth *ethereum) Init(genesisFile string) error {
|
||||||
|
|
||||||
resp, err := eth.client.ContainerCreate(context.Background(),
|
resp, err := eth.client.ContainerCreate(context.Background(),
|
||||||
&container.Config{
|
&container.Config{
|
||||||
Image: eth.imageName,
|
Image: eth.Image(),
|
||||||
Cmd: []string{
|
Cmd: []string{
|
||||||
"init",
|
"init",
|
||||||
"--" + utils.DataDirFlag.Name,
|
"--" + utils.DataDirFlag.Name,
|
||||||
|
@ -133,7 +136,7 @@ func (eth *ethereum) Start() error {
|
||||||
resp, err := eth.client.ContainerCreate(context.Background(),
|
resp, err := eth.client.ContainerCreate(context.Background(),
|
||||||
&container.Config{
|
&container.Config{
|
||||||
Hostname: "geth-" + eth.hostName,
|
Hostname: "geth-" + eth.hostName,
|
||||||
Image: eth.imageName,
|
Image: eth.Image(),
|
||||||
Cmd: eth.flags,
|
Cmd: eth.flags,
|
||||||
ExposedPorts: map[nat.Port]struct{}{
|
ExposedPorts: map[nat.Port]struct{}{
|
||||||
nat.Port(eth.port): {},
|
nat.Port(eth.port): {},
|
||||||
|
@ -235,6 +238,8 @@ func (eth *ethereum) Running() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
func (eth *ethereum) showLog(context context.Context) {
|
func (eth *ethereum) showLog(context context.Context) {
|
||||||
if readCloser, err := eth.client.ContainerLogs(context, eth.containerID,
|
if readCloser, err := eth.client.ContainerLogs(context, eth.containerID,
|
||||||
types.ContainerLogsOptions{ShowStderr: true, Follow: true}); err == nil {
|
types.ContainerLogsOptions{ShowStderr: true, Follow: true}); err == nil {
|
||||||
|
|
|
@ -36,7 +36,8 @@ func TestEthereumContainer(t *testing.T) {
|
||||||
for _, env := range envs {
|
for _, env := range envs {
|
||||||
geth := NewEthereum(
|
geth := NewEthereum(
|
||||||
env.Client,
|
env.Client,
|
||||||
ImageName("quay.io/amis/geth:istanbul_develop"),
|
ImageRepository("quay.io/amis/geth"),
|
||||||
|
ImageTag("istanbul_develop"),
|
||||||
HostDataDir(env.DataDir),
|
HostDataDir(env.DataDir),
|
||||||
DataDir("/data"),
|
DataDir("/data"),
|
||||||
Port(fmt.Sprintf("%d", env.P2PPort)),
|
Port(fmt.Sprintf("%d", env.P2PPort)),
|
||||||
|
|
|
@ -24,9 +24,15 @@ import (
|
||||||
|
|
||||||
type Option func(*ethereum)
|
type Option func(*ethereum)
|
||||||
|
|
||||||
func ImageName(imageName string) Option {
|
func ImageRepository(repository string) Option {
|
||||||
return func(eth *ethereum) {
|
return func(eth *ethereum) {
|
||||||
eth.imageName = imageName
|
eth.imageRepository = repository
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func ImageTag(tag string) Option {
|
||||||
|
return func(eth *ethereum) {
|
||||||
|
eth.imageTag = tag
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,8 @@ var _ = Describe("4 validators Istanbul", func() {
|
||||||
for _, env := range envs {
|
for _, env := range envs {
|
||||||
geth := container.NewEthereum(
|
geth := container.NewEthereum(
|
||||||
env.Client,
|
env.Client,
|
||||||
container.ImageName("quay.io/amis/geth:istanbul_develop"),
|
container.ImageRepository("quay.io/amis/geth"),
|
||||||
|
container.ImageTag("istanbul_develop"),
|
||||||
container.HostDataDir(env.DataDir),
|
container.HostDataDir(env.DataDir),
|
||||||
container.DataDir("/data"),
|
container.DataDir("/data"),
|
||||||
container.Port(fmt.Sprintf("%d", env.P2PPort)),
|
container.Port(fmt.Sprintf("%d", env.P2PPort)),
|
||||||
|
|
Loading…
Reference in New Issue