-
Notifications
You must be signed in to change notification settings - Fork 1
/
memcached.go
43 lines (39 loc) · 1.02 KB
/
memcached.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package docker
import (
"context"
"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/wait"
"log"
"sync"
)
func Memcached(ctx context.Context, wg *sync.WaitGroup) (hostPort string, ipAddress string, err error) {
log.Println("start memcached")
c, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
ContainerRequest: testcontainers.ContainerRequest{
Image: "memcached:1.5.12-alpine",
Tmpfs: map[string]string{},
WaitingFor: wait.ForListeningPort("11211/tcp"),
AlwaysPullImage: true,
},
Started: true,
})
if err != nil {
return "", "", err
}
wg.Add(1)
go func() {
defer wg.Done()
<-ctx.Done()
log.Println("DEBUG: remove container memcached", c.Terminate(context.Background()))
}()
ipAddress, err = c.ContainerIP(ctx)
if err != nil {
return "", "", err
}
temp, err := c.MappedPort(ctx, "11211/tcp")
if err != nil {
return "", "", err
}
hostPort = temp.Port()
return hostPort, ipAddress, err
}