mirror of
https://github.com/TecharoHQ/anubis.git
synced 2025-08-03 09:48:08 -04:00

* test: start work on Pale Moon tests Signed-off-by: Xe Iaso <me@xeiaso.net> * test(palemoon): rewrite to use ci-images Signed-off-by: Xe Iaso <me@xeiaso.net> * ci: enable palemoon tests Signed-off-by: Xe Iaso <me@xeiaso.net> * test(palemoon): add some variables Signed-off-by: Xe Iaso <me@xeiaso.net> * fix: disable tmate Signed-off-by: Xe Iaso <me@xeiaso.net> * test(palemoon): disable i386 for now Signed-off-by: Xe Iaso <me@xeiaso.net> * chore: spelling Signed-off-by: Xe Iaso <me@xeiaso.net> --------- Signed-off-by: Xe Iaso <me@xeiaso.net>
34 lines
830 B
Go
34 lines
830 B
Go
package internal
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/docker/docker/client"
|
|
)
|
|
|
|
// GetContainerIPAddress returns the first non-empty IP address of the container with the given name.
|
|
// It returns the IP address as a string or an error.
|
|
func GetContainerIPAddress(containerName string) (string, error) {
|
|
ctx := context.Background()
|
|
cli, err := client.NewClientWithOpts(client.FromEnv)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
// Get container details
|
|
containerJSON, err := cli.ContainerInspect(ctx, containerName)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
// Loop through all networks and return the first IP address found
|
|
for _, net := range containerJSON.NetworkSettings.Networks {
|
|
if net.IPAddress != "" {
|
|
return net.IPAddress, nil
|
|
}
|
|
}
|
|
|
|
return "", fmt.Errorf("no IP address found for container %q", containerName)
|
|
}
|