mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-26 11:51:02 +00:00
ability to specify your own service images. unit tests not yet passing
This commit is contained in:
parent
1c5aebe9fb
commit
d498f18881
3 changed files with 28 additions and 32 deletions
|
@ -174,16 +174,31 @@ func (b *Builder) setup() error {
|
|||
// start all services required for the build
|
||||
// that will get linked to the container.
|
||||
for _, service := range b.Build.Services {
|
||||
image, ok := services[service]
|
||||
if !ok {
|
||||
return fmt.Errorf("Error: Invalid or unknown service %s", service)
|
||||
|
||||
// Parse the name of the Docker image
|
||||
// And then construct a fully qualified image name
|
||||
owner, name, tag := parseImageName(service)
|
||||
cname := fmt.Sprintf("%s/%s:%s", owner, name, tag)
|
||||
|
||||
// Get the image info
|
||||
img, err := b.dockerClient.Images.Inspect(cname)
|
||||
if err != nil {
|
||||
// Get the image if it doesn't exist
|
||||
if err := b.dockerClient.Images.Pull(cname); err != nil {
|
||||
return fmt.Errorf("Error: Unable to pull image %s", cname)
|
||||
}
|
||||
|
||||
img, err = b.dockerClient.Images.Inspect(cname)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error: Invalid or unknown image %s", cname)
|
||||
}
|
||||
}
|
||||
|
||||
// debugging
|
||||
log.Infof("starting service container %s", image.Tag)
|
||||
log.Infof("starting service container %s", cname)
|
||||
|
||||
// Run the contianer
|
||||
run, err := b.dockerClient.Containers.RunDaemonPorts(image.Tag, image.Ports...)
|
||||
run, err := b.dockerClient.Containers.RunDaemonPorts(cname, img.Config.ExposedPorts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -201,7 +216,6 @@ func (b *Builder) setup() error {
|
|||
|
||||
// Add the running service to the list
|
||||
b.services = append(b.services, info)
|
||||
|
||||
}
|
||||
|
||||
if err := b.writeIdentifyFile(dir); err != nil {
|
||||
|
@ -319,13 +333,12 @@ func (b *Builder) run() error {
|
|||
|
||||
// link service containers
|
||||
for i, service := range b.services {
|
||||
image, ok := services[b.Build.Services[i]]
|
||||
if !ok {
|
||||
continue // THIS SHOULD NEVER HAPPEN
|
||||
}
|
||||
// convert name of the image to a slug
|
||||
_, name, _ := parseImageName(b.Build.Services[i])
|
||||
|
||||
// link the service container to our
|
||||
// build container.
|
||||
host.Links = append(host.Links, service.Name[1:]+":"+image.Name)
|
||||
host.Links = append(host.Links, service.Name[1:]+":"+name)
|
||||
}
|
||||
|
||||
// where are temp files going to go?
|
||||
|
|
|
@ -108,22 +108,6 @@ func TestSetupEmptyImage(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// TestSetupUnknownService will test our ability to handle an
|
||||
// unknown or unsupported service (i.e. mysql).
|
||||
func TestSetupUnknownService(t *testing.T) {
|
||||
b := Builder{}
|
||||
b.Repo = &repo.Repo{}
|
||||
b.Repo.Path = "git://github.com/drone/drone.git"
|
||||
b.Build = &script.Build{}
|
||||
b.Build.Image = "go1.2"
|
||||
b.Build.Services = append(b.Build.Services, "not-found")
|
||||
|
||||
var got, want = b.setup(), "Error: Invalid or unknown service not-found"
|
||||
if got == nil || got.Error() != want {
|
||||
t.Errorf("Expected error %s, got %s", want, got)
|
||||
}
|
||||
}
|
||||
|
||||
// TestSetupErrorRunDaemonPorts will test our ability to handle a
|
||||
// failure when starting a service (i.e. mysql) as a daemon.
|
||||
func TestSetupErrorRunDaemonPorts(t *testing.T) {
|
||||
|
|
|
@ -127,19 +127,18 @@ func (c *ContainerService) RunDaemon(conf *Config, host *HostConfig) (*Run, erro
|
|||
return run, err
|
||||
}
|
||||
|
||||
func (c *ContainerService) RunDaemonPorts(image string, ports ...string) (*Run, error) {
|
||||
func (c *ContainerService) RunDaemonPorts(image string, ports map[Port]struct{}) (*Run, error) {
|
||||
// setup configuration
|
||||
config := Config{Image: image}
|
||||
config.ExposedPorts = make(map[Port]struct{})
|
||||
config.ExposedPorts = ports
|
||||
|
||||
// host configuration
|
||||
host := HostConfig{}
|
||||
host.PortBindings = make(map[Port][]PortBinding)
|
||||
|
||||
// loop through and add ports
|
||||
for _, port := range ports {
|
||||
config.ExposedPorts[Port(port+"/tcp")] = struct{}{}
|
||||
host.PortBindings[Port(port+"/tcp")] = []PortBinding{{HostIp: "127.0.0.1", HostPort: ""}}
|
||||
for port, _ := range ports {
|
||||
host.PortBindings[port] = []PortBinding{{HostIp: "127.0.0.1", HostPort: ""}}
|
||||
}
|
||||
//127.0.0.1::%s
|
||||
//map[3306/tcp:{}] map[3306/tcp:[{127.0.0.1 }]]
|
||||
|
|
Loading…
Reference in a new issue