mirror of
https://github.com/harness/drone.git
synced 2025-05-04 14:30:28 +08:00
feat: [CDE-192]: handle docker-host for non darwin internal url (#2406)
* feat: [CDE-192]: handle docker-host for non darwin internal url * feat: [CDE-192]: handle docker-host for non darwin internal url
This commit is contained in:
parent
8e7398d362
commit
ce8b17bb93
@ -18,6 +18,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
goruntime "runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -614,12 +615,7 @@ func (e *EmbeddedDockerOrchestrator) createContainer(
|
|||||||
return fmt.Errorf("logging error: %w", loggingErr)
|
return fmt.Errorf("logging error: %w", loggingErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := dockerClient.ContainerCreate(ctx, &container.Config{
|
hostConfig := &container.HostConfig{
|
||||||
Image: imageName,
|
|
||||||
Entrypoint: []string{"/bin/sh"},
|
|
||||||
Cmd: []string{"-c", "trap 'exit 0' 15; sleep infinity & wait $!"},
|
|
||||||
ExposedPorts: exposedPorts,
|
|
||||||
}, &container.HostConfig{
|
|
||||||
PortBindings: portBindings,
|
PortBindings: portBindings,
|
||||||
Mounts: []mount.Mount{
|
Mounts: []mount.Mount{
|
||||||
{
|
{
|
||||||
@ -628,7 +624,20 @@ func (e *EmbeddedDockerOrchestrator) createContainer(
|
|||||||
Target: workingDirectory,
|
Target: workingDirectory,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}, nil, nil, containerName)
|
}
|
||||||
|
if goruntime.GOOS == "linux" {
|
||||||
|
extraHosts := []string{"host.docker.internal:host-gateway"}
|
||||||
|
hostConfig.ExtraHosts = extraHosts
|
||||||
|
}
|
||||||
|
containerConfig := &container.Config{
|
||||||
|
Image: imageName,
|
||||||
|
Entrypoint: []string{"/bin/sh"},
|
||||||
|
Cmd: []string{"-c", "trap 'exit 0' 15; sleep infinity & wait $!"},
|
||||||
|
ExposedPorts: exposedPorts,
|
||||||
|
}
|
||||||
|
_, err := dockerClient.ContainerCreate(ctx, containerConfig,
|
||||||
|
hostConfig, nil, nil, containerName)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
loggingErr = logStreamInstance.Write("Error while creating container: " + err.Error())
|
loggingErr = logStreamInstance.Write("Error while creating container: " + err.Error())
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user